Repository navigation
Expand file tree
/
Copy pathbot.py
More file actions
429 lines (392 loc) · 19 KB
/
Copy pathbot.py
File metadata and controls
429 lines (392 loc) · 19 KB
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# -*- coding: utf-8 -*-
from discord.ext import commands
import discord
import os
import asyncio
import datetime
from discord_slash import SlashCommand
from modules import help, utils
from discord_components import DiscordComponents
import os
import threading
from pymongo import MongoClient
from typing import Optional
with open('./mongourl.txt', 'r') as file:
url = file.read()
class Prefix:
def __init__(self):
self._prefix_cache = {}
def __str__(self):
return self._prefix_cache
def update(self, guild:discord.Guild, prefix):
self._prefix_cache[guild.id] = prefix
def prefix(self, guild):
return self._prefix_cache[guild.id]
prefgetter = Prefix()
def get_prefix(client, msg):
if msg.guild:
prefix = prefgetter.prefix(msg.guild)
print(prefix, msg.guild.name)
return commands.when_mentioned_or(prefix)(client, msg)
else:
return commands.when_mentioned_or('.')(client, msg)
mongo_url = url.strip()
cluster = MongoClient(mongo_url)
client = commands.AutoShardedBot(command_prefix=get_prefix, intents = discord.Intents().all(), allowed_mentions=discord.AllowedMentions.none(), case_insenstive = True, strip_after_prefix = True)
slash = SlashCommand(client, sync_commands = True)
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f"cogs.{filename[:-3]}")
print(f"{str(filename[:-3]).capitalize()} {'are' if filename[:-3].endswith('s') else 'is'} loaded.")
client.help_command = help.Help()
def voiceChatMain():
os.system('cd DJFlame && node .')
t1 = threading.Thread(target=voiceChatMain)
_command_cache = {}
_cog_cache = {}
FORBIDDEN_COGS = [
'Configuration',
'Slash'
]
@client.event
async def on_ready():
print('heretoo')
db = cluster['CONFIGURATION']
col = db['guilds']
for guild in client.guilds:
if col.count_documents({"_id":guild.id}) == 0:
pass
else:
res = col.find({"_id":guild.id})
for i in res:
prefix = i['prefix']
prefgetter.update(guild, prefix)
t1.start()
print(f"{client.user.name} is ready, logged on awwwwwwwwwwwwwwwwdddddddddddsat {datetime.datetime.utcnow()}.")
await client.change_presence(activity=discord.Game(name=f'Watching {len(client.guilds)} servers'))
try:
for guild in client.guilds:
try:
utils.add_guild_to_db(guild)
except:
continue
DiscordComponents(client, change_discord_methods=True)
except Exception as e:
print(e)
db = cluster['DISABLED_COMMANDS']
col = db['channels']
res = col.find()
resarr = []
for i in res:
resarr.append((i["name"], i["channels"]))
for i in resarr:
_command_cache[i[0]] = (i[1])
col = db['modules']
res = col.find()
resarr = []
for i in res:
resarr.append((i["name"], i["channels"]))
for i in resarr:
_cog_cache[i[0]] = (i[1])
@client.check
async def is_blacklisted(ctx):
if ctx.command.name == 'help':
return True
try:
if ctx.channel.id in _command_cache[ctx.command.qualified_name]:
embed = discord.Embed(color = discord.Color.red())
embed.description = f"This command is disabled in {ctx.channel.mention}."
await ctx.send(embed=embed)
return False
except LookupError:
pass
try:
if ctx.channel.id in _cog_cache[ctx.command.cog.qualified_name]:
embed = discord.Embed(color=discord.Color.red())
embed.description = f"This module is disabled in {ctx.channel.mention}."
await ctx.send(embed=embed)
return False
return True
except LookupError:
return True
except AttributeError:
return True
@client.command(help='Gives the ping of the bot!', aliases = ['clientping'])
async def botping(ctx):
return await ctx.send(f"{round(client.latency * 1000)}ms")
@client.command()
async def feedback(ctx):
try:
await ctx.send(f'{ctx.author.mention}, thank you for using InfiniBot. Please state your feedback here:')
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
message = await client.wait_for('message', check=check, timeout=120)
channel = client.get_channel(839951602168496149)
fembed = discord.Embed(title=f"Feedback from {ctx.author} who is in the server **{ctx.guild.name}**",
description=f"{ctx.author.id} (User ID)\n{ctx.guild.id} (Guild ID)```" + message.content + "```",
color=discord.Color.blurple(), timestamp = datetime.datetime.utcnow())
msg = await channel.send(embed=fembed)
await msg.add_reaction(str('<:thumbsup:829860462966734898>'))
await msg.add_reaction(str('<:thumbsdown:829860507125153795>'))
await message.add_reaction(str('<:checked:829061772446531624>'))
await ctx.send(str(f'{ctx.author.mention}, your feedback has been sent.'))
except asyncio.TimeoutError:
await ctx.reply("Timed out.", mention_author=False, delete_after=5)
@client.command(aliases = ['invite', 'botinvite'])
async def botinv(ctx):
embed = discord.Embed(title="InfiniBot Invite Link",
description=r'https://discord.com/api/oauth2/authorize?client_id=829464107710677022&permissions=4294307063&scope=bot%20applications.commands',
color=discord.Color.blurple())
embed.set_footer(text=f"InfiniBot Help | Requested by {ctx.author.name}")
await ctx.reply(embed=embed)
@client.command()
@commands.guild_only()
@commands.has_guild_permissions(manage_guild = True)
async def togglecommand(ctx, commnd:Optional[str] = None, channel:Optional[discord.TextChannel] = None, guild:Optional[bool] = None):
await ctx.trigger_typing()
db = cluster['DISABLED_COMMANDS']
try:
if commnd is None:
return await ctx.send("You need to specify which command you want to disable.")
command = client.get_command(commnd.lower())
if command.qualified_name.startswith('setup'):
return await ctx.send("You cannot disable any of the setup commands.")
if command is None:
embed = discord.Embed(color = discord.Color.red())
embed.description = f"Sorry, it looks like the command `{commnd.strip()}` could not be found.\n\n" \
f"Please make sure that if you were trying to reference a nested command, such as `{ctx.prefix}setup welcometext`, you type the **ENTIRE COMMAND, WRAPPED IN QUOTES!!!**.\n\n" \
f"EXAMPLE: `{ctx.prefix}togglecommand \"setup welcometext\"`."
embed.set_footer(text=f"To disable a command in the server, type \"on\" or \"off\" right after the command name. To disable it in a channel, "
f"mention the channel after the command name.")
return await ctx.send(embed=embed)
if channel is not None:
print('here3332')
channel = channel
chan = True
elif channel is None and guild is None:
channel = ctx.channel
chan = True
elif channel is None and guild is not None:
#guild toggle
chan = False
else:
return
print(guild)
col = db['channels']
if chan:
if col.count_documents({"name":command.qualified_name, "channels":channel.id}) == 0:
if col.count_documents({"name": command.qualified_name}) == 0:
payload = {
'name':command.qualified_name,
'channels':[channel.id]
}
col.insert_one(payload)
try:
if _command_cache[command.qualified_name].count(channel.id) > 0:
pass
else:
_command_cache[command.qualified_name].append(channel.id)
except LookupError:
_command_cache[command.qualified_name] = [channel.id]
else:
print('here')
col.update_one({"name":command.qualified_name}, {"$set":{"channels":[channel.id]}})
try:
if _command_cache[command.qualified_name].count(channel.id) > 0:
pass
else:
_command_cache[command.qualified_name].append(channel.id)
except LookupError:
_command_cache[command.qualified_name] = [channel.id]
await ctx.send(f"The command `{command.qualified_name}` has been blacklisted in {channel.mention}!")
else:
print('sus')
col.update_one({"name":command.qualified_name}, {"$pull":{"channels":channel.id}})
if _command_cache[command.qualified_name].count(channel.id) < 1:
pass
else:
_command_cache[command.qualified_name].pop(_command_cache[command.qualified_name].index(channel.id))
await ctx.send(f"The command `{command.qualified_name}` has been whitelisted in {channel.mention}!")
else: #guild blacklist the command
if not guild:
for channel in ctx.guild.text_channels:
if col.count_documents({"name":command.qualified_name, "channels":channel.id}) == 0:
if col.count_documents({"name": command.qualified_name}) == 0:
payload = {
'name':command.qualified_name,
'channels':[channel.id]
}
col.insert_one(payload)
try:
if _command_cache[command.qualified_name].count(channel.id) > 0:
pass
else:
_command_cache[command.qualified_name].append(channel.id)
except LookupError:
_command_cache[command.qualified_name] = [channel.id]
else:
print('here')
col.update_one({"name":command.qualified_name}, {"$set":{"channels":[channel.id]}})
try:
if _command_cache[command.qualified_name].count(channel.id) > 0:
pass
else:
_command_cache[command.qualified_name].append(channel.id)
except LookupError:
_command_cache[command.qualified_name] = [channel.id]
else:
continue
await ctx.send(f"Command {command.qualified_name} has been blacklisted from this server.")
else:
for channel in ctx.guild.text_channels:
if col.count_documents({"name": command.qualified_name, "channels": channel.id}) != 0:
if col.count_documents({"name": command.qualified_name}) == 0:
break
else:
print('here')
col.update_one({"name": command.qualified_name}, {"$pull": {"channels": channel.id}})
try:
if _command_cache[command.qualified_name].count(channel.id) > 0:
pass
else:
_command_cache[command.qualified_name].append(channel.id)
except LookupError:
_command_cache[command.qualified_name] = [channel.id]
else:
continue
await ctx.send(f"Command {command.qualified_name} has been whitelisted from this server.")
except Exception as e:
print(e)
@client.command()
@commands.guild_only()
@commands.has_guild_permissions(manage_guild = True)
async def togglemodule(ctx, cogz = None, channel:Optional[discord.TextChannel] = None, guild:Optional[bool] = None):
await ctx.trigger_typing()
db = cluster['DISABLED_COMMANDS']
try:
if cogz is None:
return await ctx.send("You need to specify which module you want to disable.")
cog = client.get_cog(cogz.title())
if cog is None:
embed = discord.Embed(color = discord.Color.red())
embed.description = f"Sorry, it looks like the module `{cogz.strip()}` could not be found.\n\n" \
f"Please make sure that if you were trying to reference a module that has two words, such as `Google Classroom`, you type the **ENTIRE MODULE NAME, WRAPPED IN QUOTES!!!**.\n\n" \
f"EXAMPLE: `{ctx.prefix}togglemodule \"Google Classroom\"`.\n\n" \
f"If you are sure that you are typing the correct name, run the {ctx.prefix}help command to make sure. **NOTE: CASE SENSITIVE!**"
embed.set_footer(text=f"To disable a module in the server, type \"on\" or \"off\" right after the module name. To disable it in a channel, "
f"mention the channel after the module\'s name.")
return await ctx.send(embed=embed)
if cog in FORBIDDEN_COGS:
return await ctx.send("You are not allowed to disable this module.")
if channel is not None:
print('here3332')
channel = channel
chan = True
elif channel is None and guild is None:
channel = ctx.channel
chan = True
elif channel is None and guild is not None:
#guild toggle
chan = False
else:
return
print(guild)
col = db['modules']
if chan:
if col.count_documents({"name":cog.qualified_name, "channels":channel.id}) == 0:
if col.count_documents({"name": cog.qualified_name}) == 0:
payload = {
'name':cog.qualified_name,
'channels':[channel.id]
}
col.insert_one(payload)
try:
if _cog_cache[cog.qualified_name].count(channel.id) > 0:
pass
else:
_cog_cache[cog.qualified_name].append(channel.id)
except LookupError:
_cog_cache[cog.qualified_name] = [channel.id]
else:
print('here')
col.update_one({"name":cog.qualified_name}, {"$set":{"channels":[channel.id]}})
try:
if _cog_cache[cog.qualified_name].count(channel.id) > 0:
pass
else:
_cog_cache[cog.qualified_name].append(channel.id)
except LookupError:
_cog_cache[cog.qualified_name] = [channel.id]
await ctx.send(f"The module `{cog.qualified_name}` has been blacklisted in {channel.mention}!")
else:
print('sus')
try:
col.update_one({"name":cog.qualified_name}, {"$pull":{"channels":channel.id}})
if _cog_cache[cog.qualified_name].count(channel.id) < 1:
pass
else:
_cog_cache[cog.qualified_name].pop(_cog_cache[cog.qualified_name].index(channel.id))
except Exception:
pass
await ctx.send(f"The module `{cog.qualified_name}` has been whitelisted in {channel.mention}!")
return
else: #guild blacklist the cog
if not guild:
for channel in ctx.guild.text_channels:
if col.count_documents({"name":cog.qualified_name, "channels":channel.id}) == 0:
if col.count_documents({"name": cog.qualified_name}) == 0:
payload = {
'name':cog.qualified_name,
'channels':[channel.id]
}
col.insert_one(payload)
try:
if _cog_cache[cog.qualified_name].count(channel.id) > 0:
pass
else:
_cog_cache[cog.qualified_name].append(channel.id)
except LookupError:
_cog_cache[cog.qualified_name] = [channel.id]
else:
print('here')
try:
col.update_one({"name": cog.qualified_name}, {"$push": {"channels": channel.id}})
except:
pass
try:
if _cog_cache[cog.qualified_name].count(channel.id) > 0:
pass
else:
_cog_cache[cog.qualified_name].append(channel.id)
except LookupError:
_cog_cache[cog.qualified_name] = [channel.id]
else:
continue
await ctx.send(f"The module `{cog.qualified_name}` has been blacklisted from this server.")
else:
print('here23212321')
for channel in ctx.guild.text_channels:
if col.count_documents({"name": cog.qualified_name, "channels": channel.id}) != 0:
if col.count_documents({"name": cog.qualified_name}) == 0:
print('here??')
break
else:
print('here')
col.update_one({"name":cog.qualified_name}, {"$pull":{"channels":channel.id}})
print(f'pulled {channel.name} from {channel.id}')
try:
if _cog_cache[cog.qualified_name].count(channel.id) > 0:
pass
else:
_cog_cache[cog.qualified_name].append(channel.id)
except LookupError:
_cog_cache[cog.qualified_name] = [channel.id]
else:
print('continue')
continue
await ctx.send(f"The module `{cog.qualified_name}` has been whitelisted from this server.")
except Exception as e:
print(e)
with open('token.txt', 'r') as f:
token = f.read()
client.run(token)