-
Notifications
You must be signed in to change notification settings - Fork 0
/
perty.py
executable file
·54 lines (39 loc) · 1.31 KB
/
perty.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
# https://www.learndatasci.com/tutorials/how-stream-text-data-twitch-sockets-python/
# We're going to need to do full client authentication.
from config import load_config
from twitch_auth import oauth
import display
import socketserver
import time
import emoji
import regex
def split_count(text):
emoji_list = []
data = regex.findall(r'\X', text)
for word in data:
if any(char in emoji.UNICODE_EMOJI['en'] for char in word):
emoji_list.append(word)
return emoji_list
cfg = load_config()
token = oauth() # Get user token
import socket
sock = socket.socket()
sock.connect((cfg['twitch']['server'], cfg['twitch']['port']))
sock.send(f"PASS oauth:{token}\n".encode('utf-8'))
sock.send(f"NICK {cfg['twitch']['name']}\n".encode('utf-8'))
sock.send(f"JOIN {cfg['twitch']['channel']}\n".encode('utf-8'))
cur_emoji = "😊"
while True:
resp = sock.recv(2048).decode('utf-8')
print (resp) # Just print whatever we get
if resp.startswith('PING'):
sock.send("PONG\n".encode('utf-8'))
if "/NAMES" in resp:
sock.send("PRIVMSG #betsyandsamantha :PERTY CONNECTED\n".encode('utf-8'))
if resp:
emojis = split_count(resp)
if any(emojis):
cur_emoji = emojis[-1]
display.display_emoji(cur_emoji)
time.sleep(1)