From fed216840f81e0e2c2e73ecc6c003e2f2352d644 Mon Sep 17 00:00:00 2001 From: Ian Mancini Date: Sun, 10 May 2020 04:47:18 -0300 Subject: [PATCH] Add twitch-notify script and rename chromium-twtich-chat --- .gitattributes | 1 + data/twitch-oauth.gpg | Bin 0 -> 911 bytes chromium-twitch-chat => launch-twitch-chat | 0 launch-twitch-notify | 3 + twitch-notify | 66 +++++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 .gitattributes create mode 100644 data/twitch-oauth.gpg rename chromium-twitch-chat => launch-twitch-chat (100%) create mode 100755 launch-twitch-notify create mode 100644 twitch-notify diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b69c02c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.gpg binary diff --git a/data/twitch-oauth.gpg b/data/twitch-oauth.gpg new file mode 100644 index 0000000000000000000000000000000000000000..03428a687a0bf96d9ea52c851a8b326530f45035 GIT binary patch literal 911 zcmV;A191F>0Sp6B$Bdlj8sSd?2mKkeeH9g{$=|&u)7BXk+EI4vY*x@09t|= z87KnrvJgf8=sK-u=&HJ8AQNHS&oyQ0z9mUL`lTIThts%lO(9Q#K?*{8f>o%P8KJqJ z!NXFGLsdB^X>VEws3q^O=M|&GPz6*tdQ)E1-Hy8yzI*7Jq?0cAb6t^E>yOW#)tKYz zse603L(Y0x_Ir`aJVH7>`iq4D3>;zo$Z+RM4 z%4K93)HM1(um=E0{DLshV|%OB`cnn?3hRDzE=leMN_ZdR9Yko8nt&;PEXpZHv zT7j~s3e`4D8g}+kJ{7iKqnr)gM|SM1NbwCa^$Kqt^o)CRQ^;^l18!E ze5I>Y1Y^}zU_*PLUU|md;_F*eSr<1nx;daRT;_RKxmfJ85^hTb@n8oL}7f_ z*e*5zR_JabSb75U#1TTpI11^kVbeDP%?Hr2WNE)RffwQI3$po6(qI9g5xVpV4-I3q zyLgHsgwK=Z(XHXPmio>S*Im`bhSEI$Bi?d(9}4*y)xDsK))RVGKU&F^80!RRRqY)m lrH0yQ#N-fS+Sb?5I)ETKl(J=Tniq4o6^gSaN~ {__file__}") + exit(1) + + +HOST = 'irc.chat.twitch.tv' +PORT = 6667 +MESSAGE_REGEX = ':(.*)\!.*@.* PRIVMSG #(.*) :(.*)' + + +sock = socket.socket() +connected = False + + +def connect(): + sock.connect((HOST, PORT)) + sock.send(f"PASS {config['token']}\n".encode('utf-8')) + sock.send(f"NICK {config['nickname']}\n".encode('utf-8')) + sock.send(f"JOIN {config['channel']}\n".encode('utf-8')) + + +connect() + +while True: + resp = sock.recv(2048).decode('utf-8') + + if resp.startswith('PING'): + sock.send("PONG\n".encode('utf-8')) + + elif len(resp) > 0: + if connected: + user, channel, message = re.search(MESSAGE_REGEX, resp).groups() + + if config['short_notification']: + notification_text = f"@{user}: {message}" + else: + notification_text = f"@{user} in #{channel}\n{message}" + + if not (config['supress_own'] and config['nickname'] == user): + call(["notify-send", notification_text]) + + if "End of /NAMES list" in resp: + connected = True + call([ + "notify-send", + f"connected to {config['channel']} as {config['nickname']}"])