Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed numerous small potential bugs #290

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
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

Expand Down Expand Up @@ -158,7 +160,7 @@ async def convert(self, ctx: commands.Context, argument: str):
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


Expand All @@ -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 ---
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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)
Expand Down