aboutsummaryrefslogtreecommitdiffstats
path: root/bot
diff options
context:
space:
mode:
Diffstat (limited to 'bot')
-rw-r--r--bot/exts/evergreen/conversationstarters.py44
-rw-r--r--bot/resources/evergreen/py_topics.yaml25
-rw-r--r--bot/resources/evergreen/starter.json24
-rw-r--r--bot/resources/evergreen/starter.yaml22
-rw-r--r--bot/utils/randomization.py23
5 files changed, 82 insertions, 56 deletions
diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py
index cfa8dbce..576b8d76 100644
--- a/bot/exts/evergreen/conversationstarters.py
+++ b/bot/exts/evergreen/conversationstarters.py
@@ -1,5 +1,3 @@
-import json
-import random
from pathlib import Path
import yaml
@@ -8,11 +6,12 @@ from discord.ext import commands
from bot.constants import WHITELISTED_CHANNELS
from bot.utils.decorators import override_in_channel
+from bot.utils.randomization import RandomCycle
+SUGGESTION_FORM = 'https://forms.gle/zw6kkJqv8U43Nfjg9'
-with Path("bot/resources/evergreen/starter.json").open("r", encoding="utf8") as f:
- STARTERS = json.load(f)["starters"]
-
+with Path("bot/resources/evergreen/starter.yaml").open("r", encoding="utf8") as f:
+ STARTERS = yaml.load(f, Loader=yaml.FullLoader)
with Path("bot/resources/evergreen/py_topics.yaml").open("r", encoding="utf8") as f:
# First ID is #python-general and the rest are top to bottom categories of Topical Chat/Help.
@@ -22,7 +21,14 @@ with Path("bot/resources/evergreen/py_topics.yaml").open("r", encoding="utf8") a
PY_TOPICS = {k: [i for i in v if i] if isinstance(v, list) else [] for k, v in PY_TOPICS.items()}
# All the allowed channels that the ".topic" command is allowed to be executed in.
- ALL_ALLOWED_CHANNELS = [channel_id for channel_id in PY_TOPICS.keys()] + list(WHITELISTED_CHANNELS)
+ ALL_ALLOWED_CHANNELS = list(PY_TOPICS.keys()) + list(WHITELISTED_CHANNELS)
+
+# Putting all topics into one dictionary and shuffling lists to reduce same-topic repetitions.
+ALL_TOPICS = {'default': STARTERS, **PY_TOPICS}
+TOPICS = {
+ channel: RandomCycle(topics or ['No topics found for this channel.'])
+ for channel, topics in ALL_TOPICS.items()
+}
class ConvoStarters(commands.Cog):
@@ -39,31 +45,25 @@ class ConvoStarters(commands.Cog):
If in a Python channel, a python-related topic will be given.
- Otherwise, a random conversation topic will be recieved by the user.
+ Otherwise, a random conversation topic will be received by the user.
"""
+ # No matter what, the form will be shown.
+ embed = Embed(description=f'Suggest more topics [here]({SUGGESTION_FORM})!', color=Color.blurple())
+
try:
# Fetching topics.
- channel_topics = PY_TOPICS[ctx.channel.id]
+ channel_topics = TOPICS[ctx.channel.id]
# If the channel isn't Python-related.
except KeyError:
- await ctx.send(random.choice(STARTERS))
+ embed.title = f'**{next(TOPICS["default"])}**'
# 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)!"
- ),
- color=Color.blurple()
- )
-
- await ctx.send(embed=embed)
+ embed.title = f'**{next(channel_topics)}**'
+
+ finally:
+ await ctx.send(embed=embed)
def setup(bot: commands.Bot) -> None:
diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml
index ae5289a7..1e53429a 100644
--- a/bot/resources/evergreen/py_topics.yaml
+++ b/bot/resources/evergreen/py_topics.yaml
@@ -1,4 +1,4 @@
-# Conversation starters for python-related channels.
+# Conversation starters for Python-related channels.
# python-general
267624335836053506:
@@ -6,18 +6,26 @@
- What's your current text editor/IDE, and what functionality do you like about it the most when programming in Python?
- What functionality is your text editor/IDE missing for programming Python?
- What parts of your life has Python automated, if any?
- - Which python project are you the most proud of making?
+ - Which Python project are you the most proud of making?
- What made you want to learn Python?
- When did you start learning Python?
- What reasons are you learning Python for?
- Where's the strangest place you've seen Python?
- How has learning Python changed your life?
+ - Is there a package you wish existed but doesn't? What is it?
+ - What feature do you think should be added to Python?
+ - Has Python helped you in school? If so, how?
+ - What was the first thing you created with Python?
# async
630504881542791169:
- Are there any frameworks you wish were async?
- How have coroutines changed the way you write Python?
+# c-extensions
+728390945384431688:
+ -
+
# computer-science
650401909852864553:
-
@@ -41,6 +49,7 @@
# esoteric-python
470884583684964352:
- What's a common part of programming we can make harder?
+ - What are the pros and cons of messing with __magic__()?
# game-development
660625198390837248:
@@ -52,15 +61,11 @@
# networking
716325106619777044:
- -
-
-# python-extensions
-728390945384431688:
- -
+ - If you could wish for a library involving networking, what would it be?
# security
366674035876167691:
- -
+ - If you could wish for a library involving net-sec, what would it be?
# software-testing
463035728335732738:
@@ -77,8 +82,8 @@
# user-interfaces
338993628049571840:
- -
+ - What's the most impressive Desktop Application you've made with Python so far?
# web-development
366673702533988363:
- -
+ - How has Python helped you in web development?
diff --git a/bot/resources/evergreen/starter.json b/bot/resources/evergreen/starter.json
deleted file mode 100644
index 31e2cbc9..00000000
--- a/bot/resources/evergreen/starter.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "starters": [
- "What is your favourite Easter candy or treat?",
- "What is your earliest memory of Easter?",
- "What is the title of the last book you read?",
- "What is better: Milk, Dark or White chocolate?",
- "What is your favourite holiday?",
- "If you could have any superpower, what would it be?",
- "Name one thing you like about a person to your right.",
- "If you could be anyone else for one day, who would it be?",
- "What Easter tradition do you enjoy most?",
- "What is the best gift you've been given?",
- "Name one famous person you would like to have at your easter dinner.",
- "What was the last movie you saw in a cinema?",
- "What is your favourite food?",
- "If you could travel anywhere in the world, where would you go?",
- "Tell us 5 things you do well.",
- "What is your favourite place that you have visited?",
- "What is your favourite color?",
- "If you had $100 bill in your Easter Basket, what would you do with it?",
- "What would you do if you know you could succeed at anything you chose to do?",
- "If you could take only three things from your house, what would they be?"
- ]
-}
diff --git a/bot/resources/evergreen/starter.yaml b/bot/resources/evergreen/starter.yaml
new file mode 100644
index 00000000..53c89364
--- /dev/null
+++ b/bot/resources/evergreen/starter.yaml
@@ -0,0 +1,22 @@
+# Conversation starters for channels that are not Python-related.
+
+- What is your favourite Easter candy or treat?
+- What is your earliest memory of Easter?
+- What is the title of the last book you read?
+- "What is better: Milk, Dark or White chocolate?"
+- What is your favourite holiday?
+- If you could have any superpower, what would it be?
+- Name one thing you like about a person to your right.
+- If you could be anyone else for one day, who would it be?
+- What Easter tradition do you enjoy most?
+- What is the best gift you've been given?
+- Name one famous person you would like to have at your easter dinner.
+- What was the last movie you saw in a cinema?
+- What is your favourite food?
+- If you could travel anywhere in the world, where would you go?
+- Tell us 5 things you do well.
+- What is your favourite place that you have visited?
+- What is your favourite color?
+- If you had $100 bill in your Easter Basket, what would you do with it?
+- What would you do if you know you could succeed at anything you chose to do?
+- If you could take only three things from your house, what would they be?
diff --git a/bot/utils/randomization.py b/bot/utils/randomization.py
new file mode 100644
index 00000000..8f47679a
--- /dev/null
+++ b/bot/utils/randomization.py
@@ -0,0 +1,23 @@
+import itertools
+import random
+import typing as t
+
+
+class RandomCycle:
+ """
+ Cycles through elements from a randomly shuffled iterable, repeating indefinitely.
+
+ The iterable is reshuffled after each full cycle.
+ """
+
+ def __init__(self, iterable: t.Iterable) -> None:
+ self.iterable = list(iterable)
+ self.index = itertools.cycle(range(len(iterable)))
+
+ def __next__(self) -> t.Any:
+ idx = next(self.index)
+
+ if idx == 0:
+ random.shuffle(self.iterable)
+
+ return self.iterable[idx]