This repository has been archived by the owner on Dec 3, 2022. It is now read-only.
/
commands.py
178 lines (129 loc) · 5.38 KB
/
commands.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""
This module has two functions.
prepCMD prepares the raw websockets data for getResp to return the appropriate response.
This makes it even easier for modding, since you can simply pass the command from the
new code instead of having to figure out how to create the correct packet.
"""
from datetime import datetime
import responses
initTime = datetime.now().strftime('%H.%M.%S')
def prepCMD(msg, bannedUsers, msgLocalID, msgs_acted):
global is_mod, is_owner
userID = msg['user_id']
userName = msg['user_name']
msgID = msg['id']
user_roles = msg['user_roles']
is_mod = False # Have to declare variable as False to avoid UnboundLocalError
is_owner = False # Have to declare variable as False to avoid UnboundLocalError
response = None # Have to declare variable as None to avoid UnboundLocalError
goodbye = False # Have to declare variable as False to avoid UnboundLocalError
if 'Owner' in user_roles:
print ('Streamer/Owner!')
is_mod = True
is_owner = True
elif 'Mod' in user_roles:
print ('Stream mod!')
is_mod = True
if userName in bannedUsers: # Is the user chatbanned?
session = requests.session()
login_r = session.post(
addr + '/api/v1/users/login',
data=_get_auth_body()
)
if login_r.status_code != requests.codes.ok:
print (login_r.text)
print ("Not Authenticated!")
quit()
del_r = session.delete(addr + '/api/v1/chats/' + str(channel) + '/message/' + msgID) # Delete the message
if del_r.status_code != requests.codes.ok:
print ('Response:\t\t',del_r.json())
quit()
session.close()
curItem = ''
"""
This loop goes through the message. If there is a link in the message, then it will show up every second
part of the message.
When there *is* a link, it won't have any text for the current part of the message, so use the "data" key
of the current part of the message.
"""
for i in range(0, len(msg['message'])):
if i % 2: # Every 2 messages
curItem += msg['message'][i]['text']
else:
curItem += msg['message'][i]['data']
for item in msg['message']: # Iterate through the message
if len(curItem) >= 1: # Just make sure it's an actual message
if curItem[0] == '!' and msgID not in msgs_acted: # It's a command! Pay attention!
response, goodbye = getResp(curItem, userName, msgLocalID)
return response, goodbye
def getResp(curItem, userName=None, msgLocalID=None):
# ----------------------------------------------------------
# Commands
# ----------------------------------------------------------
cmd = curItem[1:].split()
if cmd[0] == "hey": # Say hey
response = responses.hey(userName)
elif cmd[0] == "ping": # Ping Pong Command
response = responses.ping(userName)
elif cmd[0] == "dimes" or cmd[0] == "currency": # Get user balance
response = responses.dimes(userName, curItem)
elif cmd[0] == "give": # Give dimes to a user
response = responses.give(userName, curItem)
elif cmd[0] == "ban": # Ban a user from chatting
response, banUser = responses.ban(userName, curItem)
bannedUsers.append(banUser)
pickle.dump(bannedUsers, open('data/bannedUsers.p', "wb"))
elif cmd[0] == "unban": # Unban a user
response, uBanUser = responses.unban(userName, curItem)
bannedUsers.remove(uBanUser)
pickle.dump(bannedUsers, open('data/bannedUsers.p', "wb"))
elif cmd[0] == "quote": # Get random quote from DB
response = responses.quote(userName, curItem)
elif cmd[0] == "tackle":# Tackle a user!
response = responses.tackle(userName, curItem)
elif cmd[0] == "slap": # Slap someone
response = responses.slap(userName)
elif cmd[0] == "uptime":# Bot uptime
response = responses.uptime(userName, initTime)
elif cmd[0] == "hug": # Give hugs!
response = responses.hug(userName, curItem)
elif cmd[0] == "raid": # Go raid peoples
response = responses.raid(userName, curItem)
elif cmd[0] == "raided": # You done got raided son!
response = responses.raided(userName, curItem)
elif cmd[0] == "twitch": # Go raid peoples on Twitch.tv!
response = responses.twitch(userName, curItem)
elif cmd[0] == "whoami": # Who am I? I'M A GOAT. DUH.
response = responses.whoami(userName)
elif cmd[0] == "command": # Add command for any users
response = responses.command(userName, curItem)
elif cmd[0] == "command+": # Add mod-only command
response = responses.commandMod(userName, curItem)
elif cmd[0] == "command-": # Remove a command
response = responses.commandRM(userName, curItem)
elif cmd[0] == "whitelist": # Whitelist a user
if len(cmd) >= 3: # True means it has something like `add` or `remove`
if cmd[1] == 'add':
response = responses.whitelist(userName, curItem)
elif cmd[1] == 'remove':
response = responses.whitelistRM(userName, curItem)
else: # Not add or remove
response = None
else: # Just get the whitelist
response = responses.whitelistLS(userName, curItem)
elif cmd[0] == "goodbye": # Turn off the bot correctly
if is_owner or userName == 'ParadigmShift3d':
packet = {
"type":"method",
"method":"msg",
"arguments":['See you later my dear sir, wot wot!'],
"id":msgLocalID
}
return packet, True # Return the Goodbye message packet &
else: # Don't want anyone but owner killing the bot
return None, False
else: # Unknown or custom command
response = responses.custom(userName, curItem)
print ('command:\t',cmd,'\n',
'response:\t',response,'\n') # Console logging
return response, False # Return the response to calling statement