From 6f51cf18febdfdf8d8949e3a3a91d707ed2d9dc2 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sun, 9 Aug 2020 14:06:35 -0700 Subject: Edited "topic" command for fetching python channel topics. --- bot/exts/easter/conversationstarters.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'bot/exts/easter/conversationstarters.py') diff --git a/bot/exts/easter/conversationstarters.py b/bot/exts/easter/conversationstarters.py index a5f40445..0c773119 100644 --- a/bot/exts/easter/conversationstarters.py +++ b/bot/exts/easter/conversationstarters.py @@ -2,6 +2,7 @@ import json import logging import random from pathlib import Path +from discord import Embed from discord.ext import commands @@ -10,6 +11,10 @@ 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) + class ConvoStarters(commands.Cog): """Easter conversation topics.""" @@ -19,7 +24,25 @@ class ConvoStarters(commands.Cog): @commands.command() async def topic(self, ctx: commands.Context) -> None: - """Responds with a random topic to start a conversation.""" + """Responds with a random topic to start a conversation, changing depending on channel.""" + + # Fetching topics. + channel_topics = py_topic[str(ctx.channel.id)] + + if channel_topics: + return await ctx.send(random.choice(channel_topics['python-channels'])) + + 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'])) -- cgit v1.2.3 From 66061654ac708d6290c225808e6b9813051d5163 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sun, 9 Aug 2020 15:46:03 -0700 Subject: Finalized topic selection. --- bot/exts/easter/conversationstarters.py | 45 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'bot/exts/easter/conversationstarters.py') 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: -- cgit v1.2.3 From 7756650dc337b913bba75cdc5b9f3dabc61b4c68 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 10 Aug 2020 13:03:13 -0700 Subject: Updated to comply with reviews. --- bot/exts/easter/conversationstarters.py | 58 ------------------------------ bot/exts/evergreen/conversationstarters.py | 57 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 58 deletions(-) delete mode 100644 bot/exts/easter/conversationstarters.py create mode 100644 bot/exts/evergreen/conversationstarters.py (limited to 'bot/exts/easter/conversationstarters.py') diff --git a/bot/exts/easter/conversationstarters.py b/bot/exts/easter/conversationstarters.py deleted file mode 100644 index 212e65b7..00000000 --- a/bot/exts/easter/conversationstarters.py +++ /dev/null @@ -1,58 +0,0 @@ -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 - - -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)["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 channel_topics: - return await ctx.send(random.choice(channel_topics)) - - # If the channel ID doesn't have any 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)!" - )) - - 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: - """Conversation starters Cog load.""" - bot.add_cog(ConvoStarters(bot)) 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)) -- cgit v1.2.3