Skip to content

Commit

Permalink
fix: bad converters in commands + missing typehints (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed authored Sep 8, 2024
1 parent c488e42 commit 28856e7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
20 changes: 14 additions & 6 deletions canary/cogs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
import math
import random
import re
import time

from typing import Optional

from .base_cog import CanaryCog
from .utils.arg_converter import ArgConverter, StrConverter
Expand Down Expand Up @@ -408,7 +409,7 @@ async def lmgtfy(self, ctx: commands.Context, *, query: str):
await ctx.send(url)

@commands.command()
async def tex(self, ctx: commands.Context, *, query: str):
async def tex(self, ctx: commands.Context):
"""Parses and prints LaTeX equations."""
await ctx.trigger_typing()

Expand Down Expand Up @@ -526,7 +527,7 @@ async def modpow(self, ctx: commands.Context, a, b, m):
"""Calculates a^b mod m, where a, b, c are big integers"""
try:
a, b, m = map(int, (a, b, m))
await ctx.send(pow(a, b, m))
await ctx.send(str(pow(a, b, m)))
except ValueError:
await ctx.send("Input must be integers")

Expand Down Expand Up @@ -598,14 +599,18 @@ async def colour(self, ctx: commands.Context, *, arg: str):
await ctx.send(file=discord.File(fp=buffer, filename=fn))

@commands.command(aliases=["ui", "av", "avi", "userinfo"])
async def user_info(self, ctx: commands.Context, user: discord.Member | None = None):
async def user_info(self, ctx: commands.Context, user: Optional[discord.Member] = None):
"""
Show user info and avatar.
Displays the information of the user
that called the command, or another member's
if one is passed as an optional argument."""

await ctx.trigger_typing()

if user is None:
user = ctx.author

ui_embed = discord.Embed(colour=(user.id - sum(ord(char) for char in user.name)) % 0xFFFFFF)
ui_embed.add_field(name="username", value=str(user))
ui_embed.add_field(name="display name", value=user.display_name)
Expand All @@ -623,7 +628,7 @@ async def user_info(self, ctx: commands.Context, user: discord.Member | None = N
await ctx.send(embed=ui_embed)

@commands.command(aliases=["trans"])
async def translate(self, ctx: commands.Context, command: str, *, inp_str: str | None = None):
async def translate(self, ctx: commands.Context, command: str, *, inp_str: Optional[str] = None):
"""
Command used to translate some text from one language to another
Takes two arguments: the source/target languages and the text to translate
Expand All @@ -638,6 +643,9 @@ async def translate(self, ctx: commands.Context, command: str, *, inp_str: str |
taken from the message to which the invoking message was replying to, or if the
invoking message is not a reply, then to the rest of the message after the first argument.
"""

await ctx.trigger_typing()

if command == "help":
await ctx.send(
"Command used to translate text.\n"
Expand Down Expand Up @@ -725,7 +733,7 @@ async def create_main_webhooks(self, ctx: commands.Context):
await ctx.send("Job completed.")

async def spoilerize_utility(
self, ctx: commands.Context, message: discord.Message, reason: str | None = None, moderator: bool = False
self, ctx: commands.Context, message: discord.Message, reason: Optional[str] = None, moderator: bool = False
) -> None:
db: aiosqlite.Connection

Expand Down
2 changes: 1 addition & 1 deletion canary/cogs/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class Info(CanaryCog):
@commands.command()
async def version(self, ctx):
async def version(self, ctx: commands.Context):
# TODO: use asyncio.create_subprocess_shell
version = subprocess.check_output(("git", "describe", "--tags"), universal_newlines=True).strip()
commit, authored = (
Expand Down
6 changes: 4 additions & 2 deletions canary/cogs/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

import discord
import random

from bidict import bidict
from datetime import datetime, timedelta
from discord import utils
from discord.ext import commands, tasks
from typing import Optional

from ..bot import Canary
from .base_cog import CanaryCog
from .utils.checks import is_moderator
from datetime import datetime, timedelta
from .utils.role_restoration import (
save_existing_roles,
fetch_saved_roles,
Expand Down Expand Up @@ -216,7 +218,7 @@ async def verification_purge_utility(self, after: datetime | discord.Message | N

@commands.command()
@is_moderator()
async def verification_purge(self, ctx: commands.Context, id_: int | None = None):
async def verification_purge(self, ctx: commands.Context, id_: Optional[int] = None):
"""
Manually start the purge of pictures in the verification channel.
Expand Down
2 changes: 1 addition & 1 deletion canary/cogs/quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ async def all_quotes(self, ctx: commands.Context, *, query: Optional[str] = None
await p.paginate()

@commands.command(aliases=["gen"])
async def generate(self, ctx: commands.Context, seed: str | None = None, min_length: int = 1):
async def generate(self, ctx: commands.Context, seed: Optional[str] = None, min_length: int = 1):
"""
Generates a random 'quote' using a Markov Chain. Optionally takes in a
word to seed the Markov Chain with and (also optionally) a desired
Expand Down

0 comments on commit 28856e7

Please sign in to comment.