-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiodoBot.py
65 lines (44 loc) · 1.59 KB
/
DiodoBot.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
55
56
57
58
59
60
61
62
63
64
65
import irc
import os
import sys
def clear():
if sys.platform == "linux":
os.system('clear')
else:
os.system("cls")
class message:
def __init__(self, text: str):
self.channel = text.split("PRIVMSG").pop().split(":")[0].replace("#", "").replace(" ", "")
self.message = text.split("PRIVMSG").pop().split(":").pop()
self.username = text.split(".tmi.twitch.tv")[0].split("@").pop()
def Print(self):
print("User: ", self.username)
print("Channel: ", self.channel)
print("Message: ", self.message)
print("\n")
class Bot:
def __init__(self, channel: str, secret: str, nickname: str):
self.client = irc.IRC(channel, secret, nickname)
self.client.sock.send(f"CAP REQ :twitch.tv/tags twitch.tv/commands twitch.tv/membership\r\n".encode('utf-8')) #unused
clear()
print("============================")
print(" " + nickname + " ONLINE")
print("============================\n")
def listen_channel(self):
while True:
resp = self.client.read()
if "PRIVMSG" in resp:
m = message(resp)
m.Print()
def Run(self):
self.listen_channel()
def Main():
# Channel where you want to connect
channel = 'superdiodo'
# I take it from <https://twitchapps.com/tmi/>
token = ''
# Nickname of the twitch account you want to connect with
nickname = 'diodobot'
diodobot = Bot(channel, token , nickname)
diodobot.Run()
Main()