-
Notifications
You must be signed in to change notification settings - Fork 0
/
admincommands.py
106 lines (82 loc) · 3.67 KB
/
admincommands.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
# admincommands.py
import discord
import util
import commandv2
def load(core):
lang = core.exports.get('lang')
responder_toggle = core.exports.get_or_default('responder_toggle', True)
database = core.exports.get('database')
register_command = core.exports.get('command/register')
async def toggleresponders(message, args):
before = responder_toggle()
after = not before
core.exports.put('responder_toggle', after)
await message.channel.send(embed=util.ifsuccess(f'Toggled message responders **{"on" if after else "off"}**'))
register_command()('toggleresponders', toggleresponders, [commandv2.Command.Check.is_andyinnie])
async def alive(message, args):
await message.channel.send(embed=util.ifinfo('bot is alive'))
register_command()('alive', alive)
async def kill(message, args):
await message.channel.send(embed=util.ifinfo('Goodbye, cruel world!'))
core.bot.close()
print(f'Logging out on {util.now(date_first=True)}')
exit(0)
register_command()('kill', kill, [commandv2.Command.Check.is_andyinnie])
async def puppet(message, args):
if len(args) < 2:
await message.channel.send(
embed=util.iferror(lang()('supply.generic', 'a channel ID and a message'))
)
return
try:
channel_id = int(args[0])
except ValueError:
await message.channel.send(
embed=util.iferror(lang()('error.invalid.idwithtype', 'channel'))
)
return
channel = core.bot.get_channel(channel_id)
await channel.send(' '.join(args[1:]))
register_command()('puppet', puppet, [commandv2.Command.Check.is_andyinnie])
async def puppetdm(message, args):
if len(args) < 2:
await message.channel.send(
embed=util.iferror(lang()('supply.generic', 'a user ID and a message'))
)
return
try:
user_id = int(args[0])
except ValueError:
await message.channel.send(
embed=util.iferror(lang()('error.invalid.idwithtype', 'user'))
)
return
user = core.bot.get_user(user_id)
await user.send(' '.join(args[1:]))
register_command()('puppetdm', puppetdm, [commandv2.Command.Check.is_andyinnie])
async def prefix(message, args):
channel = message.channel
if isinstance(channel, discord.DMChannel):
await channel.send(embed=util.iferror('This command can only be used in a server.'))
return
if len(args) == 0:
await channel.send(embed=util.iferror(lang()('supply.generic', 'a prefix')))
return
pref = args[0].strip()
if len(pref) < 1 or len(pref) > 5:
await channel.send(embed=util.iferror(lang()('error.invalid.string.max', 5)))
return
if not all([util.good_char(c) for c in pref]):
await channel.send(embed=util.iferror(lang()('error.invalid.string.illegal')))
return
guild_id = channel.guild.id
table = database().get_table('prefixes')
table.update_or_insert(lambda row: row['guild_id'] == str(guild_id),
{'prefix': pref},
[guild_id, pref])
await channel.send(embed=util.ifsuccess(f'Changed command prefix to: `{pref}`'))
register_command()('prefix', prefix, [commandv2.Command.Check.is_andyinnie])
async def raiseexception(message, args):
raise Exception
register_command()('raiseexception', raiseexception, [commandv2.Command.Check.is_andyinnie])
print('Loaded admincommands.py')