Skip to content

Commit

Permalink
Merge pull request #1269 from shtlrs/load-cogs-when-config-is-setup
Browse files Browse the repository at this point in the history
Run null check on needed API keys before loading cogs.
  • Loading branch information
wookie184 authored May 6, 2023
2 parents a48dce5 + dc0193d commit 56cefe8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions bot/exts/events/hacktoberfest/hacktoberstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,6 @@ def _author_mention_from_context(ctx: commands.Context) -> tuple[str, str]:

async def setup(bot: Bot) -> None:
"""Load the Hacktober Stats Cog."""
if not Tokens.github:
log.warning("No GitHub token was provided. The HacktoberStats Cog won't be fully functional.")
await bot.add_cog(HacktoberStats(bot))
3 changes: 3 additions & 0 deletions bot/exts/fun/movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,7 @@ async def get_embed(self, name: str) -> Embed:

async def setup(bot: Bot) -> None:
"""Load the Movie Cog."""
if not Tokens.tmdb:
logger.warning("No TMDB token. Not loading Movie Cog.")
return
await bot.add_cog(Movie(bot))
3 changes: 3 additions & 0 deletions bot/exts/fun/snakes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import logging

from bot.bot import Bot
from bot.constants import Tokens
from bot.exts.fun.snakes._snakes_cog import Snakes

log = logging.getLogger(__name__)


async def setup(bot: Bot) -> None:
"""Load the Snakes Cog."""
if not Tokens.youtube:
log.warning("No Youtube token. All YouTube related commands in Snakes cog won't work.")
await bot.add_cog(Snakes(bot))
3 changes: 3 additions & 0 deletions bot/exts/holidays/halloween/scarymovie.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ async def format_metadata(movie: dict) -> Embed:

async def setup(bot: Bot) -> None:
"""Load the Scary Movie Cog."""
if not Tokens.tmdb:
log.warning("No TMDB Token. Not loading ScaryMovie Cog.")
return
await bot.add_cog(ScaryMovie(bot))
3 changes: 3 additions & 0 deletions bot/exts/holidays/halloween/spookygif.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ async def spookygif(self, ctx: commands.Context) -> None:

async def setup(bot: Bot) -> None:
"""Spooky GIF Cog load."""
if not Tokens.giphy:
log.warning("No Giphy token. Not loading SpookyGif cog.")
return
await bot.add_cog(SpookyGif(bot))
2 changes: 1 addition & 1 deletion bot/exts/utilities/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,6 @@ async def subreddits_command(self, ctx: Context) -> 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.")
log.warning("Credentials not provided, cog not loaded.")
return
await bot.add_cog(Reddit(bot))
11 changes: 7 additions & 4 deletions bot/exts/utilities/wolfram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
from discord.ext.commands import BucketType, Cog, Context, check, group

from bot.bot import Bot
from bot.constants import Colours, STAFF_ROLES, Wolfram
from bot.constants import Colours, STAFF_ROLES, Wolfram as WolframConfig
from bot.utils.pagination import ImagePaginator

log = logging.getLogger(__name__)

APPID = Wolfram.key.get_secret_value()
APPID = WolframConfig.key.get_secret_value()
DEFAULT_OUTPUT_FORMAT = "JSON"
QUERY = "http://api.wolframalpha.com/v2/{request}"
WOLF_IMAGE = "https://www.symbols.com/gi.php?type=1&id=2886&i=1"

MAX_PODS = 20

# Allows for 10 wolfram calls pr user pr day
usercd = commands.CooldownMapping.from_cooldown(Wolfram.user_limit_day, 60 * 60 * 24, BucketType.user)
usercd = commands.CooldownMapping.from_cooldown(WolframConfig.user_limit_day, 60 * 60 * 24, BucketType.user)

# Allows for max api requests / days in month per day for the entire guild (Temporary)
guildcd = commands.CooldownMapping.from_cooldown(Wolfram.guild_limit_day, 60 * 60 * 24, BucketType.guild)
guildcd = commands.CooldownMapping.from_cooldown(WolframConfig.guild_limit_day, 60 * 60 * 24, BucketType.guild)


async def send_embed(
Expand Down Expand Up @@ -303,4 +303,7 @@ async def wolfram_short_command(self, ctx: Context, *, query: str) -> None:

async def setup(bot: Bot) -> None:
"""Load the Wolfram cog."""
if not WolframConfig.key:
log.warning("No Wolfram API Key was provided. Not loading Wolfram Cog.")
return
await bot.add_cog(Wolfram(bot))

0 comments on commit 56cefe8

Please sign in to comment.