diff options
author | 2018-12-06 19:10:01 +0100 | |
---|---|---|
committer | 2018-12-06 19:10:01 +0100 | |
commit | e35df369aff2511c301fea0cdc632aa946935d35 (patch) | |
tree | e2632c3f465bcd56514d3b45eb57c6e4a28a93af | |
parent | Merge pull request #89 from python-discord/lb-stats (diff) | |
parent | Fix comment typo (diff) |
Merge pull request #88 from scragly/si_2
Send devlog notification on season load.
-rw-r--r-- | bot/bot.py | 21 | ||||
-rw-r--r-- | bot/constants.py | 2 | ||||
-rw-r--r-- | bot/seasons/season.py | 20 |
3 files changed, 35 insertions, 8 deletions
@@ -4,8 +4,11 @@ from traceback import format_exc from typing import List from aiohttp import AsyncResolver, ClientSession, TCPConnector +from discord import Embed from discord.ext.commands import Bot +from bot import constants + log = logging.getLogger(__name__) __all__ = ('SeasonalBot',) @@ -40,3 +43,21 @@ class SeasonalBot(Bot): log.info(f'Successfully loaded extension: {cog}') except Exception as e: log.error(f'Failed to load extension {cog}: {repr(e)} {format_exc()}') + + async def send_log(self, title: str, details: str = None, *, icon: str = None): + """ + Send an embed message to the devlog channel + """ + devlog = self.get_channel(constants.Channels.devlog) + + if not devlog: + log.warning("Log failed to send. Devlog channel not found.") + return + + if not icon: + icon = self.user.avatar_url_as(format="png") + + embed = Embed(description=details) + embed.set_author(name=title, icon_url=icon) + + await devlog.send(embed=embed) diff --git a/bot/constants.py b/bot/constants.py index 71bdbf5f..b57eb714 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -29,7 +29,7 @@ class Channels(NamedTuple): bot = 267659945086812160 checkpoint_test = 422077681434099723 devalerts = 460181980097675264 - devlog = 409308876241108992 + devlog = int(environ.get('CHANNEL_DEVLOG', 409308876241108992)) devtest = 414574275865870337 help_0 = 303906576991780866 help_1 = 303906556754395136 diff --git a/bot/seasons/season.py b/bot/seasons/season.py index f1d570e0..e59949d7 100644 --- a/bot/seasons/season.py +++ b/bot/seasons/season.py @@ -37,7 +37,8 @@ def get_season_class(season_name: str) -> Type["SeasonBase"]: """ season_lib = importlib.import_module(f"bot.seasons.{season_name}") - return getattr(season_lib, season_name.capitalize()) + class_name = season_name.replace("_", " ").title().replace(" ", "") + return getattr(season_lib, class_name) def get_season(season_name: str = None, date: datetime.datetime = None) -> "SeasonBase": @@ -135,6 +136,10 @@ class SeasonBase: return cls.start() <= date <= cls.end() @property + def name_clean(self) -> str: + return self.name.replace("_", " ").title() + + @property def greeting(self) -> str: """ Provides a default greeting based on the season name if one wasn't @@ -144,8 +149,7 @@ class SeasonBase: normal attribute in the inhertiting class. """ - season_name = " ".join(self.name.split("_")).title() - return f"New Season, {season_name}!" + return f"New Season, {self.name_clean}!" async def get_icon(self) -> bytes: """ @@ -326,7 +330,7 @@ class SeasonBase: # Apply seasonal elements after extensions successfully load username_changed = await self.apply_username(debug=Client.debug) - # Avoid heavy API ratelimited elements when debugging + # Avoid major changes and announcements if debug mode if not Client.debug: log.info("Applying avatar.") await self.apply_avatar() @@ -338,6 +342,8 @@ class SeasonBase: else: log.info(f"Skipping season announcement due to username not being changed.") + await bot.send_log("SeasonalBot Loaded!", f"Active Season: **{self.name_clean}**") + class SeasonManager: """ @@ -371,7 +377,7 @@ class SeasonManager: # If the season has changed, load it. new_season = get_season(date=datetime.datetime.utcnow()) - if new_season != self.season: + if new_season.name != self.season.name: await self.season.load() @with_role(Roles.moderator, Roles.admin, Roles.owner) @@ -393,8 +399,8 @@ class SeasonManager: """ # sort by start order, followed by lower duration - def season_key(season: SeasonBase): - return season.start(), season.end() - datetime.datetime.max + def season_key(season_class: Type[SeasonBase]): + return season_class.start(), season_class.end() - datetime.datetime.max current_season = self.season.name |