blob: 0c7731193bd517875e4416ab9b1bbf33f0ff732e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import json
import logging
import random
from pathlib import Path
from discord import Embed
from discord.ext import commands
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."""
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command()
async def topic(self, ctx: commands.Context) -> None:
"""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']))
def setup(bot: commands.Bot) -> None:
"""Conversation starters Cog load."""
bot.add_cog(ConvoStarters(bot))
|