Skip to content

Commit a0653ed

Browse files
committed
Fix bugs and add sync to debug
1 parent cd93570 commit a0653ed

File tree

8 files changed

+107
-53
lines changed

8 files changed

+107
-53
lines changed

Diff for: launcher.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import asyncio
22
import atexit
33
import glob
4+
import math
45
from http.client import HTTPException
56

67
import discord
78
import numpy as np
89
import requests
910
from discord import Embed, NotFound, Interaction
10-
from discord.app_commands import CommandOnCooldown, MissingPermissions, BotMissingPermissions
11+
from discord.app_commands import CommandOnCooldown, MissingPermissions, BotMissingPermissions, TransformerError
1112

1213
from lib.bot import Bot, IGNORE_EXCEPTIONS
1314
from lib.config import Config
@@ -19,8 +20,10 @@
1920
config = Config()
2021
TOTAL_GUILDS = len(requests.get("https://discord.com/api/v9/users/@me/guilds",
2122
headers={"Authorization": f"Bot {config.token}"}).json())
22-
SHARDS_LIST: list[int] = list(range(round((TOTAL_GUILDS / 1000) + 1)))
23-
CLUSTERS = round((len(SHARDS_LIST) / 2) + 1)
23+
GUILDS_PER_SHARD = 1000
24+
SHARDS_PER_CLUSTER = 100
25+
SHARDS_LIST: list[int] = list(range(math.ceil(TOTAL_GUILDS / GUILDS_PER_SHARD)))
26+
CLUSTERS = math.ceil(len(SHARDS_LIST) / SHARDS_PER_CLUSTER)
2427
SHARDS_SPLIT: list[np.ndarray[int]] = np.array_split(SHARDS_LIST, CLUSTERS)
2528

2629

