-
Notifications
You must be signed in to change notification settings - Fork 10
/
chatding.py
33 lines (27 loc) · 967 Bytes
/
chatding.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import socket, time
from config import DELAY, CHANNEL, ALERT_SOUND, ALERT_RUMBLE
from alerts import sound, rumble
from common import window
sock = socket.socket()
sock.connect(('irc.chat.twitch.tv',6667))
sock.send(f"NICK justinfan0\n".encode('utf-8'))
sock.send(f"JOIN {CHANNEL}\n".encode('utf-8'))
lastAlert = 0
def parseChat(resp):
resp = resp.rstrip().split('\r\n')
for line in resp:
if "PRIVMSG" in line:
user = line.split(':')[1].split('!')[0]
msg = line.split(':', maxsplit=2)[2]
line = user + ": " + msg
print(line)
while True:
resp = sock.recv(2048).decode('utf-8')
if resp.startswith('PING'):
sock.send("PONG\n".encode('utf-8'))
elif len(resp) > 0:
parseChat(resp)
if not window.foreground() and time.time() - lastAlert > DELAY:
if ALERT_SOUND: sound.alert()
if ALERT_RUMBLE: rumble.alert()
lastAlert = time.time()