aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/evergreen/conversationstarters.py
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2020-08-10 13:03:13 -0700
committerGravatar Xithrius <[email protected]>2020-08-10 13:03:13 -0700
commit7756650dc337b913bba75cdc5b9f3dabc61b4c68 (patch)
tree15dc3dd1d3c91706da1e556594e50f5b2b3459d3 /bot/exts/evergreen/conversationstarters.py
parentFinalized topic selection. (diff)
Updated to comply with reviews.
Diffstat (limited to 'bot/exts/evergreen/conversationstarters.py')
-rw-r--r--bot/exts/evergreen/conversationstarters.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py
new file mode 100644
index 00000000..f4d1d3ce
--- /dev/null
+++ b/bot/exts/evergreen/conversationstarters.py
@@ -0,0 +1,57 @@
+import json
+import logging
+import random
+from pathlib import Path
+
+from discord import Embed
+from discord.ext import commands
+
+from bot.utils.decorators import override_in_channel
+
+
+with Path("bot/resources/easter/starter.json").open("r", encoding="utf8") as f:
+ STARTERS = json.load(f)["starters"]
+
+
+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()]
+
+
+class ConvoStarters(commands.Cog):
+ """Easter conversation topics."""
+
+ def __init__(self, bot: commands.Bot):
+ 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."""
+ try:
+ # Fetching topics.
+ channel_topics = PY_TOPICS[str(ctx.channel.id)]
+
+ # 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.
+ else:
+ if channel_topics:
+ await ctx.send(random.choice(channel_topics))
+
+ 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)!"
+ ))
+
+ await ctx.send(embed=embed)
+
+
+def setup(bot: commands.Bot) -> None:
+ """Conversation starters Cog load."""
+ bot.add_cog(ConvoStarters(bot))