11
11
import io
12
12
import sr_api
13
13
import humanize
14
- import aiohttp
15
14
import asyncpg
16
15
import ext .helpers as helpers
17
16
from PIL import Image , ImageDraw , ImageFont , ImageFilter
18
17
from dotenv import load_dotenv
19
18
from discord .ext import commands , tasks
20
- from discord_slash import SlashCommand , SlashContext
21
- from dislash import SlashClient
22
19
23
20
24
21
async def prefix (bot_ , message ):
@@ -30,7 +27,7 @@ class CustomHelp(commands.HelpCommand):
30
27
31
28
def get_ending_note (self ):
32
29
return 'Use {0}{1} [command] for more info on a command.' .format (
33
- self .clean_prefix , self .invoked_with )
30
+ self .context . clean_prefix , self .invoked_with )
34
31
35
32
def get_command_signature (self , command ):
36
33
parent = command .full_parent_name
@@ -90,9 +87,9 @@ async def send_group_help(self, group):
90
87
embed .set_footer (text = self .get_ending_note ())
91
88
await self .get_destination ().send (embed = embed )
92
89
93
- # This makes it so it uses the function above
90
+ # This makes it use the function above
94
91
# Less work for us to do since they're both similar.
95
- # If you want to make regular command help look different then override it
92
+ # If you want to make regular command help look different, then override it
96
93
send_command_help = send_group_help
97
94
98
95
@@ -110,7 +107,7 @@ async def send_group_help(self, group):
110
107
init_data = helpers .storage (bot )
111
108
112
109
113
- class pools :
110
+ class Pools :
114
111
config = asyncpg .create_pool (database = 'codingbot_db' ,
115
112
init = helpers .init_connection )
116
113
@@ -119,7 +116,7 @@ class pools:
119
116
bot .tracker = DiscordUtils .InviteTracker (bot )
120
117
bot .default_prefixes = [',' ]
121
118
bot .server_cache = {}
122
- bot .pools = pools
119
+ bot .pools = Pools
123
120
bot .owner_id = None
124
121
bot .owner_ids = init_data ['owners' ]
125
122
bot .blacklisted = init_data ['blacklisted' ]
@@ -129,8 +126,6 @@ class pools:
129
126
bot .sr_api = sr_api .Client ()
130
127
bot .sr_api_premium = False
131
128
bot .processing_commands = 0
132
- bot .slash = SlashCommand (bot , sync_commands = True )
133
- bot .dislash = SlashClient (bot )
134
129
for cog in bot .active_cogs :
135
130
try :
136
131
bot .load_extension (cog )
@@ -148,7 +143,8 @@ async def on_message(message):
148
143
ctx = await bot .get_context (message , cls = helpers .Context )
149
144
await bot .invoke (ctx )
150
145
for prefix_ in await prefix (bot , message ):
151
- if message .content .startswith (f'\\ { prefix_ } ' ) and bot .get_command (message .content .split ()[0 ][len (prefix_ ) + 1 :]):
146
+ if (message .content .startswith (f'\\ { prefix_ } ' )
147
+ and bot .get_command (message .content .split ()[0 ][len (prefix_ ) + 1 :])):
152
148
return await message .channel .send ('lol' )
153
149
154
150
@@ -191,31 +187,31 @@ async def on_member_join(member):
191
187
if not member .guild .id == 681882711945641997 :
192
188
return
193
189
if not member .name .isalnum ():
194
- await member .edit (nick = unicodedata .normalize ('NFKD' ,member .name ))
190
+ await member .edit (nick = unicodedata .normalize ('NFKD' , member .name ))
195
191
if member .bot :
196
192
channel = member .guild .get_channel (743817386792058971 )
197
193
return await channel .send (content = f'Bot added: { member .mention } ' )
198
194
inviter = await bot .tracker .fetch_inviter (member )
199
195
rules = member .guild .rules_channel .mention
200
196
embed = discord .Embed (
201
- title = 'Welcome to The Coding Realm !' ,
197
+ title = f 'Welcome to { member . guild . name } !' ,
202
198
description = (
203
199
f'Welcome { member .mention } , we\' re glad you joined! Before you get'
204
200
' started, here are some things to check out: \n **Read the Rules:'
205
201
f'** { rules } \n **Get roles:** <#726074137168183356> and '
206
202
'<#806909970482069556> \n **Want help? Read here:** '
207
203
'<#799527165863395338> and <#754712400757784709>' ),
208
- timestamp = datetime .datetime .utcnow ( ))
209
- ago = datetime .datetime .utcnow ( ) - member .created_at
210
- img = io .BytesIO (await member .avatar_url_as ( format = ' png' , size = 128 ).read ())
204
+ timestamp = datetime .datetime .now ( datetime . timezone . utc ))
205
+ ago = datetime .datetime .now ( datetime . timezone . utc ) - member .created_at
206
+ img = io .BytesIO (await member .avatar . with_format ( " png" ). with_size ( 128 ).read ())
211
207
try :
212
- img2 = io .BytesIO (await member .guild .banner_url_as ( format = ' png' , size = 512 ).read ())
208
+ img2 = io .BytesIO (await member .guild .banner . with_format ( " png" ). with_size ( 512 ).read ())
213
209
except :
214
210
img2 = 'storage/banner.png'
215
211
base = Image .open (img ).convert ("RGBA" )
216
212
base = base .resize ((128 , 128 ))
217
213
txt = Image .open (img2 ).convert ("RGBA" )
218
- txt = txt .point (lambda p : p * 0.5 )
214
+ txt = txt .point (lambda p : int ( p * 0.5 ) )
219
215
txt = txt .resize ((512 , 200 ))
220
216
d = ImageDraw .Draw (txt )
221
217
fill = (255 , 255 , 255 , 255 )
@@ -243,7 +239,7 @@ async def on_member_join(member):
243
239
try :
244
240
invite = await member .guild .vanity_invite ()
245
241
text = f'• Joined using vanity invite: { invite .code } ({ invite .uses } uses)'
246
- except discord .errors . HTTPException :
242
+ except discord .HTTPException :
247
243
text = 'I couldn\' t find who invited them'
248
244
d .text (((txt .size [0 ] // 8 ) * 3 , (txt .size [1 ] // 16 ) * 9 ), text , font = font , fill = fill , align = 'center' )
249
245
text = f'• Account created: { humanize .naturaldelta (ago )} ago'
@@ -265,7 +261,10 @@ async def on_member_join(member):
265
261
channel = member .guild .get_channel (743817386792058971 )
266
262
await channel .send (content = member .mention , file = file )
267
263
verify_here = member .guild .get_channel (759220767711297566 )
268
- await verify_here .send (f'Welcome { member .mention } ! Follow the instructions in other channels to get verified. :)' , embed = embed )
264
+ await verify_here .send (f'Welcome { member .mention } ! Follow the instructions in other channels to get verified. :)' ,
265
+ embed = embed )
266
+
267
+
269
268
# try:
270
269
# await member.send(embed=embed)
271
270
# except discord.errors.Forbidden:
@@ -292,7 +291,7 @@ async def on_command_error(ctx, error):
292
291
commands .MissingPermissions , commands .MaxConcurrencyReached ))):
293
292
try :
294
293
await ctx .reinvoke ()
295
- except discord .ext .commands .CommandError as e :
294
+ except discord .ext .commands .CommandError :
296
295
pass
297
296
else :
298
297
return
@@ -319,10 +318,10 @@ async def on_command_error(ctx, error):
319
318
if not isinstance (error , commands .CommandNotFound ):
320
319
embed = ctx .embed (title = "Error" , description = text ,
321
320
color = discord .Color .red ())
322
- embed .set_author (name = ctx .author , icon_url = ctx .author .avatar_url )
321
+ embed .set_author (name = ctx .author , icon_url = ctx .author .avatar . url )
323
322
owner = bot .get_user (ctx .bot .owner_ids [0 ])
324
323
embed .set_footer (
325
- icon_url = bot .user .avatar_url ,
324
+ icon_url = bot .user .avatar . url ,
326
325
text = f'If you think this is a mistake please contact { owner } ' )
327
326
await ctx .send (embed = embed )
328
327
@@ -333,10 +332,10 @@ async def on_command_error(ctx, error):
333
332
f'{ humanize .precisedelta (time )} ' )
334
333
embed = ctx .embed (title = "Error" , description = error ,
335
334
color = discord .Color .red ())
336
- embed .set_author (name = ctx .author , icon_url = ctx .author .avatar_url )
335
+ embed .set_author (name = ctx .author , icon_url = ctx .author .avatar . url )
337
336
owner = bot .get_user (ctx .bot .owner_ids [0 ])
338
337
embed .set_footer (
339
- icon_url = bot .user .avatar_url ,
338
+ icon_url = bot .user .avatar . url ,
340
339
text = f'If you think this is a mistake please contact { owner } ' )
341
340
await ctx .send (embed = embed )
342
341
@@ -347,7 +346,7 @@ async def on_command_error(ctx, error):
347
346
'but if it continues to occur please DM '
348
347
f'<@{ ctx .bot .owner_ids [0 ]} >' ), color = discord .Color .red ())
349
348
await ctx .send (embed = embed )
350
- except discord .errors . Forbidden :
349
+ except discord .Forbidden :
351
350
pass
352
351
await helpers .log_command_error (ctx , exception , False )
353
352
@@ -451,27 +450,33 @@ async def _reloadall(self, ctx):
451
450
452
451
@bot .before_invoke
453
452
async def before_invoke (ctx ):
454
- bot .processing_commands += 1
453
+ ctx . bot .processing_commands += 1
455
454
456
455
457
456
@bot .after_invoke
458
457
async def after_invoke (ctx ):
459
- bot .processing_commands -= 1
458
+ ctx . bot .processing_commands -= 1
460
459
461
460
462
461
@tasks .loop (minutes = 2 )
463
462
async def status_change ():
464
- statuses = ['over TCR' , 'you' , 'swas' , '@everyone' , 'general chat' , 'discord' , ',help' , 'your mom' ,
465
- 'bob and shadow argue' , 'swas simp for false' , 'new members' , 'the staff team' ,
466
- random .choice (bot .get_guild (681882711945641997 ).get_role (795145820210462771 ).members ).name ,
467
- 'helpers' , 'code' , 'mass murders' , 'karen be an idiot' , 'a video' , 'watches' , 'bob' ,
468
- 'fight club' , 'youtube' , 'https://devbio.me/u/CodingBot' , 'potatoes' , 'simps' , 'people' , 'my server' ,
469
- 'humans destroy the world' , 'AI take over the world' , 'female bots 😳' , 'dinosaurs' ,
470
- 'https://youtu.be/dQw4w9WgXcQ' , 'idiots' , 'the beginning of WWIII' , 'verified bot tags with envy' ,
471
- random .choice (bot .get_guild (681882711945641997 ).get_role (737517726737629214 ).members ).name +
472
- ' (Server Booster)' , 'Server Boosters (boost to get your name on here)' , 'OG members' ,
473
- "dalek rising from the ashes" , 'spongebob' , 'turtles' , 'SQUIRREL!!!' , 'people get banned' , 'por...k chops' ,
474
- 'my poggers discriminator' , 'tux' , 'linux overcome windows' , 'bob get a gf' , 'a documentary' ]
463
+
464
+ statuses = ['over TCR' , 'you' , 'swas' , '@everyone' , 'general chat' , 'discord' , ',help' , 'your mom' ,
465
+ 'bob and shadow argue' , 'swas simp for false' , 'new members' , 'the staff team' , 'helpers' , 'code' ,
466
+ 'mass murders' , 'karen be an idiot' , 'a video' , 'watches' , 'bob' , 'fight club' , 'youtube' ,
467
+ 'https://devbio.me/u/CodingBot' , 'potatoes' , 'simps' , 'people' , 'my server' , 'humans destroy the world' ,
468
+ 'AI take over the world' , 'female bots 😳' , 'dinosaurs' , 'https://youtu.be/dQw4w9WgXcQ' , 'idiots' ,
469
+ 'the beginning of WWIII' , 'verified bot tags with envy' ,
470
+ 'Server Boosters (boost to get your name on here)' , 'OG members' , "dalek rising from the ashes" ,
471
+ 'spongebob' , 'turtles' , 'SQUIRREL!!!' , 'people get banned' , 'por...k chops' , 'my poggers discriminator' ,
472
+ 'tux' , 'linux overcome windows' , 'bob get a gf' , 'a documentary' ]
473
+ tcr = bot .get_guild (681882711945641997 )
474
+ if tcr :
475
+ if tcr .get_role (795145820210462771 ):
476
+ statuses .append (random .choice (tcr .get_role (795145820210462771 ).members ).name )
477
+ if tcr .get_role (737517726737629214 ):
478
+ statuses .append (random .choice (tcr .get_role (737517726737629214 ).members ).name + ' (Server Booster)' )
479
+
475
480
await bot .change_presence (activity = discord .Activity (
476
481
type = discord .ActivityType .watching ,
477
482
name = random .choice (
@@ -489,14 +494,16 @@ async def before_status_change():
489
494
@tasks .loop (minutes = 5 )
490
495
async def booster_perms ():
491
496
guild = bot .get_guild (681882711945641997 )
497
+ if not guild :
498
+ return
492
499
nitro_booster = guild .get_role (737517726737629214 )
493
500
active = guild .get_role (726029173067481129 )
494
501
muted = guild .get_role (766469426429820949 )
495
502
for member in nitro_booster .members :
496
503
if not (active in member .roles or muted in member .roles ):
497
504
try :
498
505
await member .add_roles (active )
499
- except discord .errors . Forbidden :
506
+ except discord .Forbidden :
500
507
pass
501
508
502
509
@@ -523,20 +530,21 @@ async def disabled_command(ctx):
523
530
or ctx .author .id == ctx .guild .owner .id )
524
531
525
532
526
- @bot .slash . slash (name = 'help' , description = 'Get the help for the bot' )
527
- async def slash_help (ctx : SlashContext ):
528
- await ctx .send ( embeds = [ discord .Embed (title = 'Hello There!' , description = (
533
+ @bot .slash_command (name = 'help' , description = 'Get the help for the bot' )
534
+ async def slash_help (ctx ):
535
+ await ctx .respond ( embed = discord .Embed (title = 'Hello There!' , description = (
529
536
'I use special command prefixes for my commands. Please type \n '
530
- f'{ bot .user .mention + " help" } \n for my full help menu!' ))] )
537
+ f'{ bot .user .mention + " help" } \n for my full help menu!' )))
531
538
532
539
533
- @bot .slash . slash (name = 'invite' , description = 'Invite the bot to your server' )
534
- async def slash_invite (ctx : SlashContext ):
540
+ @bot .slash_command (name = 'invite' , description = 'Invite the bot to your server' )
541
+ async def slash_invite (ctx ):
535
542
embed = discord .Embed (title = 'Invite' , description = (
536
543
'[Click Here](https://discord.com/oauth2/authorize?client_id='
537
544
f'{ bot .user .id } &permissions=8&scope=bot%20applications.commands) '
538
- 'to invite me!' ), timestamp = datetime .datetime .utcnow ())
539
- await ctx .send (embeds = [embed ])
545
+ 'to invite me!' ), timestamp = datetime .datetime .now (datetime .timezone .utc ))
546
+ await ctx .respond (embed = embed )
547
+
540
548
541
549
status_change .start ()
542
550
booster_perms .start ()
0 commit comments