-
Notifications
You must be signed in to change notification settings - Fork 17
/
utils.py
46 lines (41 loc) · 1.33 KB
/
utils.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
#libraries
import json
#configuration
with open('config.json') as f:
config = json.load(f)
token = config['token']
guild_id = config['guild_id']
success_emoji = config['emojis']['success']
error_emoji = config['emojis']['failure']
#afk functions
#adds a user to the afk list
def add_afk(user_id, message):
with open('database.json', 'r') as f:
database = json.load(f)
#first add userid to database then add message
database['afks'][str(user_id)] = message
with open('database.json', 'w') as f:
json.dump(database, f, indent = 4)
#removes a user from the afk list
def remove_afk(user_id):
with open('database.json', 'r') as f:
database = json.load(f)
#remove userid from database
del database['afks'][str(user_id)]
with open('database.json', 'w') as f:
json.dump(database, f, indent = 4)
#checks if a user is afk
def is_afk(user_id):
with open('database.json', 'r') as f:
database = json.load(f)
#check if userid is in database
if user_id in database['afks']:
return True
else:
return False
#gets the message of a user
def get_message(user_id):
with open('database.json', 'r') as f:
database = json.load(f)
#get message of userid
return database['afks'][str(user_id)]