aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2020-08-09 15:46:03 -0700
committerGravatar Xithrius <[email protected]>2020-08-09 15:46:03 -0700
commit66061654ac708d6290c225808e6b9813051d5163 (patch)
treed388da5c806bb8757ca562070d6abc4a250e1d60
parentUpdated dependencies (diff)
Finalized topic selection.
-rw-r--r--bot/exts/easter/conversationstarters.py45
1 files changed, 26 insertions, 19 deletions
diff --git a/bot/exts/easter/conversationstarters.py b/bot/exts/easter/conversationstarters.py
index 0c773119..212e65b7 100644
--- a/bot/exts/easter/conversationstarters.py
+++ b/bot/exts/easter/conversationstarters.py
@@ -2,18 +2,23 @@ import json
import logging
import random
from pathlib import Path
-from discord import Embed
+from discord import Embed
from discord.ext import commands
+from bot.utils.decorators import override_in_channel
+
+
log = logging.getLogger(__name__)
+
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:
# First ID is #python-general and the rest are top to bottom categories of Topical Chat/Help.
- py_topics = json.load(f)
+ py_topics = json.load(f)["python-channels"]
+ all_python_channels = [int(channel_id) for channel_id in py_topics.keys()]
class ConvoStarters(commands.Cog):
@@ -23,27 +28,29 @@ class ConvoStarters(commands.Cog):
self.bot = bot
@commands.command()
+ @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."""
+ """Responds with a random topic to start a conversation, changing depending on channel."""
+ try:
+ # Fetching topics.
+ channel_topics = py_topics[str(ctx.channel.id)]
- # Fetching topics.
- channel_topics = py_topic[str(ctx.channel.id)]
-
- if channel_topics:
- return await ctx.send(random.choice(channel_topics['python-channels']))
+ if channel_topics:
+ return await ctx.send(random.choice(channel_topics))
- else:
# If the channel ID doesn't have any topics.
- embed = Embed(
- description=(
- "No topics found. You can suggest new ideas for topics "
- "[here](https://github.com/python-discord/seasonalbot/issues/426)!"
- ))
-
- return await ctx.send(embed=embed)
-
- # If the channel isn't Python.
- await ctx.send(random.choice(starters['starters']))
+ else:
+ embed = Embed(
+ description=(
+ "No topics found for this Python channel. You can suggest new ideas for topics "
+ "[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']))
def setup(bot: commands.Bot) -> None: