Skip to content

Commit 2d1d117

Browse files
author
rtk-rnjn
committed
minor fixes
1 parent 99fe8b2 commit 2d1d117

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

cogs/nsfw/nsfw.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
from random import choice, random
44
from typing import Literal
5-
5+
import io
66
import discord
77
from core import Cog, Context, Parrot
88
from discord.ext import commands, tasks
99
from utilities.checks import is_adult
1010
from utilities.exceptions import ParrotCheckFailure
11-
from utilities.nsfw.sexdotcom import SexDotComGif, SexDotComPics
1211
from utilities.nsfw.constants import SEXDOTCOM_TAGS
12+
from utilities.nsfw.sexdotcom import SexDotComGif, SexDotComPics
1313
from utilities.paginator import PaginationView as PV
1414

1515
from ._nsfw import ENDPOINTS
@@ -213,7 +213,7 @@ async def _sex_gif(self, ctx: Context) -> None:
213213
return
214214

215215
_bytes = await response.read()
216-
file = discord.File(_bytes, "file.gif")
216+
file = discord.File(io.BytesIO(_bytes), "file.gif")
217217
await ctx.reply(file=file)
218218

219219
async def sexdotcom_write_to_db(self):

cogs/ticket/ticket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def log(self, *, guild: discord.Guild, author: discord.Member | discord.Us
6868
async def new_ticket(self, *, guild: discord.Guild, author: discord.Member | discord.User) -> None:
6969
ticket_config = self.bot.guild_configurations_cache[guild.id]["ticket_config"]
7070

71-
mod_role: int = ticket_config["mod_role"]
71+
mod_role: int | None = self.bot.guild_configurations_cache[guild.id]["mod_role"]
7272

7373
category: discord.CategoryChannel = guild.get_channel(ticket_config["category"] or 0) # type: ignore
7474
overwrites = {

custom_commands/sector_17_29/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ async def claim_vote(self, ctx: Context):
204204
@in_support_server()
205205
async def my_votes(self, ctx: Context):
206206
if data := await self.bot.user_collections_ind.find_one({"_id": ctx.author.id, "topgg_votes": {"$exists": True}}):
207-
await ctx.send(f"You voted for **{self.bot.user}** for **{len(data['topgg_votes'])}** times on Top.gg")
207+
await ctx.send(f"You voted for **{self.bot.user}** for **{data['topgg_votes']}** times on Top.gg")
208208
else:
209209
await ctx.send("You haven't voted for the bot on Top.gg yet.")
210210

@@ -222,7 +222,7 @@ async def __add_to_db(self, member: discord.Member) -> None:
222222
message=int(discord.utils.utcnow().timestamp() * 10),
223223
expires_at=(discord.utils.utcnow() + timedelta(hours=12)).timestamp(),
224224
messageAuthor=member.id,
225-
content=f"You can vote for the bot again on Top.gg.\n>>> Click **<https://top.gg/bot/{self.bot.user.id}/vote>** to vote.",
225+
content=f"You can vote for the bot again on Top.gg. Click **<https://top.gg/bot/{self.bot.user.id}/vote>** to vote.",
226226
dm_notify=True,
227227
)
228228

events/on_cmd.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
import asyncio
44
import pathlib
55
import random
6-
from typing import TYPE_CHECKING, TypeVar
76
from collections.abc import Sequence
7+
from typing import TYPE_CHECKING, TypeVar
88

99
import arrow
10+
from rapidfuzz import fuzz, process
11+
1012
import discord
1113
from core import Cog
1214
from discord.ext import commands
1315
from utilities.exceptions import ParrotCheckFailure
1416

15-
from rapidfuzz import fuzz, process
16-
1717
if TYPE_CHECKING:
1818
from core import Context, Parrot
1919

@@ -59,21 +59,17 @@ async def on_command(self, ctx: Context):
5959
"""This event will be triggered when the command is being completed; triggered by [discord.User]!."""
6060
if ctx.author.bot:
6161
return
62-
await ctx.database_command_update(
63-
success=not ctx.command_failed,
64-
)
62+
await ctx.database_command_update(success=not ctx.command_failed)
6563

66-
def _get_object_by_fuzzy(self, *, argument: str, objects: Sequence[T]) -> tuple[T | None, str | None, int | None] | None:
64+
def _get_object_by_fuzzy(self, *, argument: str, objects: Sequence[T]) -> tuple[T, str, int] | None:
6765
"""Get an object from a list of objects by fuzzy matching."""
6866
if not argument:
6967
return None
7068
CUT_OFF = 90
7169
names = [o.name for o in objects]
72-
algorithms = [fuzz.ratio, fuzz.partial_ratio, fuzz.token_sort_ratio, fuzz.token_set_ratio, fuzz.WRatio]
73-
for algo in algorithms:
74-
if data := process.extractOne(argument, names, scorer=algo, score_cutoff=CUT_OFF):
75-
result, score, position = data
76-
return objects[position], result, int(score)
70+
if data := process.extractOne(argument, names, scorer=fuzz.WRatio, score_cutoff=CUT_OFF):
71+
result, score, position = data
72+
return objects[position], result, int(score)
7773

7874
@Cog.listener()
7975
async def on_command_error(self, ctx: Context, error: commands.CommandError): # noqa: PLR0912, PLR0915, C901
@@ -84,7 +80,7 @@ async def on_command_error(self, ctx: Context, error: commands.CommandError): #
8480

8581
# get the original exception
8682
error = getattr(error, "original", error)
87-
TO_RAISE_ERROR, DELETE_AFTER = False, None
83+
TO_RAISE_ERROR, DELETE_AFTER, RESET_COOLDOWN = False, None, False
8884
ignore = (
8985
commands.CommandNotFound,
9086
discord.NotFound,
@@ -105,6 +101,7 @@ async def on_command_error(self, ctx: Context, error: commands.CommandError): #
105101
fmt = " and ".join(missing)
106102
ERROR_EMBED.description = f"Please provide the following permission(s) to the bot.```\n{fmt}```"
107103
ERROR_EMBED.set_author(name=(f"{QUESTION_MARK} Bot Missing permissions {QUESTION_MARK}"))
104+
RESET_COOLDOWN = True
108105

109106
elif isinstance(error, commands.CommandOnCooldown):
110107
now = arrow.utcnow().shift(seconds=error.retry_after).datetime
@@ -126,7 +123,7 @@ async def on_command_error(self, ctx: Context, error: commands.CommandError): #
126123

127124
ERROR_EMBED.description = f"You need the following permission(s) to the run the command.```\n{fmt}```"
128125
ERROR_EMBED.set_author(name=f"{QUESTION_MARK} Missing permissions {QUESTION_MARK}")
129-
ctx.command.reset_cooldown(ctx)
126+
RESET_COOLDOWN = True
130127

131128
elif isinstance(error, commands.MissingRole):
132129
missing = [error.missing_role]
@@ -136,7 +133,7 @@ async def on_command_error(self, ctx: Context, error: commands.CommandError): #
136133
fmt = " and ".join(missing) # type: ignore
137134
ERROR_EMBED.description = f"You need the the following role(s) to use the command```\n{fmt}```"
138135
ERROR_EMBED.set_author(name=f"{QUESTION_MARK} Missing Role {QUESTION_MARK}")
139-
ctx.command.reset_cooldown(ctx)
136+
RESET_COOLDOWN = True
140137

141138
elif isinstance(error, commands.MissingAnyRole):
142139
missing = list(error.missing_roles)
@@ -146,16 +143,16 @@ async def on_command_error(self, ctx: Context, error: commands.CommandError): #
146143
fmt = " and ".join(missing) # type: ignore
147144
ERROR_EMBED.description = f"You need the the following role(s) to use the command```\n{fmt}```"
148145
ERROR_EMBED.set_author(name=f"{QUESTION_MARK} Missing Role {QUESTION_MARK}")
149-
ctx.command.reset_cooldown(ctx)
146+
RESET_COOLDOWN = True
150147

151148
elif isinstance(error, commands.NSFWChannelRequired):
152149
ERROR_EMBED.description = "This command will only run in NSFW marked channel. https://i.imgur.com/oe4iK5i.gif"
153150
ERROR_EMBED.set_author(name=f"{QUESTION_MARK} NSFW Channel Required {QUESTION_MARK}")
154151
ERROR_EMBED.set_image(url="https://i.imgur.com/oe4iK5i.gif")
155-
ctx.command.reset_cooldown(ctx)
152+
RESET_COOLDOWN = True
156153

157154
elif isinstance(error, commands.BadArgument):
158-
ctx.command.reset_cooldown(ctx)
155+
RESET_COOLDOWN = True
159156
objects = []
160157
if isinstance(error, commands.MessageNotFound):
161158
ERROR_EMBED.description = "Message ID/Link you provied is either invalid or deleted"
@@ -189,7 +186,7 @@ async def on_command_error(self, ctx: Context, error: commands.CommandError): #
189186
ERROR_EMBED.set_author(name=f"{QUESTION_MARK} Bad Argument {QUESTION_MARK}")
190187

191188
if objects:
192-
if (obj := self._get_object_by_fuzzy(argument=error.argument, objects=objects)): # type: ignore
189+
if obj := self._get_object_by_fuzzy(argument=error.argument, objects=objects): # type: ignore
193190
_, result, score = obj
194191
ERROR_EMBED.description += f"\n\nDid you mean `{result}`?"
195192
ERROR_EMBED.set_footer(text=f"Confidence: {score}%")
@@ -199,7 +196,7 @@ async def on_command_error(self, ctx: Context, error: commands.CommandError): #
199196
commands.MissingRequiredArgument | commands.BadUnionArgument | commands.TooManyArguments,
200197
):
201198
command = ctx.command
202-
ctx.command.reset_cooldown(ctx)
199+
RESET_COOLDOWN = True
203200
ERROR_EMBED.description = f"Please use proper syntax.```\n{ctx.clean_prefix}{command.qualified_name}{'|' if command.aliases else ''}{'|'.join(command.aliases or '')} {command.signature}```"
204201

205202
ERROR_EMBED.set_author(name=f"{QUESTION_MARK} Invalid Syntax {QUESTION_MARK}")
@@ -218,17 +215,17 @@ async def on_command_error(self, ctx: Context, error: commands.CommandError): #
218215
ERROR_EMBED.set_author(name=(f"{QUESTION_MARK} Max Concurrenry Reached {QUESTION_MARK}"))
219216

220217
elif isinstance(error, ParrotCheckFailure):
221-
ctx.command.reset_cooldown(ctx)
218+
RESET_COOLDOWN = True
222219
ERROR_EMBED.description = f"{error.__str__().format(ctx=ctx)}"
223220
ERROR_EMBED.set_author(name=f"{QUESTION_MARK} Unexpected Error {QUESTION_MARK}")
224221

225222
elif isinstance(error, commands.CheckAnyFailure):
226-
ctx.command.reset_cooldown(ctx)
223+
RESET_COOLDOWN = True
227224
ERROR_EMBED.description = " or\n".join([error.__str__().format(ctx=ctx) for error in error.errors])
228225
ERROR_EMBED.set_author(name=f"{QUESTION_MARK} Unexpected Error {QUESTION_MARK}")
229226

230227
elif isinstance(error, commands.CheckFailure):
231-
ctx.command.reset_cooldown(ctx)
228+
RESET_COOLDOWN = True
232229
ERROR_EMBED.set_author(name=f"{QUESTION_MARK} Unexpected Error {QUESTION_MARK}")
233230
ERROR_EMBED.description = "You don't have the required permissions to use this command."
234231

@@ -257,6 +254,9 @@ async def on_command_error(self, ctx: Context, error: commands.CommandError): #
257254

258255
ERROR_EMBED.timestamp = discord.utils.utcnow()
259256

257+
if RESET_COOLDOWN:
258+
ctx.command.reset_cooldown(ctx)
259+
260260
msg: discord.Message | None = await ctx.reply(random.choice(quote), embed=ERROR_EMBED)
261261

262262
try:

0 commit comments

Comments
 (0)