@@ -37,7 +40,7 @@ async def on_command_error(ctx: Interaction, exc) -> None:
3740
pass
3841
elif isinstance(exc, CommandOnCooldown):
3942
embed: Embed = Embed(title='Command on Cooldown',
40-
description=f"That command is on cooldown. Try again in {exc.retry_after:,.2f} seconds.",
43+
description=f">>> That command is on cooldown. Try again in {exc.retry_after:,.2f} seconds.",
4144
colour=0xff0000)
4245
await bot.send(ctx, embed=embed)
4346
elif isinstance(exc, MissingPermissions):
@@ -47,18 +50,21 @@ async def on_command_error(ctx: Interaction, exc) -> None:
4750
embed: Embed = Embed(title='Bot Missing Permissions', description=f">>> {exc}", colour=0xff0000)
4851
await bot.send(ctx, embed=embed)
4952
elif isinstance(exc, HTTPException):
50-
embed: Embed = Embed(title="Http Error", description='Message failed to send', colour=0xff0000)
53+
embed: Embed = Embed(title="Http Error", description='>>> Message failed to send', colour=0xff0000)
5154
await bot.send(ctx, embed=embed)
5255
elif isinstance(exc, NotFound):
5356
await bot.send(ctx,
54-
embed=Embed(title='Not Found Error', description='One or more items could not be found.',
57+
embed=Embed(title='Not Found Error', description='>>> One or more items could not be found.',
5558
colour=0xff0000))
59+
elif isinstance(exc, TransformerError):
60+
await bot.send(ctx,
61+
embed=Embed(title=':x: | Enter in the correct format', colour=0xff0000))
5662
elif hasattr(exc, "original"):
5763
if isinstance(exc.original, HTTPException):
58-
embed: Embed = Embed(title="Http Error", description='Message failed to send', colour=0xff0000)
64+
embed: Embed = Embed(title="Http Error", description='>>> Message failed to send', colour=0xff0000)
5965
await bot.send(ctx, embed=embed)
6066
if isinstance(exc.original, discord.Forbidden):
61-
embed: Embed = Embed(title='Forbidden Error', description='Insufficient Permissions',
67+
embed: Embed = Embed(title='Forbidden Error', description='>>> Insufficient Permissions',
6268
colour=0xff0000)
6369
await bot.send(ctx, embed=embed)
6470
else:

Diff for: lib/bot/__init__.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
import tzlocal
1111
from apscheduler.schedulers.asyncio import AsyncIOScheduler
1212
from discord import Guild, Interaction, VoiceChannel
13-
from discord.app_commands import Command
13+
from discord.app_commands import Command, CommandOnCooldown, MissingPermissions, BotMissingPermissions
1414
from discord.embeds import Embed
15-
from discord.errors import NotFound
15+
from discord.errors import NotFound, HTTPException, InteractionResponded
1616
from discord.ext.commands import AutoShardedBot
1717
from discord.ext.commands.errors import CommandNotFound, BadArgument
18+
from discord import AutoShardedClient
1819

1920
from lib.config import Config
2021
from lib.db import DB
21-
from lib.progress import Progress, Timer
22+
from lib.errors import BotNotReady
23+
from lib.progress import Progress, Timer, Loading
2224
from lib.urban import UrbanDictionary
2325

2426
COMMAND_ERROR_REGEX = r"Command raised an exception: (.*?(?=: )): (.*)"
@@ -49,10 +51,10 @@ def __init__(self, shards: list[int], version: str):
4951
self.shard_progress.start()
5052

5153
async def on_connect(self):
52-
await self.tree.sync()
5354
while not self.shards_ready:
54-
print('Shards Not Ready')
5555
await asyncio.sleep(.5)
56+
self.tree.copy_global_to(guild=discord.Object(id="1064582321728143421"))
57+
await self.tree.sync(guild=discord.Object(id="1064582321728143421"))
5658
self.register_guilds()
5759
asyncio.ensure_future(self.monitor_shutdown())
5860
print(f"Signed into {self.user.display_name}#{self.user.discriminator}")
@@ -71,29 +73,34 @@ async def on_interaction(self, ctx: Interaction):
7173
name_list, options = self.get_name(ctx.data, [])
7274
name = " ".join(name_list)
7375
self.db.insert.commands(command_name=name, guild_id=ctx.guild_id, user_id=ctx.user.id, params=json.dumps(options), ts=datetime.now().timestamp())
74-
# self.db.run(f"""INSERT INTO commands VALUES (?,?,?,?,?)""", name, ctx.guild_id,
75-
# ctx.user.id, json.dumps(options), datetime.now().timestamp())
76+
self.db.run(f"""INSERT INTO commands VALUES (?,?,?,?,?)""", name, ctx.guild_id,
77+
ctx.user.id, json.dumps(options), datetime.now().timestamp())
78+
79+
7680

7781
@staticmethod
7882
async def send(ctx: Interaction, *args, **kwargs):
7983
if kwargs.get('embed'):
8084
embed: Embed = kwargs['embed']
81-
if not isinstance(embed.colour, discord.Colour):
85+
if embed.colour is None:
8286
color = int("0x" + ''.join([random.choice('0123456789ABCDEF') for j in range(6)]), 16)
8387
embed.colour = color
8488
embed.set_footer(text="Made by Gccody")
8589
embed.timestamp = datetime.now()
8690
# embed.set_thumbnail(url=self.logo_path)
8791
kwargs['embed'] = embed
92+
8893
if ctx.is_expired():
8994
channel = ctx.channel
9095
if not isinstance(channel, VoiceChannel):
9196
return await ctx.channel.send(*args, **kwargs)
9297
try:
93-
await ctx.original_response()
94-
return await ctx.followup.send(*args, **kwargs)
95-
except NotFound:
9698
return await ctx.response.send_message(*args, **kwargs)
99+
except InteractionResponded:
100+
try:
101+
return await ctx.followup.send(*args, **kwargs)
102+
except NotFound:
103+
return await ctx.channel.send(*args, **kwargs)
97104

98105
async def monitor_shutdown(self):
99106
while True:
@@ -111,6 +118,7 @@ async def monitor_shutdown(self):
111118

112119
def register_guilds(self):
113120
progress = Progress('Registering guilds', len(self.guilds))
121+
progress.start()
114122
for guild in self.guilds:
115123
self.db.insert.guilds(id=guild.id)
116124
progress.next()
@@ -120,7 +128,6 @@ def register_guilds(self):
120128
self.db.delete.guilds(id=guild.id)
121129
self.db.commit()
122130
self.ready = True
123-
print('End')
124131
self.tasks.start()
125132

126133
async def on_guild_join(self, guild: Guild):

Diff for: lib/cogs/Fun.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def eightball(self, ctx: Interaction, question: str):
4848
'Signs point to no',
4949
'Most likely not',
5050
]
51-
await ctx.response.send_message(embed=Embed(title=f':8ball: | {random.choice(responses)}, {ctx.user.display_name}'))
51+
await self.bot.send(ctx, embed=Embed(title=f':8ball: | {random.choice(responses)}, {ctx.user.display_name}'))
5252

5353
@app_commands.command(name='embed')
5454
@app_commands.describe(title='Title of embed', title_url='Url embeded into title', author='Author of the embed')

0 commit comments

Comments
 (0)