diff options
-rw-r--r-- | bot/exts/evergreen/conversationstarters.py (renamed from bot/exts/easter/conversationstarters.py) | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/bot/exts/easter/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index 212e65b7..f4d1d3ce 100644 --- a/bot/exts/easter/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -9,16 +9,14 @@ from discord.ext import commands from bot.utils.decorators import override_in_channel -log = logging.getLogger(__name__) +with Path("bot/resources/easter/starter.json").open("r", encoding="utf8") as f: + STARTERS = json.load(f)["starters"] -with open(Path("bot/resources/easter/starter.json"), "r", encoding="utf8") as f: - starters = json.load(f) - -with open(Path("bot/resources/easter/py_topics.json"), "r", encoding="utf8") as f: +with Path("bot/resources/easter/py_topics.json").open("r", encoding="utf8") as f: # First ID is #python-general and the rest are top to bottom categories of Topical Chat/Help. - py_topics = json.load(f)["python-channels"] - all_python_channels = [int(channel_id) for channel_id in py_topics.keys()] + PY_TOPICS = json.load(f)["python-channels"] + ALL_PYTHON_CHANNELS = [int(channel_id) for channel_id in PY_TOPICS.keys()] class ConvoStarters(commands.Cog): @@ -28,17 +26,22 @@ class ConvoStarters(commands.Cog): self.bot = bot @commands.command() - @override_in_channel(all_python_channels) + @override_in_channel(ALL_PYTHON_CHANNELS) async def topic(self, ctx: commands.Context) -> None: """Responds with a random topic to start a conversation, changing depending on channel.""" try: # Fetching topics. - channel_topics = py_topics[str(ctx.channel.id)] + channel_topics = PY_TOPICS[str(ctx.channel.id)] - if channel_topics: - return await ctx.send(random.choice(channel_topics)) + # If the channel isn't Python-related. + except KeyError: + await ctx.send(random.choice(starters['starters'])) - # If the channel ID doesn't have any topics. + # If the channel ID doesn't have any topics. + else: + if channel_topics: + await ctx.send(random.choice(channel_topics)) + else: embed = Embed( description=( @@ -46,11 +49,7 @@ class ConvoStarters(commands.Cog): "[here](https://github.com/python-discord/seasonalbot/issues/426)!" )) - return await ctx.send(embed=embed) - - except KeyError: - # If the channel isn't Python. - await ctx.send(random.choice(starters['starters'])) + await ctx.send(embed=embed) def setup(bot: commands.Bot) -> None: |