-
Notifications
You must be signed in to change notification settings - Fork 1
/
list_of_channels.py
36 lines (36 loc) · 1.29 KB
/
list_of_channels.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
#this file is to control whether the 'trivia' works in a particular channel or not
from replit import db
#this function is to add 'trivia' to a particular channel which enables you to play trivia in that channel
#used 'try' and 'except' in both functions to avoid getting errors when users give invalid queries
#'db["Ch"]' is the list of all channel ids that user can play 'trivia'
def AddChannel(m,chi):# 'm' is the message and 'chi' is the channel id
try:
t=str(m.content).split(' ')[1]#t gets the second word of the query
if t=="trivia":#checks if the second word of query is trivia
if "Ch" in db.keys():
y=db["Ch"]
y.append(chi)
db["Ch"]=y
else:
db["Ch"]=[chi]
return str(m.channel.name)#returns channel name
else:
return "!"
except:
return "!"
#this function is to remove 'trivia' from a particular channel, when removed 'trivia' can't be played in that channel until added
def RemChannel(m,chi):# 'm' is the message and 'chi' is the channel id
try:
t=str(m.content).split(' ')[1]
if t=="trivia":
if "Ch" in db.keys():
y=db["Ch"]
y.remove(chi)
db["Ch"]=y
return str(m.channel.name)##returns channel name
else:
return "!"
else:
return "!"
except:
return "!"