diff options
author | 2019-03-30 11:15:28 +0100 | |
---|---|---|
committer | 2019-03-30 11:15:28 +0100 | |
commit | c1830aa53edbb277f8a40e4fe806c0c3f2d747ab (patch) | |
tree | 7e78c86f2d5603e1bce250ff382af26a92f146bd | |
parent | Merge pull request #161 from python-discord/easter_icon (diff) | |
parent | Add season icon as announcement image. (diff) |
Merge pull request #162 from python-discord/announce_fix
Always announce a season change when a docstring is present for the season; improved the formatting of the announcement.
-rw-r--r-- | bot/seasons/season.py | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/bot/seasons/season.py b/bot/seasons/season.py index b7892606..cfc27172 100644 --- a/bot/seasons/season.py +++ b/bot/seasons/season.py @@ -17,6 +17,8 @@ from bot.decorators import with_role log = logging.getLogger(__name__) +ICON_BASE_URL = "https://raw.githubusercontent.com/python-discord/branding/master" + def get_seasons() -> List[str]: """ @@ -163,12 +165,11 @@ class SeasonBase: `https://raw.githubusercontent.com/python-discord/branding/master` """ - base_url = "https://raw.githubusercontent.com/python-discord/branding/master" if avatar: icon = self.bot_icon or self.icon else: icon = self.icon - full_url = base_url + icon + full_url = ICON_BASE_URL + icon log.debug(f"Getting icon from: {full_url}") async with bot.http_session.get(full_url) as resp: return await resp.read() @@ -278,7 +279,21 @@ class SeasonBase: channel = guild.get_channel(Channels.announcements) mention = f"<@&{Roles.announcements}>" - # collect seasonal cogs + # build cog info output + doc = inspect.getdoc(self) + announce = "\n\n".join(l.replace("\n", " ") for l in doc.split("\n\n")) + + # no announcement message found + if not doc: + return + + embed = discord.Embed(description=f"{announce}\n\n", colour=self.colour or guild.me.colour) + embed.set_author(name=self.greeting) + + if self.icon: + embed.set_image(url=ICON_BASE_URL+self.icon) + + # find any seasonal commands cogs = [] for cog in bot.cogs.values(): if "evergreen" in cog.__module__: @@ -287,30 +302,21 @@ class SeasonBase: if cog_name != "SeasonManager": cogs.append(cog_name) - # no cogs, so no seasonal commands - if not cogs: - return - - # build cog info output - doc = inspect.getdoc(self) - announce_text = doc + "\n\n" if doc else "" + if cogs: + def cog_name(cog): + return type(cog).__name__ - def cog_name(cog): - return type(cog).__name__ - - cog_info = [] - for cog in sorted(cogs, key=cog_name): - doc = inspect.getdoc(bot.get_cog(cog)) - if doc: - cog_info.append(f"**{cog}**\n*{doc}*") - else: - cog_info.append(f"**{cog}**") + cog_info = [] + for cog in sorted(cogs, key=cog_name): + doc = inspect.getdoc(bot.get_cog(cog)) + if doc: + cog_info.append(f"**{cog}**\n*{doc}*") + else: + cog_info.append(f"**{cog}**") - embed = discord.Embed(description=announce_text, colour=self.colour or guild.me.colour) - embed.set_author(name=self.greeting) - cogs_text = "\n".join(cog_info) - embed.add_field(name="New Command Categories", value=cogs_text) - embed.set_footer(text="To see the new commands, use .help Category") + cogs_text = "\n".join(cog_info) + embed.add_field(name="New Command Categories", value=cogs_text) + embed.set_footer(text="To see the new commands, use .help Category") await channel.send(mention, embed=embed) |