aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/evergreen/conversationstarters.py
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2020-09-09 15:49:05 -0700
committerGravatar Xithrius <[email protected]>2020-09-09 15:49:05 -0700
commit434e9a65529d77a0954255781c8792de60ab28d6 (patch)
treef534047a431b71b329f7699591c9fb1a11b4efb9 /bot/exts/evergreen/conversationstarters.py
parentRemoved logging. (diff)
Added RandomCycle utility to jump between set indexes repeatedly.
Diffstat (limited to 'bot/exts/evergreen/conversationstarters.py')
-rw-r--r--bot/exts/evergreen/conversationstarters.py13
1 files changed, 3 insertions, 10 deletions
diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py
index 68790dca..ebefc53e 100644
--- a/bot/exts/evergreen/conversationstarters.py
+++ b/bot/exts/evergreen/conversationstarters.py
@@ -1,5 +1,3 @@
-import itertools
-import random
from pathlib import Path
import yaml
@@ -8,6 +6,7 @@ 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'
@@ -25,14 +24,8 @@ with Path("bot/resources/evergreen/py_topics.yaml").open("r", encoding="utf8") a
ALL_ALLOWED_CHANNELS = [channel_id for channel_id in PY_TOPICS.keys()] + list(WHITELISTED_CHANNELS)
# Putting all topics into one dictionary and shuffling lists to reduce same-topic repetitions.
-TOPICS = {}
-for k, v in {**{'default': STARTERS}, **PY_TOPICS}.items():
- if len(v):
- random.shuffle(v)
- TOPICS[k] = itertools.cycle(v)
-
- else:
- TOPICS[k] = False
+all_topics = {'default': STARTERS, **PY_TOPICS}
+TOPICS = {channel: RandomCycle(topics) if len(topics) else False for channel, topics in all_topics.items()}
class ConvoStarters(commands.Cog):