From 58b9e81f3576aafdd1f5cefd27b5e17b3867a851 Mon Sep 17 00:00:00 2001 From: Scragly <29337040+scragly@users.noreply.github.com> Date: Sat, 30 Mar 2019 15:15:37 +1000 Subject: Always announce if docstring, better formatting. --- bot/seasons/season.py | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'bot') diff --git a/bot/seasons/season.py b/bot/seasons/season.py index b7892606..c78de981 100644 --- a/bot/seasons/season.py +++ b/bot/seasons/season.py @@ -278,7 +278,18 @@ 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) + + # find any seasonal commands cogs = [] for cog in bot.cogs.values(): if "evergreen" in cog.__module__: @@ -287,30 +298,21 @@ class SeasonBase: if cog_name != "SeasonManager": cogs.append(cog_name) - # no cogs, so no seasonal commands - if not cogs: - return + if cogs: + def cog_name(cog): + return type(cog).__name__ - # build cog info output - doc = inspect.getdoc(self) - announce_text = doc + "\n\n" if doc else "" - - 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) -- cgit v1.2.3 From 51d36c768e8c6338f02f1275b58b811928d18f82 Mon Sep 17 00:00:00 2001 From: Scragly <29337040+scragly@users.noreply.github.com> Date: Sat, 30 Mar 2019 18:11:15 +1000 Subject: Add season icon as announcement image. --- bot/seasons/season.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/seasons/season.py b/bot/seasons/season.py index c78de981..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() @@ -289,6 +290,9 @@ class SeasonBase: 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(): -- cgit v1.2.3