This repository has been archived by the owner on Jul 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
249 lines (224 loc) · 11.2 KB
/
admin.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# This file is part of torn-bot.
#
# torn-bot is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# torn-bot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with torn-bot. If not, see <https://www.gnu.org/licenses/>.
import discord
from discord.ext import commands
from required import *
import dbutils
class Admin(commands.Cog):
def __init__(self, logger, bot, client):
self.logger = logger
self.bot = bot
self.client = client
@commands.command()
@commands.cooldown(1, 5, commands.BucketType.user)
async def config(self, ctx, arg=None, value=None):
'''
Returns the current configuration of the bot
'''
if not check_admin(ctx.message.author) and dbutils.get_superuser() != ctx.message.author.id:
embed = discord.Embed()
embed.title = "Permission Denied"
embed.description = f'This command requires {ctx.message.author.name} to be an Administrator. ' \
f'This interaction has been logged.'
await ctx.send(embed=embed)
self.logger.warning(f'{ctx.message.author.name} has attempted to run config, but is not an Administrator')
return None
embed = discord.Embed()
if not arg:
embed = None
page1 = discord.Embed(
title="Configuration",
description=f'''Torn API Key: Classified
Bot Token: Classified
Prefix: {get_prefix(self.bot, ctx.message)}
Superuser: {dbutils.get_superuser()}''',
).set_footer(text="Page 1/2")
page2 = discord.Embed(
title="Configuration: Vault",
description=f'''Vault Channel: {dbutils.read("vault")[str(ctx.guild.id)]["channel"]}
Vault Channel 2: {dbutils.read("vault")[str(ctx.guild.id)]["channel2"]}
Vault Role: {dbutils.read("vault")[str(ctx.guild.id)]["role"]}
Vault Role 2: {dbutils.read("vault")[str(ctx.guild.id)]["role2"]}
Banking Channel: {dbutils.read("vault")[str(ctx.guild.id)]["banking"]}'''
).set_footer(text="Page 2/2")
pages = [page1, page2]
message = await ctx.send(embed=page1)
await message.add_reaction('⏮')
await message.add_reaction('◀')
await message.add_reaction('▶')
await message.add_reaction('⏭')
def check(reaction, user):
return user == ctx.author
i = 0
reaction = None
while True:
if str(reaction) == '⏮':
i = 0
await message.edit(embed=pages[i])
elif str(reaction) == '◀':
if i > 0:
i -= 1
await message.edit(embed=pages[i])
elif str(reaction) == '▶':
if i < 2:
i += 1
await message.edit(embed=pages[i])
elif str(reaction) == '⏭':
i = 2
await message.edit(embed=pages[i])
try:
reaction, user = await self.bot.wait_for('reaction_add', timeout=30.0, check=check)
await message.remove_reaction(reaction, user)
except:
break
await message.clear_reactions()
# Configurations that require a value below here
elif not value:
embed.title = "Value Error"
embed.description = "A value must be passed"
elif arg == "vc":
for channel in ctx.guild.channels:
if str(channel.id) != value[2:-1]:
continue
data = dbutils.read("vault")
data[str(ctx.guild.id)]["channel"] = channel.name
dbutils.write("vault", data)
self.logger.info(f'Vault Channel has been set to {data[str(ctx.guild.id)]["channel"]}.')
embed.title = "Vault Channel"
embed.description = f'Vault Channel has been set to {data[str(ctx.guild.id)]["channel"]}.'
elif arg == "vc2":
for channel in ctx.guild.channels:
if str(channel.id) != value[2:-1]:
continue
data = dbutils.read("vault")
data[str(ctx.guild.id)]["channel2"] = channel.name
dbutils.write("vault", data)
self.logger.info(f'Vault Channel 2 has been set to {data[str(ctx.guild.id)]["channel2"]}.')
embed.title = "Vault Channel 2"
embed.description = f'Vault Channel 2 has been set to {data[str(ctx.guild.id)]["channel2"]}.'
elif arg == "vc3":
for channel in ctx.guild.channels:
if str(channel.id) != value[2:-1]:
continue
data = dbutils.read("vault")
data[str(ctx.guild.id)]["channel3"] = channel.name
dbutils.write("vault", data)
self.logger.info(f'Vault Channel 3 has been set to {data[str(ctx.guild.id)]["channel3"]}.')
embed.title = "Vault Channel 3"
embed.description = f'Vault Channel 3 has been set to {data[str(ctx.guild.id)]["channel3"]}.'
elif arg == "vr":
for role in ctx.guild.roles:
if role.mention != value:
continue
data = dbutils.read("vault")
data[str(ctx.guild.id)]["role"] = str(role.mention)
dbutils.write("vault", data)
self.logger.info(f'Vault Role has been set to {data[str(ctx.guild.id)]["role"]}.')
embed.title = "Vault Role"
embed.description = f'Vault Role has been set to {data[str(ctx.guild.id)]["role"]}.'
elif arg == "vr2":
for role in ctx.guild.roles:
if role.mention != value:
continue
data = dbutils.read("vault")
data[str(ctx.guild.id)]["role2"] = str(role.mention)
dbutils.write("vault", data)
self.logger.info(f'Vault Role has been set to {data[str(ctx.guild.id)]["role2"]}.')
embed.title = "Vault Role"
embed.description = f'Vault Role has been set to {data[str(ctx.guild.id)]["role2"]}.'
elif arg == "vr3":
for role in ctx.guild.roles:
if role.mention != value:
continue
data = dbutils.read("vault")
data[str(ctx.guild.id)]["role3"] = str(role.mention)
dbutils.write("vault", data)
self.logger.info(f'Vault Role has been set to {data[str(ctx.guild.id)]["role3"]}.')
embed.title = "Vault Role"
embed.description = f'Vault Role has been set to {data[str(ctx.guild.id)]["role3"]}.'
elif arg == "prefix":
data = dbutils.read("guilds")
for guild in data["guilds"]:
if guild["id"] == str(ctx.guild.id):
guild["prefix"] = str(value)
dbutils.write("guilds", data)
self.logger.info(f'Bot Prefix has been set to {value}.')
embed.title = "Bot Prefix"
embed.description = f'Bot Prefix has been set to {value}.'
elif arg == "key":
data = dbutils.read("guilds")
for guild in data["guilds"]:
if guild["id"] == str(ctx.guild.id):
guild["tornapikey"] = str(value)
dbutils.write("guilds", data)
self.logger.info(f'{ctx.message.author.name} has set the primary Torn API Key.')
embed.title = "Torn API Key"
embed.description = f'The Torn API key for the primary faction has been set by {ctx.message.author.name}.'
await ctx.message.delete()
elif arg == "key2":
data = dbutils.read("guilds")
for guild in data["guilds"]:
if guild["id"] == str(ctx.guild.id):
guild["tornapikey2"] = str(value)
dbutils.write("guilds", data)
self.logger.info(f'{ctx.message.author.name} has set the secondary Torn API Key.')
embed.title = "Torn API Key"
embed.description = f'The Torn API key for the secondary faction has been set by {ctx.message.author.name}.'
await ctx.message.delete()
elif arg == "key3":
data = dbutils.read("guilds")
for guild in data["guilds"]:
if guild["id"] == str(ctx.guild.id):
guild["tornapikey3"] = str(value)
dbutils.write("guilds", data)
self.logger.info(f'{ctx.message.author.name} has set the secondary Torn API Key.')
embed.title = "Torn API Key"
embed.description = f'The Torn API key for the secondary faction has been set by {ctx.message.author.name}.'
await ctx.message.delete()
elif arg == "bc":
for channel in ctx.guild.channels:
if str(channel.id) != value[2:-1]:
continue
data = dbutils.read("vault")
data[str(ctx.guild.id)]["banking"] = str(channel.id)
dbutils.write("vault", data)
self.logger.info(f'Banking Channel has been set to {data[str(ctx.guild.id)]["banking"]}.')
embed.title = "Banking Channel"
embed.description = f'Banking Channel has been set to {channel.name}.'
elif arg == "bc2":
for channel in ctx.guild.channels:
if str(channel.id) != value[2:-1]:
continue
data = dbutils.read("vault")
data[str(ctx.guild.id)]["banking2"] = str(channel.id)
dbutils.write("vault", data)
self.logger.info(f'Banking Channel 2 has been set to {data[str(ctx.guild.id)]["banking2"]}.')
embed.title = "Banking Channel 2"
embed.description = f'Banking Channel 2 has been set to {channel.name}.'
elif arg == "bc3":
for channel in ctx.guild.channels:
if str(channel.id) != value[2:-1]:
continue
data = dbutils.read("vault")
data[str(ctx.guild.id)]["banking3"] = str(channel.id)
dbutils.write("vault", data)
self.logger.info(f'Banking Channel 3 has been set to {data[str(ctx.guild.id)]["banking3"]}.')
embed.title = "Banking Channel 3"
embed.description = f'Banking Channel 3 has been set to {channel.name}.'
else:
embed.title = "Configuration"
embed.description = "This key is not a valid configuration key."
if embed is not None:
await ctx.send(embed=embed)