From 33ad42cef738241af7647011970d5157c8b8e4ec Mon Sep 17 00:00:00 2001 From: Xithrius Date: Wed, 9 Sep 2020 14:59:03 -0700 Subject: Changed from json formatting to yaml to get the ability for comments. --- bot/resources/evergreen/starter.json | 24 ------------------------ bot/resources/evergreen/starter.yaml | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 24 deletions(-) delete mode 100644 bot/resources/evergreen/starter.json create mode 100644 bot/resources/evergreen/starter.yaml (limited to 'bot') 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? -- cgit v1.2.3 From 415b8bfee1f4b4301e9ad3acbea147ecb3f6c6f0 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Wed, 9 Sep 2020 15:00:23 -0700 Subject: Added more topics. --- bot/resources/evergreen/py_topics.yaml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'bot') diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml index ae5289a7..971be3cd 100644 --- a/bot/resources/evergreen/py_topics.yaml +++ b/bot/resources/evergreen/py_topics.yaml @@ -1,17 +1,21 @@ -# Conversation starters for python-related channels. +# Conversation starters for Python-related channels. -# python-general +# Python-general 267624335836053506: - What's your favorite PEP? - 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: @@ -38,9 +42,10 @@ - What feature would you like to see added to the library? what feature in the library do you think is redundant? - Do you think there's a way in which Discord could handle bots better? -# esoteric-python +# 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 +57,15 @@ # networking 716325106619777044: - - + - If you could wish for a library involving networking, what would it be? -# python-extensions +# Python-extensions 728390945384431688: - # 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? -- cgit v1.2.3 From 3544e71de5c9bf2de801be22977b7dd9a40ae6f0 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Wed, 9 Sep 2020 15:01:07 -0700 Subject: Topics are now iterated through instead of randomly selected. --- bot/exts/evergreen/conversationstarters.py | 42 ++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index cfa8dbce..423662bb 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -1,4 +1,5 @@ -import json +import itertools +import logging import random from pathlib import Path @@ -9,10 +10,12 @@ from discord.ext import commands from bot.constants import WHITELISTED_CHANNELS from bot.utils.decorators import override_in_channel +log = logging.getLogger(__name__) -with Path("bot/resources/evergreen/starter.json").open("r", encoding="utf8") as f: - STARTERS = json.load(f)["starters"] +SUGGESTION_FORM = 'https://forms.gle/zw6kkJqv8U43Nfjg9' +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. @@ -24,6 +27,16 @@ with Path("bot/resources/evergreen/py_topics.yaml").open("r", encoding="utf8") a # 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) +# 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 + class ConvoStarters(commands.Cog): """Evergreen conversation topics.""" @@ -39,31 +52,28 @@ 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)) + embed.title = f'**{next(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 = 'No topics found for this channel.' + + await ctx.send(embed=embed) def setup(bot: commands.Bot) -> None: -- cgit v1.2.3 From f1b0c9da9abf32a838f5ea323325507fd5af8020 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Wed, 9 Sep 2020 15:17:40 -0700 Subject: Removed logging. --- bot/exts/evergreen/conversationstarters.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index 423662bb..68790dca 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -1,5 +1,4 @@ import itertools -import logging import random from pathlib import Path @@ -10,8 +9,6 @@ from discord.ext import commands from bot.constants import WHITELISTED_CHANNELS from bot.utils.decorators import override_in_channel -log = logging.getLogger(__name__) - SUGGESTION_FORM = 'https://forms.gle/zw6kkJqv8U43Nfjg9' with Path("bot/resources/evergreen/starter.yaml").open("r", encoding="utf8") as f: -- cgit v1.2.3 From 434e9a65529d77a0954255781c8792de60ab28d6 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Wed, 9 Sep 2020 15:49:05 -0700 Subject: Added RandomCycle utility to jump between set indexes repeatedly. --- bot/exts/evergreen/conversationstarters.py | 13 +++---------- bot/utils/randomization.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 bot/utils/randomization.py (limited to 'bot') 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): diff --git a/bot/utils/randomization.py b/bot/utils/randomization.py new file mode 100644 index 00000000..063d7e1f --- /dev/null +++ b/bot/utils/randomization.py @@ -0,0 +1,19 @@ +import itertools +import random +import typing as t + + +class RandomCycle: + """Cycling through jumping to random indexes in an iterable.""" + + 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] -- cgit v1.2.3 From 2844b11032e0a330bfeaf43f08c607c2f26ffc58 Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Wed, 9 Sep 2020 20:01:08 -0700 Subject: Update bot/exts/evergreen/conversationstarters.py Co-authored-by: Shirayuki Nekomata --- bot/exts/evergreen/conversationstarters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index ebefc53e..16a7dcfc 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -24,7 +24,7 @@ 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. -all_topics = {'default': STARTERS, **PY_TOPICS} +ALL_TOPICS = {'default': STARTERS, **PY_TOPICS} TOPICS = {channel: RandomCycle(topics) if len(topics) else False for channel, topics in all_topics.items()} -- cgit v1.2.3 From 189d2e3714cb532f00921d11a9908b39ca1d7955 Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Thu, 10 Sep 2020 08:43:47 -0700 Subject: Update bot/utils/randomization.py Co-authored-by: Dennis Pham --- bot/utils/randomization.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/utils/randomization.py b/bot/utils/randomization.py index 063d7e1f..8f47679a 100644 --- a/bot/utils/randomization.py +++ b/bot/utils/randomization.py @@ -4,7 +4,11 @@ import typing as t class RandomCycle: - """Cycling through jumping to random indexes in an iterable.""" + """ + 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) -- cgit v1.2.3 From ee693c284103ca1e730f71a845b359a400bd7ed2 Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Thu, 10 Sep 2020 08:46:50 -0700 Subject: Update bot/exts/evergreen/conversationstarters.py Co-authored-by: Shirayuki Nekomata --- bot/exts/evergreen/conversationstarters.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index 16a7dcfc..beda8479 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -25,7 +25,10 @@ with Path("bot/resources/evergreen/py_topics.yaml").open("r", encoding="utf8") a # Putting all topics into one dictionary and shuffling lists to reduce same-topic repetitions. ALL_TOPICS = {'default': STARTERS, **PY_TOPICS} -TOPICS = {channel: RandomCycle(topics) if len(topics) else False for channel, topics in all_topics.items()} +TOPICS = { + channel: RandomCycle(topics or ['No topics found for this channel.']) + for channel, topics in all_topics.items() +} class ConvoStarters(commands.Cog): -- cgit v1.2.3 From f2062902047e46e3edf05707a6cd570c6d5ddbe4 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Thu, 10 Sep 2020 08:53:33 -0700 Subject: Renamed "esoteric-Python" to "esoteric-python" --- bot/resources/evergreen/py_topics.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml index 971be3cd..52582667 100644 --- a/bot/resources/evergreen/py_topics.yaml +++ b/bot/resources/evergreen/py_topics.yaml @@ -42,7 +42,7 @@ - What feature would you like to see added to the library? what feature in the library do you think is redundant? - Do you think there's a way in which Discord could handle bots better? -# esoteric-Python +# esoteric-python 470884583684964352: - What's a common part of programming we can make harder? - What are the pros and cons of messing with __magic__()? -- cgit v1.2.3 From ffdb4ac4a80e4f1579ba1ea26547e206c18ff646 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Thu, 10 Sep 2020 09:06:37 -0700 Subject: Updated conversationstarters to simplify what values need to be checked. --- bot/exts/evergreen/conversationstarters.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index beda8479..1912d1af 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -27,7 +27,7 @@ with Path("bot/resources/evergreen/py_topics.yaml").open("r", encoding="utf8") a ALL_TOPICS = {'default': STARTERS, **PY_TOPICS} TOPICS = { channel: RandomCycle(topics or ['No topics found for this channel.']) - for channel, topics in all_topics.items() + for channel, topics in ALL_TOPICS.items() } @@ -60,13 +60,10 @@ class ConvoStarters(commands.Cog): # If the channel ID doesn't have any topics. else: - if channel_topics: - embed.title = f'**{next(channel_topics)}**' + embed.title = f'**{next(channel_topics)}**' - else: - embed.title = 'No topics found for this channel.' - - await ctx.send(embed=embed) + finally: + await ctx.send(embed=embed) def setup(bot: commands.Bot) -> None: -- cgit v1.2.3 From f2cd2214e59c4c38353a2591273e5407805f491c Mon Sep 17 00:00:00 2001 From: Xithrius Date: Thu, 10 Sep 2020 11:37:33 -0700 Subject: Made all channel names lowercase. --- bot/resources/evergreen/py_topics.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml index 52582667..278e6697 100644 --- a/bot/resources/evergreen/py_topics.yaml +++ b/bot/resources/evergreen/py_topics.yaml @@ -1,7 +1,7 @@ # Conversation starters for Python-related channels. -# Python-general -267624335836053506: +# python-general +704362672644423840: - What's your favorite PEP? - 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? @@ -23,7 +23,7 @@ - How have coroutines changed the way you write Python? # computer-science -650401909852864553: +704406535509639209: - # databases @@ -59,7 +59,7 @@ 716325106619777044: - If you could wish for a library involving networking, what would it be? -# Python-extensions +# python-extensions 728390945384431688: - -- cgit v1.2.3 From e7f65121440a5fcbc53ad604a7dfbc24f30bab3b Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Thu, 10 Sep 2020 15:54:07 -0700 Subject: Update bot/exts/evergreen/conversationstarters.py Co-authored-by: Dennis Pham --- bot/exts/evergreen/conversationstarters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index 1912d1af..576b8d76 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -21,7 +21,7 @@ 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} -- cgit v1.2.3 From ca105b297ea65fafdcf26135565c23147341e243 Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Thu, 10 Sep 2020 15:55:41 -0700 Subject: Updated the #python-general channel ID. Co-authored-by: Dennis Pham --- bot/resources/evergreen/py_topics.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml index 278e6697..aaa9ba48 100644 --- a/bot/resources/evergreen/py_topics.yaml +++ b/bot/resources/evergreen/py_topics.yaml @@ -1,7 +1,7 @@ # Conversation starters for Python-related channels. # python-general -704362672644423840: +267624335836053506: - What's your favorite PEP? - 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? -- cgit v1.2.3 From bf09b71197bbf8f424ac5c1a9be3f6f6d698f7a9 Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Thu, 10 Sep 2020 15:55:59 -0700 Subject: Updated the #computer-science channel ID. Co-authored-by: Dennis Pham --- bot/resources/evergreen/py_topics.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml index aaa9ba48..7c3df5d3 100644 --- a/bot/resources/evergreen/py_topics.yaml +++ b/bot/resources/evergreen/py_topics.yaml @@ -23,7 +23,7 @@ - How have coroutines changed the way you write Python? # computer-science -704406535509639209: +650401909852864553: - # databases -- cgit v1.2.3 From 10ad8370b2c69828869c25b41fd8a722619fa0f1 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Thu, 10 Sep 2020 16:07:57 -0700 Subject: Renamed from python-extensions to c-extensions, reordered within list. --- bot/resources/evergreen/py_topics.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml index 7c3df5d3..1e53429a 100644 --- a/bot/resources/evergreen/py_topics.yaml +++ b/bot/resources/evergreen/py_topics.yaml @@ -22,6 +22,10 @@ - Are there any frameworks you wish were async? - How have coroutines changed the way you write Python? +# c-extensions +728390945384431688: + - + # computer-science 650401909852864553: - @@ -59,10 +63,6 @@ 716325106619777044: - If you could wish for a library involving networking, what would it be? -# python-extensions -728390945384431688: - - - # security 366674035876167691: - If you could wish for a library involving net-sec, what would it be? -- cgit v1.2.3