-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbwlists.py
94 lines (76 loc) · 3.19 KB
/
bwlists.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
# bwlists.py
import util
import commandv2
def load(core):
database = core.exports.get('database')
register_command = core.exports.get('command/register')
lang = core.exports.get('lang')
def update_lists():
print('Updating black and white lists...')
table = database().get_table('blacklists')
res = table.select(lambda d: True)
blacklists = {}
for row in res:
name = row['list_name']
channel_id = int(row['channel_id'])
if name in blacklists.keys():
blacklists[name] += [channel_id]
else:
blacklists[name] = [channel_id]
core.exports.put('blacklists', blacklists)
table = database().get_table('whitelists')
res = table.select(lambda d: True)
whitelists = {}
for row in res:
name = row['list_name']
channel_id = int(row['guild_id'])
if name in whitelists.keys():
whitelists[name] += [channel_id]
else:
whitelists[name] = [channel_id]
core.exports.put('whitelists', whitelists)
update_lists()
async def updatelists(message, args):
await message.channel.send(embed=util.ifinfo('Refreshing black/whitelists...'))
update_lists()
register_command()('updatelists', updatelists, [commandv2.Command.Check.is_andyinnie])
async def blacklist(message, args):
try:
name = args[0]
except IndexError:
await message.channel.send(embed=util.iferror(lang()('supply.generic', 'a blacklist name and a channel ID')))
return
try:
channel_id = int(args[1])
except IndexError:
await message.channel.send(embed=util.iferror(lang()('supply.generic', 'a blacklist name and a channel ID')))
return
except ValueError:
await message.channel.send(embed=util.iferror(lang()('error.invalid.idwithtype', 'channel')))
return
table = database().get_table('blacklists')
table.insert([name, channel_id])
update_lists()
register_command()('blacklist', blacklist, [commandv2.Command.Check.is_andyinnie])
async def whitelist(message, args):
try:
name = args[0]
except IndexError:
await message.channel.send(embed=util.iferror(lang()('supply.generic', 'a whitelist name and a guild ID')))
return
try:
guild_id = int(args[1])
except IndexError:
await message.channel.send(embed=util.iferror(lang()('supply.generic', 'a whitelist name and a guild ID')))
return
except ValueError:
await message.channel.send(embed=util.iferror(lang()('error.invalid.idwithtype', 'guild')))
return
table = database().get_table('whitelists')
table.insert([name, guild_id])
update_lists()
register_command()('whitelist', whitelist, [commandv2.Command.Check.is_andyinnie])
print('Loaded bwlists.py')
# async def load_async(core):
# print('bwlists load_async')
# await update_lists()