1+ import discord
2+ import json
3+
4+ def store (file , key = None , read = False , val = None , * , pop = False ):
5+ with open (file , 'r' ) as v :
6+ x = json .load (v )
7+ if x is None : return
8+ if read is not False :
9+ if key is None :
10+ return x
11+ else :
12+ return x [key ]
13+ elif pop is True :
14+ return
15+ else :
16+ if val is None :
17+ with open (file , 'w' ) as v :
18+ json .dump (key , v , indent = 4 )
19+ return
20+ x [key ] = val
21+ with open (file , 'w' ) as v :
22+ json .dump (x , v , indent = 4 )
23+
24+ async def get_ready (bot ):
25+ config = store ('config.json' , None , True )
26+ load_cogs (bot , config )
27+ await ready_status (bot , config )
28+ print ("Ready" )
29+
30+ def load_cogs (bot , config ):
31+ for cog in config ['cogs' ]:
32+ bot .load_extension (cog )
33+
34+ async def ready_status (client , x ):
35+ f = x ['testMode' ]
36+ def type ():
37+ d = x ['activity' ]
38+ if f :
39+ return discord .Game (name = 'Test mode (commands don\' t work)' )
40+ elif x ['atype' ] == 'l' :
41+ return discord .Activity (type = discord .ActivityType .listening , name = d )
42+ elif x ['atype' ] == 'w' :
43+ return discord .Activity (type = discord .ActivityType .watching , name = d )
44+ elif x ['atype' ] == 'c' :
45+ return discord .Activity (type = discord .ActivityType .competing , name = d )
46+ elif x ['atype' ] == 's' :
47+ return discord .Streaming (name = d , url = x ['surl' ])
48+ else :
49+ return discord .Game (name = d )
50+ def stat ():
51+ l = x ['status' ]
52+ if l == 'dnd' or f :
53+ return discord .Status .dnd
54+ elif l == 'online' :
55+ return discord .Status .online
56+ elif l == 'idle' :
57+ return discord .Status .idle
58+ else :
59+ return discord .Status .invisible
60+ if x ['atype' ] != 'n' or f :
61+ await client .change_presence (status = stat (), activity = type ())
0 commit comments