aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/utilities
diff options
context:
space:
mode:
Diffstat (limited to 'bot/exts/utilities')
-rw-r--r--bot/exts/utilities/bookmark.py4
-rw-r--r--bot/exts/utilities/challenges.py4
-rw-r--r--bot/exts/utilities/cheatsheet.py4
-rw-r--r--bot/exts/utilities/colour.py7
-rw-r--r--bot/exts/utilities/conversationstarters.py4
-rw-r--r--bot/exts/utilities/emoji.py10
-rw-r--r--bot/exts/utilities/epoch.py12
-rw-r--r--bot/exts/utilities/githubinfo.py7
-rw-r--r--bot/exts/utilities/logging.py40
-rw-r--r--bot/exts/utilities/pythonfacts.py4
-rw-r--r--bot/exts/utilities/realpython.py4
-rw-r--r--bot/exts/utilities/reddit.py17
-rw-r--r--bot/exts/utilities/stackoverflow.py4
-rw-r--r--bot/exts/utilities/timed.py4
-rw-r--r--bot/exts/utilities/twemoji.py11
-rw-r--r--bot/exts/utilities/wikipedia.py4
-rw-r--r--bot/exts/utilities/wolfram.py17
-rw-r--r--bot/exts/utilities/wtf_python.py6
18 files changed, 106 insertions, 57 deletions
diff --git a/bot/exts/utilities/bookmark.py b/bot/exts/utilities/bookmark.py
index 9eb23988..50e3038f 100644
--- a/bot/exts/utilities/bookmark.py
+++ b/bot/exts/utilities/bookmark.py
@@ -189,6 +189,6 @@ class Bookmark(commands.Cog):
await target_message.delete()
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Bookmark cog."""
- bot.add_cog(Bookmark(bot))
+ await bot.add_cog(Bookmark(bot))
diff --git a/bot/exts/utilities/challenges.py b/bot/exts/utilities/challenges.py
index ab7ae442..1a5bf289 100644
--- a/bot/exts/utilities/challenges.py
+++ b/bot/exts/utilities/challenges.py
@@ -336,6 +336,6 @@ class Challenges(commands.Cog):
await original_message.edit(embed=kata_embed, view=None)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Challenges cog."""
- bot.add_cog(Challenges(bot))
+ await bot.add_cog(Challenges(bot))
diff --git a/bot/exts/utilities/cheatsheet.py b/bot/exts/utilities/cheatsheet.py
index 33d29f67..3141a050 100644
--- a/bot/exts/utilities/cheatsheet.py
+++ b/bot/exts/utilities/cheatsheet.py
@@ -107,6 +107,6 @@ class CheatSheet(commands.Cog):
await ctx.send(content=description)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the CheatSheet cog."""
- bot.add_cog(CheatSheet(bot))
+ await bot.add_cog(CheatSheet(bot))
diff --git a/bot/exts/utilities/colour.py b/bot/exts/utilities/colour.py
index ee6bad93..20f97e4b 100644
--- a/bot/exts/utilities/colour.py
+++ b/bot/exts/utilities/colour.py
@@ -13,7 +13,6 @@ from discord.ext import commands
from bot import constants
from bot.bot import Bot
-from bot.exts.core.extensions import invoke_help_command
from bot.utils.decorators import whitelist_override
THUMBNAIL_SIZE = (80, 80)
@@ -99,7 +98,7 @@ class Colour(commands.Cog):
extra_colour = ImageColor.getrgb(colour_input)
await self.send_colour_response(ctx, extra_colour)
except ValueError:
- await invoke_help_command(ctx)
+ await self.bot.invoke_help_command(ctx)
@colour.command()
async def rgb(self, ctx: commands.Context, red: int, green: int, blue: int) -> None:
@@ -261,6 +260,6 @@ class Colour(commands.Cog):
return f"#{self.colour_mapping[match]}"
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Colour cog."""
- bot.add_cog(Colour(bot))
+ await bot.add_cog(Colour(bot))
diff --git a/bot/exts/utilities/conversationstarters.py b/bot/exts/utilities/conversationstarters.py
index 8bf2abfd..410ea884 100644
--- a/bot/exts/utilities/conversationstarters.py
+++ b/bot/exts/utilities/conversationstarters.py
@@ -121,6 +121,6 @@ class ConvoStarters(commands.Cog):
self.bot.loop.create_task(self._listen_for_refresh(ctx.author, message))
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the ConvoStarters cog."""
- bot.add_cog(ConvoStarters(bot))
+ await bot.add_cog(ConvoStarters(bot))
diff --git a/bot/exts/utilities/emoji.py b/bot/exts/utilities/emoji.py
index fa438d7f..ec40be01 100644
--- a/bot/exts/utilities/emoji.py
+++ b/bot/exts/utilities/emoji.py
@@ -10,7 +10,6 @@ from discord.ext import commands
from bot.bot import Bot
from bot.constants import Colours, ERROR_REPLIES
-from bot.utils.extensions import invoke_help_command
from bot.utils.pagination import LinePaginator
from bot.utils.time import time_since
@@ -20,6 +19,9 @@ log = logging.getLogger(__name__)
class Emojis(commands.Cog):
"""A collection of commands related to emojis in the server."""
+ def __init__(self, bot: Bot) -> None:
+ self.bot = bot
+
@staticmethod
def embed_builder(emoji: dict) -> tuple[Embed, list[str]]:
"""Generates an embed with the emoji names and count."""
@@ -74,7 +76,7 @@ class Emojis(commands.Cog):
if emoji is not None:
await ctx.invoke(self.info_command, emoji)
else:
- await invoke_help_command(ctx)
+ await self.bot.invoke_help_command(ctx)
@emoji_group.command(name="count", aliases=("c",))
async def count_command(self, ctx: commands.Context, *, category_query: str = None) -> None:
@@ -118,6 +120,6 @@ class Emojis(commands.Cog):
await ctx.send(embed=emoji_information)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Emojis cog."""
- bot.add_cog(Emojis())
+ await bot.add_cog(Emojis(bot))
diff --git a/bot/exts/utilities/epoch.py b/bot/exts/utilities/epoch.py
index 42312dd1..6f572640 100644
--- a/bot/exts/utilities/epoch.py
+++ b/bot/exts/utilities/epoch.py
@@ -6,7 +6,6 @@ from dateutil import parser
from discord.ext import commands
from bot.bot import Bot
-from bot.utils.extensions import invoke_help_command
# https://discord.com/developers/docs/reference#message-formatting-timestamp-styles
STYLES = {
@@ -48,6 +47,9 @@ class DateString(commands.Converter):
class Epoch(commands.Cog):
"""Convert an entered time and date to a unix timestamp."""
+ def __init__(self, bot: Bot) -> None:
+ self.bot = bot
+
@commands.command(name="epoch")
async def epoch(self, ctx: commands.Context, *, date_time: DateString = None) -> None:
"""
@@ -71,7 +73,7 @@ class Epoch(commands.Cog):
Times in the dropdown are shown in UTC
"""
if not date_time:
- await invoke_help_command(ctx)
+ await self.bot.invoke_help_command(ctx)
return
if isinstance(date_time, tuple):
@@ -117,7 +119,7 @@ class TimestampMenuView(discord.ui.View):
self.dropdown.add_option(label=label, description=date_time)
@discord.ui.select(placeholder="Select the format of your timestamp")
- async def select_format(self, _: discord.ui.Select, interaction: discord.Interaction) -> discord.Message:
+ async def select_format(self, interaction: discord.Interaction, _: discord.ui.Select) -> discord.Message:
"""Drop down menu which contains a list of formats which discord timestamps can take."""
selected = interaction.data["values"][0]
if selected == "Epoch":
@@ -133,6 +135,6 @@ class TimestampMenuView(discord.ui.View):
return True
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Epoch cog."""
- bot.add_cog(Epoch())
+ await bot.add_cog(Epoch(bot))
diff --git a/bot/exts/utilities/githubinfo.py b/bot/exts/utilities/githubinfo.py
index 046f67df..a7979718 100644
--- a/bot/exts/utilities/githubinfo.py
+++ b/bot/exts/utilities/githubinfo.py
@@ -12,7 +12,6 @@ from discord.ext import commands
from bot.bot import Bot
from bot.constants import Colours, ERROR_REPLIES, Emojis, NEGATIVE_REPLIES, Tokens
-from bot.exts.core.extensions import invoke_help_command
log = logging.getLogger(__name__)
@@ -168,7 +167,7 @@ class GithubInfo(commands.Cog):
async def github_group(self, ctx: commands.Context) -> None:
"""Commands for finding information related to GitHub."""
if ctx.invoked_subcommand is None:
- await invoke_help_command(ctx)
+ await self.bot.invoke_help_command(ctx)
@commands.Cog.listener()
async def on_message(self, message: discord.Message) -> None:
@@ -363,6 +362,6 @@ class GithubInfo(commands.Cog):
await ctx.send(embed=embed)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the GithubInfo cog."""
- bot.add_cog(GithubInfo(bot))
+ await bot.add_cog(GithubInfo(bot))
diff --git a/bot/exts/utilities/logging.py b/bot/exts/utilities/logging.py
new file mode 100644
index 00000000..83b7025f
--- /dev/null
+++ b/bot/exts/utilities/logging.py
@@ -0,0 +1,40 @@
+from botcore.utils.logging import get_logger
+from discord.ext.commands import Cog
+
+from bot import constants
+from bot.bot import Bot
+
+log = get_logger(__name__)
+
+
+class Logging(Cog):
+ """Debug logging module."""
+
+ def __init__(self, bot: Bot):
+ self.bot = bot
+
+ async def cog_load(self) -> None:
+ """Announce our presence to the configured dev-log channel after checking channel constants."""
+ await self.check_channels()
+ await self.bot.log_to_dev_log(
+ title=self.bot.name,
+ details="Connected!",
+ )
+
+ async def check_channels(self) -> None:
+ """Verifies that all channel constants refer to channels which exist."""
+ if constants.Client.debug:
+ log.info("Skipping Channels Check.")
+ return
+
+ all_channels_ids = [channel.id for channel in self.bot.get_all_channels()]
+ for name, channel_id in vars(constants.Channels).items():
+ if name.startswith("_"):
+ continue
+ if channel_id not in all_channels_ids:
+ log.error(f'Channel "{name}" with ID {channel_id} missing')
+
+
+async def setup(bot: Bot) -> None:
+ """Load the Logging cog."""
+ await bot.add_cog(Logging(bot))
diff --git a/bot/exts/utilities/pythonfacts.py b/bot/exts/utilities/pythonfacts.py
index ef190185..a5bfb612 100644
--- a/bot/exts/utilities/pythonfacts.py
+++ b/bot/exts/utilities/pythonfacts.py
@@ -31,6 +31,6 @@ class PythonFacts(commands.Cog):
await ctx.send(embed=embed)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the PythonFacts Cog."""
- bot.add_cog(PythonFacts())
+ await bot.add_cog(PythonFacts())
diff --git a/bot/exts/utilities/realpython.py b/bot/exts/utilities/realpython.py
index 5e9757d0..46b02866 100644
--- a/bot/exts/utilities/realpython.py
+++ b/bot/exts/utilities/realpython.py
@@ -94,6 +94,6 @@ class RealPython(commands.Cog):
await ctx.send(embed=article_embed)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Real Python Cog."""
- bot.add_cog(RealPython(bot))
+ await bot.add_cog(RealPython(bot))
diff --git a/bot/exts/utilities/reddit.py b/bot/exts/utilities/reddit.py
index 782583d2..028c16bc 100644
--- a/bot/exts/utilities/reddit.py
+++ b/bot/exts/utilities/reddit.py
@@ -15,7 +15,6 @@ from discord.utils import escape_markdown, sleep_until
from bot.bot import Bot
from bot.constants import Channels, ERROR_REPLIES, Emojis, Reddit as RedditConfig, STAFF_ROLES
from bot.utils.converters import Subreddit
-from bot.utils.extensions import invoke_help_command
from bot.utils.messages import sub_clyde
from bot.utils.pagination import ImagePaginator, LinePaginator
@@ -39,20 +38,17 @@ class Reddit(Cog):
self.access_token = None
self.client_auth = BasicAuth(RedditConfig.client_id, RedditConfig.secret)
- bot.loop.create_task(self.init_reddit_ready())
self.auto_poster_loop.start()
- def cog_unload(self) -> None:
+ async def cog_unload(self) -> None:
"""Stop the loop task and revoke the access token when the cog is unloaded."""
self.auto_poster_loop.cancel()
if self.access_token and self.access_token.expires_at > datetime.utcnow():
asyncio.create_task(self.revoke_access_token())
- async def init_reddit_ready(self) -> None:
+ async def cog_load(self) -> None:
"""Sets the reddit webhook when the cog is loaded."""
- await self.bot.wait_until_guild_available()
- if not self.webhook:
- self.webhook = await self.bot.fetch_webhook(RedditConfig.webhook)
+ self.webhook = await self.bot.fetch_webhook(RedditConfig.webhook)
@property
def channel(self) -> TextChannel:
@@ -258,7 +254,6 @@ class Reddit(Cog):
await sleep_until(midnight_tomorrow)
- await self.bot.wait_until_guild_available()
if not self.webhook:
await self.bot.fetch_webhook(RedditConfig.webhook)
@@ -302,7 +297,7 @@ class Reddit(Cog):
@group(name="reddit", invoke_without_command=True)
async def reddit_group(self, ctx: Context) -> None:
"""View the top posts from various subreddits."""
- await invoke_help_command(ctx)
+ await self.bot.invoke_help_command(ctx)
@reddit_group.command(name="top")
async def top_command(self, ctx: Context, subreddit: Subreddit = "r/Python") -> None:
@@ -360,9 +355,9 @@ class Reddit(Cog):
)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Reddit cog."""
if not RedditConfig.secret or not RedditConfig.client_id:
log.error("Credentials not provided, cog not loaded.")
return
- bot.add_cog(Reddit(bot))
+ await bot.add_cog(Reddit(bot))
diff --git a/bot/exts/utilities/stackoverflow.py b/bot/exts/utilities/stackoverflow.py
index 64455e33..b248e83f 100644
--- a/bot/exts/utilities/stackoverflow.py
+++ b/bot/exts/utilities/stackoverflow.py
@@ -83,6 +83,6 @@ class Stackoverflow(commands.Cog):
await ctx.send(embed=search_query_too_long)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Stackoverflow Cog."""
- bot.add_cog(Stackoverflow(bot))
+ await bot.add_cog(Stackoverflow(bot))
diff --git a/bot/exts/utilities/timed.py b/bot/exts/utilities/timed.py
index 2ea6b419..d419dd08 100644
--- a/bot/exts/utilities/timed.py
+++ b/bot/exts/utilities/timed.py
@@ -43,6 +43,6 @@ class TimedCommands(commands.Cog):
await ctx.send(f"Command execution for `{new_ctx.command}` finished in {(t_end - t_start):.4f} seconds.")
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Timed cog."""
- bot.add_cog(TimedCommands())
+ await bot.add_cog(TimedCommands())
diff --git a/bot/exts/utilities/twemoji.py b/bot/exts/utilities/twemoji.py
index c915f05b..25a03d25 100644
--- a/bot/exts/utilities/twemoji.py
+++ b/bot/exts/utilities/twemoji.py
@@ -4,12 +4,11 @@ from typing import Literal, Optional
import discord
from discord.ext import commands
-from emoji import UNICODE_EMOJI_ENGLISH, is_emoji
+from emoji import EMOJI_DATA, is_emoji
from bot.bot import Bot
from bot.constants import Colours, Roles
from bot.utils.decorators import whitelist_override
-from bot.utils.extensions import invoke_help_command
log = logging.getLogger(__name__)
BASE_URLS = {
@@ -50,7 +49,7 @@ class Twemoji(commands.Cog):
emoji = "".join(Twemoji.emoji(e) or "" for e in codepoint.split("-"))
embed = discord.Embed(
- title=Twemoji.alias_to_name(UNICODE_EMOJI_ENGLISH[emoji]),
+ title=Twemoji.alias_to_name(EMOJI_DATA[emoji]["en"]),
description=f"{codepoint.replace('-', ' ')}\n[Download svg]({Twemoji.get_url(codepoint, 'svg')})",
colour=Colours.twitter_blue,
)
@@ -133,7 +132,7 @@ class Twemoji(commands.Cog):
async def twemoji(self, ctx: commands.Context, *raw_emoji: str) -> None:
"""Sends a preview of a given Twemoji, specified by codepoint or emoji."""
if len(raw_emoji) == 0:
- await invoke_help_command(ctx)
+ await self.bot.invoke_help_command(ctx)
return
try:
codepoint = self.codepoint_from_input(raw_emoji)
@@ -145,6 +144,6 @@ class Twemoji(commands.Cog):
await ctx.send(embed=self.build_embed(codepoint))
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Twemoji cog."""
- bot.add_cog(Twemoji(bot))
+ await bot.add_cog(Twemoji(bot))
diff --git a/bot/exts/utilities/wikipedia.py b/bot/exts/utilities/wikipedia.py
index e5e8e289..d87982c9 100644
--- a/bot/exts/utilities/wikipedia.py
+++ b/bot/exts/utilities/wikipedia.py
@@ -93,6 +93,6 @@ class WikipediaSearch(commands.Cog):
)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the WikipediaSearch cog."""
- bot.add_cog(WikipediaSearch(bot))
+ await bot.add_cog(WikipediaSearch(bot))
diff --git a/bot/exts/utilities/wolfram.py b/bot/exts/utilities/wolfram.py
index 9a26e545..a2f1228a 100644
--- a/bot/exts/utilities/wolfram.py
+++ b/bot/exts/utilities/wolfram.py
@@ -202,6 +202,13 @@ class Wolfram(Cog):
message = "Wolfram API key is invalid or missing."
footer = ""
color = Colours.soft_red
+ elif status != 200:
+ # Handle all other possible status codes here
+ message = f"Unexpected status code from Wolfram API: {status}"
+ footer = ""
+ color = Colours.soft_red
+
+ log.warning(f"Unexpected status code from Wolfram API: {status}\nInput: {query}")
else:
message = ""
footer = "View original for a bigger picture."
@@ -281,6 +288,12 @@ class Wolfram(Cog):
elif response_text == "Error 1: Invalid appid.":
message = "Wolfram API key is invalid or missing."
color = Colours.soft_red
+ elif status != 200:
+ # Handle all other possible status codes here
+ message = f"Unexpected status code from Wolfram API: {status}"
+ color = Colours.soft_red
+
+ log.warning(f"Unexpected status code from Wolfram API: {status}\nInput: {query}")
else:
message = response_text
color = Colours.soft_orange
@@ -288,6 +301,6 @@ class Wolfram(Cog):
await send_embed(ctx, message, color)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Wolfram cog."""
- bot.add_cog(Wolfram(bot))
+ await bot.add_cog(Wolfram(bot))
diff --git a/bot/exts/utilities/wtf_python.py b/bot/exts/utilities/wtf_python.py
index 980b3dba..0c0375cb 100644
--- a/bot/exts/utilities/wtf_python.py
+++ b/bot/exts/utilities/wtf_python.py
@@ -78,7 +78,7 @@ class WTFPython(commands.Cog):
match, certainty, _ = rapidfuzz.process.extractOne(query, self.headers.keys())
return match if certainty > MINIMUM_CERTAINTY else None
- @commands.command(aliases=("wtf", "WTF"))
+ @commands.command(aliases=("wtf",))
async def wtf_python(self, ctx: commands.Context, *, query: Optional[str] = None) -> None:
"""
Search WTF Python repository.
@@ -133,6 +133,6 @@ class WTFPython(commands.Cog):
self.fetch_readme.cancel()
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the WTFPython Cog."""
- bot.add_cog(WTFPython(bot))
+ await bot.add_cog(WTFPython(bot))