Fixed numerous small potential bugs

- Most are typing related

Fixes #289
This commit is contained in:
0x5c 2020-10-28 23:22:28 -04:00
parent ff9d46f379
commit 19952396f2
No known key found for this signature in database
GPG Key ID: A57F71C3176B9581
2 changed files with 8 additions and 5 deletions

View File

@ -15,11 +15,13 @@ import traceback
from datetime import datetime
from pathlib import Path
from types import SimpleNamespace
from typing import Union
import aiohttp
import discord
import discord.ext.commands as commands
from discord import Emoji, Reaction, PartialEmoji
import data.options as opt
@ -158,7 +160,7 @@ class GlobalChannelConverter(commands.IDConverter):
def embed_factory(ctx: commands.Context) -> discord.Embed:
"""Creates an embed with neutral colour and standard footer."""
embed = discord.Embed(timestamp=datetime.utcnow(), colour=colours.neutral)
embed.set_footer(text=ctx.author, icon_url=str(ctx.author.avatar_url))
embed.set_footer(text=str(ctx.author), icon_url=str(ctx.author.avatar_url))
return embed
@ -175,11 +177,12 @@ def error_embed_factory(ctx: commands.Context, exception: Exception, debug_mode:
return embed
async def add_react(msg: discord.Message, react: str):
async def add_react(msg: discord.Message, react: Union[Emoji, Reaction, PartialEmoji, str]):
try:
await msg.add_reaction(react)
except discord.Forbidden:
print(f"[!!] Missing permissions to add reaction in '{msg.guild.id}/{msg.channel.id}'!")
idpath = (f"{msg.guild.id}/" if msg.guild else "") + str(msg.channel.id)
print(f"[!!] Missing permissions to add reaction in '{idpath}'!")
# --- Checks ---

View File

@ -100,7 +100,7 @@ async def _extctl(ctx: commands.Context):
"""Extension control commands.
Defaults to `list` if no subcommand specified"""
if ctx.invoked_subcommand is None:
cmd = bot.get_command("extctl list")
cmd = _extctl_list
await ctx.invoke(cmd)
@ -168,7 +168,7 @@ async def on_command_error(ctx: commands.Context, err: commands.CommandError):
await cmn.add_react(ctx.message, cmn.emojis.warning)
await ctx.send_help(ctx.command)
elif isinstance(err, commands.CommandNotFound):
if ctx.invoked_with.startswith(("?", "!")):
if ctx.invoked_with and ctx.invoked_with.startswith(("?", "!")):
return
else:
await cmn.add_react(ctx.message, cmn.emojis.question)