From 217b42985f782a1227371296f313c4ea7402a87a Mon Sep 17 00:00:00 2001 From: AtieP <62116490+AtieP@users.noreply.github.com> Date: Sat, 13 Jun 2020 14:44:52 +0200 Subject: 6 more questions added. 6 more questions added for the quiz command on the category Evergreen. --- bot/resources/evergreen/trivia_quiz.json | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bot/resources/evergreen/trivia_quiz.json b/bot/resources/evergreen/trivia_quiz.json index 6100ca62..f655e39d 100644 --- a/bot/resources/evergreen/trivia_quiz.json +++ b/bot/resources/evergreen/trivia_quiz.json @@ -217,6 +217,36 @@ "question": "What does the acronym GPRS stand for?", "answer": "General Packet Radio Service", "info": "General Packet Radio Service (GPRS) is a packet-based mobile data service on the global system for mobile communications (GSM) of 3G and 2G cellular communication systems. It is a non-voice, high-speed and useful packet-switching technology intended for GSM networks." + }, + { + "id": 131, + "question": "In what country the Ebro river is located?", + "answer": "Spain", + "info": "The Ebro river is a river located in Spain. It is 930 kilometers long and it's the second longest river that ends on the Mediterranean Sea." + }, + { + "id": 132, + "question": "What year the IBM PC model 5150 was introduced in the market?", + "answer": "1981", + "info": "The IBM PC was introduced in the market on 1981. It used the Intel 8088, with a clock speed of 4.77 MHz, along with the MDA and CGA as a video card." + }, + { + "id": 133, + "question": "What's the world's largest urban area?", + "answer": "Tokio", + "info": "Tokio is the most populated city in the world, with 37 million of people. It is located on Japan." + }, + { + "id": 134, + "question": "How many planets there are on the Solar system?", + "answer": "8", + "info": "On the Solar system there are 8 planets: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune. Pluto isn't considered a planet on the Solar System anymore." + }, + { + "id": 135, + "question": "What is the capital of Iraq?", + "answer": "Baghdad", + "info": "Baghdad is the capital of Iraq. It has a population of 7 million people." } ] } -- cgit v1.2.3 From 4b871609190ce5ecb9eb47c5e1f7e3a42effd989 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sat, 13 Jun 2020 23:06:37 +0800 Subject: Add initial caesarcipher command --- bot/exts/evergreen/fun.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 67a4bae5..5f4c5b3e 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -87,6 +87,40 @@ class Fun(Cog): converted_text = f">>> {converted_text.lstrip('> ')}" await ctx.send(content=converted_text, embed=embed) + @commands.command(name="caesarcipher", aliases=("caesar",)) + async def caesarcipher_command(self, ctx: Context, offset: int, *, text: str) -> None: + """ + Given an integer `offset`, encrypt the given `text`. + + A positive `offset` will cause the letters to shift right, + while a negative `offset` will cause the letters to shift left. + + Also accepts a valid discord Message ID or link. + """ + + def cipher_func(text: str) -> str: + """Implements a lazy Caesar cipher algorithm.""" + for char in text: + if not char.isascii() or not char.isalpha() or char.isspace(): + yield char + continue + case_start = 65 if char.isupper() else 97 + yield chr((ord(char) - case_start + offset) % 26 + case_start) + + def conversion_func(text: str) -> str: + """Encrypts the given string using the Caesar cipher.""" + return "".join(cipher_func(text)) + + text, embed = await Fun._get_text_and_embed(ctx, text) + # Convert embed if it exists + if embed is not None: + embed = Fun._convert_embed(conversion_func, embed) + converted_text = conversion_func(text) + # Don't put >>> if only embed present + if converted_text: + converted_text = f">>> {converted_text.lstrip('> ')}" + await ctx.send(content=converted_text, embed=embed) + @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: """ -- cgit v1.2.3 From 3e58b35174ea4aa686f1347c41ecd056df74f6ee Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 14 Jun 2020 11:20:59 +0800 Subject: Make caesarcipher a command group --- bot/exts/evergreen/fun.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 5f4c5b3e..2b1abaa4 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -87,19 +87,32 @@ class Fun(Cog): converted_text = f">>> {converted_text.lstrip('> ')}" await ctx.send(content=converted_text, embed=embed) - @commands.command(name="caesarcipher", aliases=("caesar",)) - async def caesarcipher_command(self, ctx: Context, offset: int, *, text: str) -> None: + @commands.group(name="caesarcipher", aliases=("caesar",)) + async def caesarcipher_group(self, ctx: Context) -> None: """ - Given an integer `offset`, encrypt the given `text`. + Translates a message using the Caesar Cipher. + + See `info` and `translate` subcommands. + """ + if ctx.invoked_subcommand is None: + await self.bot.get_cog("Help").new_help(ctx, "caesarcipher") + + @caesarcipher_group.command(name="info") + async def caesarcipher_info(self, ctx: Context) -> None: + """Information about the Caesar Cipher.""" + + @caesarcipher_group.command(name="translate") + async def caesarcipher_translate(self, ctx: Context, offset: int, *, text: str) -> None: + """ + Given an integer `offset`, translate the given `text`. A positive `offset` will cause the letters to shift right, while a negative `offset` will cause the letters to shift left. Also accepts a valid discord Message ID or link. """ - def cipher_func(text: str) -> str: - """Implements a lazy Caesar cipher algorithm.""" + """Implements a lazy Caesar Cipher algorithm.""" for char in text: if not char.isascii() or not char.isalpha() or char.isspace(): yield char @@ -108,7 +121,7 @@ class Fun(Cog): yield chr((ord(char) - case_start + offset) % 26 + case_start) def conversion_func(text: str) -> str: - """Encrypts the given string using the Caesar cipher.""" + """Encrypts the given string using the Caesar Cipher.""" return "".join(cipher_func(text)) text, embed = await Fun._get_text_and_embed(ctx, text) -- cgit v1.2.3 From ab63770f00783a7d12e34affefe3c3c8abce0d8f Mon Sep 17 00:00:00 2001 From: AtieP <62116490+AtieP@users.noreply.github.com> Date: Fri, 19 Jun 2020 19:12:26 +0200 Subject: Update bot/resources/evergreen/trivia_quiz.json Co-authored-by: Dennis Pham --- bot/resources/evergreen/trivia_quiz.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/resources/evergreen/trivia_quiz.json b/bot/resources/evergreen/trivia_quiz.json index f655e39d..dfffc0c2 100644 --- a/bot/resources/evergreen/trivia_quiz.json +++ b/bot/resources/evergreen/trivia_quiz.json @@ -220,7 +220,7 @@ }, { "id": 131, - "question": "In what country the Ebro river is located?", + "question": "In what country is the Ebro river located?", "answer": "Spain", "info": "The Ebro river is a river located in Spain. It is 930 kilometers long and it's the second longest river that ends on the Mediterranean Sea." }, -- cgit v1.2.3 From 9eaaf91076e564364c321e7860044e697da5dffc Mon Sep 17 00:00:00 2001 From: AtieP <62116490+AtieP@users.noreply.github.com> Date: Fri, 19 Jun 2020 19:12:38 +0200 Subject: Update bot/resources/evergreen/trivia_quiz.json Co-authored-by: Dennis Pham --- bot/resources/evergreen/trivia_quiz.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/resources/evergreen/trivia_quiz.json b/bot/resources/evergreen/trivia_quiz.json index dfffc0c2..e521f901 100644 --- a/bot/resources/evergreen/trivia_quiz.json +++ b/bot/resources/evergreen/trivia_quiz.json @@ -226,7 +226,7 @@ }, { "id": 132, - "question": "What year the IBM PC model 5150 was introduced in the market?", + "question": "What year was the IBM PC model 5150 introduced into the market?", "answer": "1981", "info": "The IBM PC was introduced in the market on 1981. It used the Intel 8088, with a clock speed of 4.77 MHz, along with the MDA and CGA as a video card." }, -- cgit v1.2.3 From 49b99331bbbb5c6532d20ae0216f0db4966f23f3 Mon Sep 17 00:00:00 2001 From: AtieP <62116490+AtieP@users.noreply.github.com> Date: Fri, 19 Jun 2020 19:12:59 +0200 Subject: Update bot/resources/evergreen/trivia_quiz.json Co-authored-by: Dennis Pham --- bot/resources/evergreen/trivia_quiz.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/resources/evergreen/trivia_quiz.json b/bot/resources/evergreen/trivia_quiz.json index e521f901..067b8fb5 100644 --- a/bot/resources/evergreen/trivia_quiz.json +++ b/bot/resources/evergreen/trivia_quiz.json @@ -233,7 +233,7 @@ { "id": 133, "question": "What's the world's largest urban area?", - "answer": "Tokio", + "answer": "Tokyo", "info": "Tokio is the most populated city in the world, with 37 million of people. It is located on Japan." }, { -- cgit v1.2.3 From baa20503e716a9ed9ab8be5f82c3456c7b4cfbb5 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 14 Jun 2020 14:20:09 +0800 Subject: Add basic caesar cipher information embed --- bot/exts/evergreen/fun.py | 13 ++++++++++++- bot/resources/evergreen/caesar_info.json | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 bot/resources/evergreen/caesar_info.json diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 2b1abaa4..f3e3bfcc 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -1,4 +1,5 @@ import functools +import json import logging import random from typing import Callable, Tuple, Union @@ -8,7 +9,7 @@ from discord.ext import commands from discord.ext.commands import Bot, Cog, Context, MessageConverter from bot import utils -from bot.constants import Emojis +from bot.constants import Colours, Emojis log = logging.getLogger(__name__) @@ -100,6 +101,16 @@ class Fun(Cog): @caesarcipher_group.command(name="info") async def caesarcipher_info(self, ctx: Context) -> None: """Information about the Caesar Cipher.""" + with open("bot\\resources\\evergreen\\caesar_info.json", "r") as f: + data = json.load(f) + + embed = Embed( + title=data["title"], + description="".join(data["description"]), + colour=Colours.dark_green, + ) + + await ctx.send(embed=embed) @caesarcipher_group.command(name="translate") async def caesarcipher_translate(self, ctx: Context, offset: int, *, text: str) -> None: diff --git a/bot/resources/evergreen/caesar_info.json b/bot/resources/evergreen/caesar_info.json new file mode 100644 index 00000000..ae3a4656 --- /dev/null +++ b/bot/resources/evergreen/caesar_info.json @@ -0,0 +1,4 @@ +{ + "title": "Caesar Cipher", + "description": "**Information**\nThe Caesar Cipher, named after hte Roman General Julius Caesar is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter given a specific position offset in the alphabet, with the letters wrapping around both sides.\n\n**Examples**\n1) `Hello World` <=> `Khoor Zruog` where letters are shifted forwards by `3.`\n2) `Julius Caesar` <=> `Yjaxjh Rpthpg` where letters are shifted backwards by `11.`" +} -- cgit v1.2.3 From 3260a16d78351fec2bab9ba6124e4a655fbd2e26 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 25 Jun 2020 23:29:06 +0800 Subject: Refactor translate subcommand to encrypt and decrypt --- bot/exts/evergreen/fun.py | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index f3e3bfcc..75b0e2b0 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -93,7 +93,7 @@ class Fun(Cog): """ Translates a message using the Caesar Cipher. - See `info` and `translate` subcommands. + See `decrpyt`, `encrypt`, and `info` subcommands. """ if ctx.invoked_subcommand is None: await self.bot.get_cog("Help").new_help(ctx, "caesarcipher") @@ -112,17 +112,17 @@ class Fun(Cog): await ctx.send(embed=embed) - @caesarcipher_group.command(name="translate") - async def caesarcipher_translate(self, ctx: Context, offset: int, *, text: str) -> None: + @staticmethod + async def _caesar_cipher(ctx: Context, offset: int, text: str) -> None: """ - Given an integer `offset`, translate the given `text`. + Given an integer `offset`, translates and sends the given `text`. - A positive `offset` will cause the letters to shift right, - while a negative `offset` will cause the letters to shift left. + A positive `offset` will cause the letters to shift right, while + a negative `offset` will cause the letters to shift left. - Also accepts a valid discord Message ID or link. + Also accepts a valid Discord Message ID or link. """ - def cipher_func(text: str) -> str: + def caesar_func(text: str) -> str: """Implements a lazy Caesar Cipher algorithm.""" for char in text: if not char.isascii() or not char.isalpha() or char.isspace(): @@ -133,7 +133,7 @@ class Fun(Cog): def conversion_func(text: str) -> str: """Encrypts the given string using the Caesar Cipher.""" - return "".join(cipher_func(text)) + return "".join(caesar_func(text)) text, embed = await Fun._get_text_and_embed(ctx, text) # Convert embed if it exists @@ -145,6 +145,28 @@ class Fun(Cog): converted_text = f">>> {converted_text.lstrip('> ')}" await ctx.send(content=converted_text, embed=embed) + @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift")) + async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, text: str) -> None: + """ + Given a positive integer `offset`, encrypt the given `text`. + + Performs a right shift of the letters in the message. + + Also accepts a valid Discord Message ID or link. + """ + await self._caesar_cipher(ctx, offset, text) + + @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift")) + async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, text: str) -> None: + """ + Given a positive integer `offset`, decrypt the given `text`. + + Performs a left shift of the letters in the message. + + Also accepts a valid Discord Message ID or link. + """ + await self._caesar_cipher(ctx, -offset, text) + @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: """ -- cgit v1.2.3 From f1a79fb65a98c4c483b3e77dfb1c910c8702165b Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 25 Jun 2020 23:47:30 +0800 Subject: Add offset validation --- bot/exts/evergreen/fun.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 75b0e2b0..364ce74b 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -154,7 +154,10 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - await self._caesar_cipher(ctx, offset, text) + if offset < 0: + await ctx.send(":no_entry: Cannot use a negative offset.") + else: + await self._caesar_cipher(ctx, offset, text) @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift")) async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, text: str) -> None: @@ -165,7 +168,10 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - await self._caesar_cipher(ctx, -offset, text) + if offset < 0: + await ctx.send(":no_entry: Cannot use a negative offset.") + else: + await self._caesar_cipher(ctx, -offset, text) @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: -- cgit v1.2.3 From d6539562aef0ae4be88ddb023f5ff49206a90cf0 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Fri, 26 Jun 2020 12:11:00 +0800 Subject: Load embed data in __init__ and use Embed.from_dict --- bot/exts/evergreen/fun.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 364ce74b..4fc06b49 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -33,6 +33,9 @@ class Fun(Cog): def __init__(self, bot: Bot) -> None: self.bot = bot + with open("bot\\resources\\evergreen\\caesar_info.json", "r") as f: + self._caesar_cipher_embed = json.load(f) + @commands.command() async def roll(self, ctx: Context, num_rolls: int = 1) -> None: """Outputs a number of random dice emotes (up to 6).""" @@ -101,14 +104,8 @@ class Fun(Cog): @caesarcipher_group.command(name="info") async def caesarcipher_info(self, ctx: Context) -> None: """Information about the Caesar Cipher.""" - with open("bot\\resources\\evergreen\\caesar_info.json", "r") as f: - data = json.load(f) - - embed = Embed( - title=data["title"], - description="".join(data["description"]), - colour=Colours.dark_green, - ) + embed = Embed.from_dict(self._caesar_cipher_embed) + embed.colour = Colours.dark_green await ctx.send(embed=embed) -- cgit v1.2.3 From 3fe9a22fc9cf57d284d17949563596e05ea5d033 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Fri, 26 Jun 2020 12:21:46 +0800 Subject: Use Context.invoke instead of invoking the Help cog --- bot/exts/evergreen/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 4fc06b49..090714aa 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -99,7 +99,7 @@ class Fun(Cog): See `decrpyt`, `encrypt`, and `info` subcommands. """ if ctx.invoked_subcommand is None: - await self.bot.get_cog("Help").new_help(ctx, "caesarcipher") + await ctx.invoke(self.bot.get_command("help"), "caesarcipher") @caesarcipher_group.command(name="info") async def caesarcipher_info(self, ctx: Context) -> None: -- cgit v1.2.3 From 3b27b96374488f2c2c34f51e718fc42fa5b7c1a6 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Fri, 26 Jun 2020 14:50:44 +0800 Subject: Utilize Union[Message, str] for converting messages --- bot/exts/evergreen/fun.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 090714aa..d1f87b6a 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -110,7 +110,7 @@ class Fun(Cog): await ctx.send(embed=embed) @staticmethod - async def _caesar_cipher(ctx: Context, offset: int, text: str) -> None: + async def _caesar_cipher(ctx: Context, offset: int, msg: Union[Message, str]) -> None: """ Given an integer `offset`, translates and sends the given `text`. @@ -132,18 +132,23 @@ class Fun(Cog): """Encrypts the given string using the Caesar Cipher.""" return "".join(caesar_func(text)) - text, embed = await Fun._get_text_and_embed(ctx, text) - # Convert embed if it exists + is_message = isinstance(msg, Message) + + text = msg.content if is_message else msg + embed = msg.embeds[0] if is_message and msg.embeds else None + if embed is not None: embed = Fun._convert_embed(conversion_func, embed) + converted_text = conversion_func(text) - # Don't put >>> if only embed present + if converted_text: converted_text = f">>> {converted_text.lstrip('> ')}" + await ctx.send(content=converted_text, embed=embed) @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift")) - async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, text: str) -> None: + async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ Given a positive integer `offset`, encrypt the given `text`. @@ -154,10 +159,10 @@ class Fun(Cog): if offset < 0: await ctx.send(":no_entry: Cannot use a negative offset.") else: - await self._caesar_cipher(ctx, offset, text) + await self._caesar_cipher(ctx, offset, msg) @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift")) - async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, text: str) -> None: + async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ Given a positive integer `offset`, decrypt the given `text`. @@ -168,7 +173,7 @@ class Fun(Cog): if offset < 0: await ctx.send(":no_entry: Cannot use a negative offset.") else: - await self._caesar_cipher(ctx, -offset, text) + await self._caesar_cipher(ctx, -offset, msg) @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: -- cgit v1.2.3 From 093a54c9acd546435c517497af409d55e0512412 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sat, 27 Jun 2020 15:17:18 +0800 Subject: Use pathlib and fix grammar in the information embed --- bot/exts/evergreen/fun.py | 3 ++- bot/resources/evergreen/caesar_info.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index d1f87b6a..601ae45b 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -2,6 +2,7 @@ import functools import json import logging import random +from pathlib import Path from typing import Callable, Tuple, Union from discord import Embed, Message @@ -33,7 +34,7 @@ class Fun(Cog): def __init__(self, bot: Bot) -> None: self.bot = bot - with open("bot\\resources\\evergreen\\caesar_info.json", "r") as f: + with Path("bot/resources/evergreen/caesar_info.json").open("r") as f: self._caesar_cipher_embed = json.load(f) @commands.command() diff --git a/bot/resources/evergreen/caesar_info.json b/bot/resources/evergreen/caesar_info.json index ae3a4656..8229c4f3 100644 --- a/bot/resources/evergreen/caesar_info.json +++ b/bot/resources/evergreen/caesar_info.json @@ -1,4 +1,4 @@ { "title": "Caesar Cipher", - "description": "**Information**\nThe Caesar Cipher, named after hte Roman General Julius Caesar is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter given a specific position offset in the alphabet, with the letters wrapping around both sides.\n\n**Examples**\n1) `Hello World` <=> `Khoor Zruog` where letters are shifted forwards by `3.`\n2) `Julius Caesar` <=> `Yjaxjh Rpthpg` where letters are shifted backwards by `11.`" + "description": "**Information**\nThe Caesar Cipher, named after the Roman General Julius Caesar, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter given a specific position offset in the alphabet, with the letters wrapping around both sides.\n\n**Examples**\n1) `Hello World` <=> `Khoor Zruog` where letters are shifted forwards by `3`.\n2) `Julius Caesar` <=> `Yjaxjh Rpthpg` where letters are shifted backwards by `11`." } -- cgit v1.2.3 From c59a1630817503ed8507a0b364e037077645af35 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sat, 27 Jun 2020 15:29:03 +0800 Subject: Add UTF-8 encoding when loading embed information --- bot/exts/evergreen/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 601ae45b..f9bd8812 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -34,7 +34,7 @@ class Fun(Cog): def __init__(self, bot: Bot) -> None: self.bot = bot - with Path("bot/resources/evergreen/caesar_info.json").open("r") as f: + with Path("bot/resources/evergreen/caesar_info.json").open("r", encoding="UTF-8") as f: self._caesar_cipher_embed = json.load(f) @commands.command() -- cgit v1.2.3 From e8a94313f93f12b52c76cebf4f425206475b89c1 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 28 Jun 2020 13:51:01 +0800 Subject: Add 'cc' alias for caesarcipher --- bot/exts/evergreen/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index f9bd8812..0abc0138 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -92,7 +92,7 @@ class Fun(Cog): converted_text = f">>> {converted_text.lstrip('> ')}" await ctx.send(content=converted_text, embed=embed) - @commands.group(name="caesarcipher", aliases=("caesar",)) + @commands.group(name="caesarcipher", aliases=("caesar", "cc",)) async def caesarcipher_group(self, ctx: Context) -> None: """ Translates a message using the Caesar Cipher. -- cgit v1.2.3 From 1d9ee64755736b715896e90c9b359b490f08e547 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 28 Jun 2020 13:53:54 +0800 Subject: Fix return type annotation --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 0abc0138..d376c44e 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -3,7 +3,7 @@ import json import logging import random from pathlib import Path -from typing import Callable, Tuple, Union +from typing import Callable, Iterable, Tuple, Union from discord import Embed, Message from discord.ext import commands @@ -120,7 +120,7 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - def caesar_func(text: str) -> str: + def caesar_func(text: str) -> Iterable[str]: """Implements a lazy Caesar Cipher algorithm.""" for char in text: if not char.isascii() or not char.isalpha() or char.isspace(): -- cgit v1.2.3 From b02b4e84caddb595d39b87571de6181f7446c528 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Tue, 30 Jun 2020 20:21:50 +0800 Subject: Change text to msg in command docstrings --- bot/exts/evergreen/fun.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index d376c44e..220881d4 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -113,7 +113,7 @@ class Fun(Cog): @staticmethod async def _caesar_cipher(ctx: Context, offset: int, msg: Union[Message, str]) -> None: """ - Given an integer `offset`, translates and sends the given `text`. + Given an integer `offset`, translates and sends the given `msg`. A positive `offset` will cause the letters to shift right, while a negative `offset` will cause the letters to shift left. @@ -151,7 +151,7 @@ class Fun(Cog): @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift")) async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ - Given a positive integer `offset`, encrypt the given `text`. + Given a positive integer `offset`, encrypt the given `msg`. Performs a right shift of the letters in the message. @@ -165,7 +165,7 @@ class Fun(Cog): @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift")) async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ - Given a positive integer `offset`, decrypt the given `text`. + Given a positive integer `offset`, decrypt the given `msg`. Performs a left shift of the letters in the message. -- cgit v1.2.3 From 52f99c69f882fdc253de594002d404a5b454a971 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 2 Jul 2020 19:21:56 +0800 Subject: Separate the formula for the actual offset --- bot/exts/evergreen/fun.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 220881d4..5f5c3718 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -126,8 +126,11 @@ class Fun(Cog): if not char.isascii() or not char.isalpha() or char.isspace(): yield char continue + case_start = 65 if char.isupper() else 97 - yield chr((ord(char) - case_start + offset) % 26 + case_start) + true_offset = (ord(char) - case_start + offset) % 26 + + yield chr(case_start + true_offset) def conversion_func(text: str) -> str: """Encrypts the given string using the Caesar Cipher.""" -- cgit v1.2.3 From c7f6489453ccad4ec10bd316a641461ee8ca4c94 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 2 Jul 2020 19:31:44 +0800 Subject: Add 'enc'/'dec' aliases for encrypt/decrypt --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 5f5c3718..31dba936 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -151,7 +151,7 @@ class Fun(Cog): await ctx.send(content=converted_text, embed=embed) - @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift")) + @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift", "enc",)) async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ Given a positive integer `offset`, encrypt the given `msg`. @@ -165,7 +165,7 @@ class Fun(Cog): else: await self._caesar_cipher(ctx, offset, msg) - @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift")) + @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift", "dec",)) async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ Given a positive integer `offset`, decrypt the given `msg`. -- cgit v1.2.3 From 411db10969387fbb8e89f87c78a39dc580cc6498 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Wed, 15 Jul 2020 15:03:13 +0800 Subject: Refactor translation methods to avoid repetition --- bot/exts/evergreen/fun.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 31dba936..759a9e2a 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -111,15 +111,21 @@ class Fun(Cog): await ctx.send(embed=embed) @staticmethod - async def _caesar_cipher(ctx: Context, offset: int, msg: Union[Message, str]) -> None: + async def _caesar_cipher(ctx: Context, offset: int, msg: Union[Message, str], left_shift: bool = False) -> None: """ - Given an integer `offset`, translates and sends the given `msg`. + Given a positive integer `offset`, translates and sends the given `msg`. - A positive `offset` will cause the letters to shift right, while - a negative `offset` will cause the letters to shift left. + Performs a right shift by default unless `left_shift` is specified as `True`. Also accepts a valid Discord Message ID or link. """ + if offset < 0: + await ctx.send(":no_entry: Cannot use a negative offset.") + return + + if left_shift: + offset = -offset + def caesar_func(text: str) -> Iterable[str]: """Implements a lazy Caesar Cipher algorithm.""" for char in text: @@ -160,10 +166,7 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - if offset < 0: - await ctx.send(":no_entry: Cannot use a negative offset.") - else: - await self._caesar_cipher(ctx, offset, msg) + await self._caesar_cipher(ctx, offset, msg, False) @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift", "dec",)) async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: @@ -174,10 +177,7 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - if offset < 0: - await ctx.send(":no_entry: Cannot use a negative offset.") - else: - await self._caesar_cipher(ctx, -offset, msg) + await self._caesar_cipher(ctx, offset, msg, True) @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: -- cgit v1.2.3 From 86387796ca671a47d7f7a7740b63980e6d0346b6 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Wed, 29 Jul 2020 12:37:16 +0800 Subject: Explicitly pass left_shift as a keyword argument --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 759a9e2a..5a499270 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -166,7 +166,7 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - await self._caesar_cipher(ctx, offset, msg, False) + await self._caesar_cipher(ctx, offset, msg, left_shift=False) @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift", "dec",)) async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: @@ -177,7 +177,7 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - await self._caesar_cipher(ctx, offset, msg, True) + await self._caesar_cipher(ctx, offset, msg, left_shift=True) @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: -- cgit v1.2.3 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(-) 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 4d6e9f2b692939eccd8fed414f063f6bd3de858f Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sun, 9 Aug 2020 14:07:08 -0700 Subject: Added base file for python topics. With a couple suggestions for #python-general --- bot/resources/easter/py_topics.json | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 bot/resources/easter/py_topics.json diff --git a/bot/resources/easter/py_topics.json b/bot/resources/easter/py_topics.json new file mode 100644 index 00000000..d1035b7a --- /dev/null +++ b/bot/resources/easter/py_topics.json @@ -0,0 +1,58 @@ +{ + "python-channels": { + "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?" + ], + "630504881542791169": [ + + ], + "650401909852864553": [ + + ], + "342318764227821568": [ + + ], + "366673247892275221": [ + + ], + "343944376055103488": [ + + ], + "470884583684964352": [ + + ], + "660625198390837248": [ + + ], + "545603026732318730": [ + + ], + "716325106619777044": [ + + ], + "728390945384431688": [ + + ], + "366674035876167691": [ + + ], + "463035728335732738": [ + + ], + "463035462760792066": [ + + ], + "491523972836360192": [ + + ], + "338993628049571840": [ + + ], + "366673702533988363": [ + + ] + } +} -- cgit v1.2.3 From a932d631701eba93fe21a027ddd1521c9d65388e Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sun, 9 Aug 2020 15:22:28 -0700 Subject: Updated dependencies --- Pipfile.lock | 126 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/Pipfile.lock b/Pipfile.lock index c9ee97a1..c720a36d 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -44,11 +44,11 @@ }, "arrow": { "hashes": [ - "sha256:3f1a92b25bbee5f80cc8f6bdecfeade9028219229137c559c37335b4f574a292", - "sha256:61a1af3a31f731e7993509124839ac28b91b6743bd6692a949600737900cf43b" + "sha256:271b8e05174d48e50324ed0dc5d74796c839c7e579a4f21cf1a7394665f9e94f", + "sha256:edc31dc051db12c95da9bac0271cd1027b8e36912daf6d4580af53b23e62721a" ], "index": "pypi", - "version": "==0.15.7" + "version": "==0.15.8" }, "async-timeout": { "hashes": [ @@ -84,36 +84,36 @@ }, "cffi": { "hashes": [ - "sha256:001bf3242a1bb04d985d63e138230802c6c8d4db3668fb545fb5005ddf5bb5ff", - "sha256:00789914be39dffba161cfc5be31b55775de5ba2235fe49aa28c148236c4e06b", - "sha256:028a579fc9aed3af38f4892bdcc7390508adabc30c6af4a6e4f611b0c680e6ac", - "sha256:14491a910663bf9f13ddf2bc8f60562d6bc5315c1f09c704937ef17293fb85b0", - "sha256:1cae98a7054b5c9391eb3249b86e0e99ab1e02bb0cc0575da191aedadbdf4384", - "sha256:2089ed025da3919d2e75a4d963d008330c96751127dd6f73c8dc0c65041b4c26", - "sha256:2d384f4a127a15ba701207f7639d94106693b6cd64173d6c8988e2c25f3ac2b6", - "sha256:337d448e5a725bba2d8293c48d9353fc68d0e9e4088d62a9571def317797522b", - "sha256:399aed636c7d3749bbed55bc907c3288cb43c65c4389964ad5ff849b6370603e", - "sha256:3b911c2dbd4f423b4c4fcca138cadde747abdb20d196c4a48708b8a2d32b16dd", - "sha256:3d311bcc4a41408cf5854f06ef2c5cab88f9fded37a3b95936c9879c1640d4c2", - "sha256:62ae9af2d069ea2698bf536dcfe1e4eed9090211dbaafeeedf5cb6c41b352f66", - "sha256:66e41db66b47d0d8672d8ed2708ba91b2f2524ece3dee48b5dfb36be8c2f21dc", - "sha256:675686925a9fb403edba0114db74e741d8181683dcf216be697d208857e04ca8", - "sha256:7e63cbcf2429a8dbfe48dcc2322d5f2220b77b2e17b7ba023d6166d84655da55", - "sha256:8a6c688fefb4e1cd56feb6c511984a6c4f7ec7d2a1ff31a10254f3c817054ae4", - "sha256:8c0ffc886aea5df6a1762d0019e9cb05f825d0eec1f520c51be9d198701daee5", - "sha256:95cd16d3dee553f882540c1ffe331d085c9e629499ceadfbda4d4fde635f4b7d", - "sha256:99f748a7e71ff382613b4e1acc0ac83bf7ad167fb3802e35e90d9763daba4d78", - "sha256:b8c78301cefcf5fd914aad35d3c04c2b21ce8629b5e4f4e45ae6812e461910fa", - "sha256:c420917b188a5582a56d8b93bdd8e0f6eca08c84ff623a4c16e809152cd35793", - "sha256:c43866529f2f06fe0edc6246eb4faa34f03fe88b64a0a9a942561c8e22f4b71f", - "sha256:cab50b8c2250b46fe738c77dbd25ce017d5e6fb35d3407606e7a4180656a5a6a", - "sha256:cef128cb4d5e0b3493f058f10ce32365972c554572ff821e175dbc6f8ff6924f", - "sha256:cf16e3cf6c0a5fdd9bc10c21687e19d29ad1fe863372b5543deaec1039581a30", - "sha256:e56c744aa6ff427a607763346e4170629caf7e48ead6921745986db3692f987f", - "sha256:e577934fc5f8779c554639376beeaa5657d54349096ef24abe8c74c5d9c117c3", - "sha256:f2b0fa0c01d8a0c7483afd9f31d7ecf2d71760ca24499c8697aeb5ca37dc090c" - ], - "version": "==1.14.0" + "sha256:267adcf6e68d77ba154334a3e4fc921b8e63cbb38ca00d33d40655d4228502bc", + "sha256:26f33e8f6a70c255767e3c3f957ccafc7f1f706b966e110b855bfe944511f1f9", + "sha256:3cd2c044517f38d1b577f05927fb9729d3396f1d44d0c659a445599e79519792", + "sha256:4a03416915b82b81af5502459a8a9dd62a3c299b295dcdf470877cb948d655f2", + "sha256:4ce1e995aeecf7cc32380bc11598bfdfa017d592259d5da00fc7ded11e61d022", + "sha256:4f53e4128c81ca3212ff4cf097c797ab44646a40b42ec02a891155cd7a2ba4d8", + "sha256:4fa72a52a906425416f41738728268072d5acfd48cbe7796af07a923236bcf96", + "sha256:66dd45eb9530e3dde8f7c009f84568bc7cac489b93d04ac86e3111fb46e470c2", + "sha256:6923d077d9ae9e8bacbdb1c07ae78405a9306c8fd1af13bfa06ca891095eb995", + "sha256:833401b15de1bb92791d7b6fb353d4af60dc688eaa521bd97203dcd2d124a7c1", + "sha256:8416ed88ddc057bab0526d4e4e9f3660f614ac2394b5e019a628cdfff3733849", + "sha256:892daa86384994fdf4856cb43c93f40cbe80f7f95bb5da94971b39c7f54b3a9c", + "sha256:98be759efdb5e5fa161e46d404f4e0ce388e72fbf7d9baf010aff16689e22abe", + "sha256:a6d28e7f14ecf3b2ad67c4f106841218c8ab12a0683b1528534a6c87d2307af3", + "sha256:b1d6ebc891607e71fd9da71688fcf332a6630b7f5b7f5549e6e631821c0e5d90", + "sha256:b2a2b0d276a136146e012154baefaea2758ef1f56ae9f4e01c612b0831e0bd2f", + "sha256:b87dfa9f10a470eee7f24234a37d1d5f51e5f5fa9eeffda7c282e2b8f5162eb1", + "sha256:bac0d6f7728a9cc3c1e06d4fcbac12aaa70e9379b3025b27ec1226f0e2d404cf", + "sha256:c991112622baee0ae4d55c008380c32ecfd0ad417bcd0417ba432e6ba7328caa", + "sha256:cda422d54ee7905bfc53ee6915ab68fe7b230cacf581110df4272ee10462aadc", + "sha256:d3148b6ba3923c5850ea197a91a42683f946dba7e8eb82dfa211ab7e708de939", + "sha256:d6033b4ffa34ef70f0b8086fd4c3df4bf801fee485a8a7d4519399818351aa8e", + "sha256:ddff0b2bd7edcc8c82d1adde6dbbf5e60d57ce985402541cd2985c27f7bec2a0", + "sha256:e23cb7f1d8e0f93addf0cae3c5b6f00324cccb4a7949ee558d7b6ca973ab8ae9", + "sha256:effd2ba52cee4ceff1a77f20d2a9f9bf8d50353c854a282b8760ac15b9833168", + "sha256:f90c2267101010de42f7273c94a1f026e56cbc043f9330acd8a80e64300aba33", + "sha256:f960375e9823ae6a07072ff7f8a85954e5a6434f97869f50d0e41649a1c8144f", + "sha256:fcf32bf76dc25e30ed793145a57426064520890d7c02866eb93d3e4abe516948" + ], + "version": "==1.14.1" }, "chardet": { "hashes": [ @@ -285,11 +285,11 @@ }, "urllib3": { "hashes": [ - "sha256:3018294ebefce6572a474f0604c2021e33b3fd8006ecd11d62107a5d2a963527", - "sha256:88206b0eb87e6d677d424843ac5209e3fb9d0190d0ee169599165ec25e9d9115" + "sha256:91056c15fa70756691db97756772bb1eb9678fa585d9184f24534b100dc60f4a", + "sha256:e7983572181f5e1522d9c98453462384ee92a0be7fac5f1413a1e35c56cc0461" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", - "version": "==1.25.9" + "version": "==1.25.10" }, "websockets": { "hashes": [ @@ -321,26 +321,26 @@ }, "yarl": { "hashes": [ - "sha256:0c2ab325d33f1b824734b3ef51d4d54a54e0e7a23d13b86974507602334c2cce", - "sha256:0ca2f395591bbd85ddd50a82eb1fde9c1066fafe888c5c7cc1d810cf03fd3cc6", - "sha256:2098a4b4b9d75ee352807a95cdf5f10180db903bc5b7270715c6bbe2551f64ce", - "sha256:25e66e5e2007c7a39541ca13b559cd8ebc2ad8fe00ea94a2aad28a9b1e44e5ae", - "sha256:26d7c90cb04dee1665282a5d1a998defc1a9e012fdca0f33396f81508f49696d", - "sha256:308b98b0c8cd1dfef1a0311dc5e38ae8f9b58349226aa0533f15a16717ad702f", - "sha256:3ce3d4f7c6b69c4e4f0704b32eca8123b9c58ae91af740481aa57d7857b5e41b", - "sha256:58cd9c469eced558cd81aa3f484b2924e8897049e06889e8ff2510435b7ef74b", - "sha256:5b10eb0e7f044cf0b035112446b26a3a2946bca9d7d7edb5e54a2ad2f6652abb", - "sha256:6faa19d3824c21bcbfdfce5171e193c8b4ddafdf0ac3f129ccf0cdfcb083e462", - "sha256:944494be42fa630134bf907714d40207e646fd5a94423c90d5b514f7b0713fea", - "sha256:a161de7e50224e8e3de6e184707476b5a989037dcb24292b391a3d66ff158e70", - "sha256:a4844ebb2be14768f7994f2017f70aca39d658a96c786211be5ddbe1c68794c1", - "sha256:c2b509ac3d4b988ae8769901c66345425e361d518aecbe4acbfc2567e416626a", - "sha256:c9959d49a77b0e07559e579f38b2f3711c2b8716b8410b320bf9713013215a1b", - "sha256:d8cdee92bc930d8b09d8bd2043cedd544d9c8bd7436a77678dd602467a993080", - "sha256:e15199cdb423316e15f108f51249e44eb156ae5dba232cb73be555324a1d49c2" + "sha256:040b237f58ff7d800e6e0fd89c8439b841f777dd99b4a9cca04d6935564b9409", + "sha256:17668ec6722b1b7a3a05cc0167659f6c95b436d25a36c2d52db0eca7d3f72593", + "sha256:3a584b28086bc93c888a6c2aa5c92ed1ae20932f078c46509a66dce9ea5533f2", + "sha256:4439be27e4eee76c7632c2427ca5e73703151b22cae23e64adb243a9c2f565d8", + "sha256:48e918b05850fffb070a496d2b5f97fc31d15d94ca33d3d08a4f86e26d4e7c5d", + "sha256:9102b59e8337f9874638fcfc9ac3734a0cfadb100e47d55c20d0dc6087fb4692", + "sha256:9b930776c0ae0c691776f4d2891ebc5362af86f152dd0da463a6614074cb1b02", + "sha256:b3b9ad80f8b68519cc3372a6ca85ae02cc5a8807723ac366b53c0f089db19e4a", + "sha256:bc2f976c0e918659f723401c4f834deb8a8e7798a71be4382e024bcc3f7e23a8", + "sha256:c22c75b5f394f3d47105045ea551e08a3e804dc7e01b37800ca35b58f856c3d6", + "sha256:c52ce2883dc193824989a9b97a76ca86ecd1fa7955b14f87bf367a61b6232511", + "sha256:ce584af5de8830d8701b8979b18fcf450cef9a382b1a3c8ef189bedc408faf1e", + "sha256:da456eeec17fa8aa4594d9a9f27c0b1060b6a75f2419fe0c00609587b2695f4a", + "sha256:db6db0f45d2c63ddb1a9d18d1b9b22f308e52c83638c26b422d520a815c4b3fb", + "sha256:df89642981b94e7db5596818499c4b2219028f2a528c9c37cc1de45bf2fd3a3f", + "sha256:f18d68f2be6bf0e89f1521af2b1bb46e66ab0018faafa81d70f358153170a317", + "sha256:f379b7f83f23fe12823085cd6b906edc49df969eb99757f58ff382349a3303c6" ], "markers": "python_version >= '3.5'", - "version": "==1.4.2" + "version": "==1.5.1" } }, "develop": { @@ -361,11 +361,11 @@ }, "cfgv": { "hashes": [ - "sha256:1ccf53320421aeeb915275a196e23b3b8ae87dea8ac6698b1638001d4a486d53", - "sha256:c8e8f552ffcc6194f4e18dd4f68d9aef0c0d58ae7e7be8c82bee3c5e9edfa513" + "sha256:32e43d604bbe7896fe7c248a9c2276447dbef840feb28fe20494f62af110211d", + "sha256:cf22deb93d4bcf92f345a5c3cd39d3d41d6340adc60c78bbbd6588c384fda6a1" ], "markers": "python_full_version >= '3.6.1'", - "version": "==3.1.0" + "version": "==3.2.0" }, "distlib": { "hashes": [ @@ -453,11 +453,11 @@ }, "identify": { "hashes": [ - "sha256:882c4b08b4569517b5f2257ecca180e01f38400a17f429f5d0edff55530c41c7", - "sha256:f89add935982d5bc62913ceee16c9297d8ff14b226e9d3072383a4e38136b656" + "sha256:110ed090fec6bce1aabe3c72d9258a9de82207adeaa5a05cd75c635880312f9a", + "sha256:ccd88716b890ecbe10920659450a635d2d25de499b9a638525a48b48261d989b" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.4.23" + "version": "==1.4.25" }, "mccabe": { "hashes": [ @@ -552,11 +552,11 @@ }, "virtualenv": { "hashes": [ - "sha256:c11a475400e98450403c0364eb3a2d25d42f71cf1493da64390487b666de4324", - "sha256:e10cc66f40cbda459720dfe1d334c4dc15add0d80f09108224f171006a97a172" + "sha256:7b54fd606a1b85f83de49ad8d80dbec08e983a2d2f96685045b262ebc7481ee5", + "sha256:8cd7b2a4850b003a11be2fc213e206419efab41115cc14bca20e69654f2ac08e" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==20.0.26" + "version": "==20.0.30" } } } -- 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(-) 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 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 From 0bcbe43557b9566f265d894b28c7f47a96765196 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 10 Aug 2020 13:08:38 -0700 Subject: Linted. --- bot/exts/evergreen/conversationstarters.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index f4d1d3ce..54ed70c1 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -1,5 +1,4 @@ import json -import logging import random from pathlib import Path @@ -35,13 +34,13 @@ class ConvoStarters(commands.Cog): # If the channel isn't Python-related. except KeyError: - await ctx.send(random.choice(starters['starters'])) + await ctx.send(random.choice(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=( -- cgit v1.2.3 From 41f3d6fdbc2fc23f2d00a04392a00fc4736d801b Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 10 Aug 2020 13:48:46 -0700 Subject: Moved the resources to the correct folder for evergreen. --- bot/resources/easter/py_topics.json | 58 ---------------------------------- bot/resources/easter/starter.json | 24 -------------- bot/resources/evergreen/py_topics.json | 58 ++++++++++++++++++++++++++++++++++ bot/resources/evergreen/starter.json | 24 ++++++++++++++ 4 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 bot/resources/easter/py_topics.json delete mode 100644 bot/resources/easter/starter.json create mode 100644 bot/resources/evergreen/py_topics.json create mode 100644 bot/resources/evergreen/starter.json diff --git a/bot/resources/easter/py_topics.json b/bot/resources/easter/py_topics.json deleted file mode 100644 index d1035b7a..00000000 --- a/bot/resources/easter/py_topics.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "python-channels": { - "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?" - ], - "630504881542791169": [ - - ], - "650401909852864553": [ - - ], - "342318764227821568": [ - - ], - "366673247892275221": [ - - ], - "343944376055103488": [ - - ], - "470884583684964352": [ - - ], - "660625198390837248": [ - - ], - "545603026732318730": [ - - ], - "716325106619777044": [ - - ], - "728390945384431688": [ - - ], - "366674035876167691": [ - - ], - "463035728335732738": [ - - ], - "463035462760792066": [ - - ], - "491523972836360192": [ - - ], - "338993628049571840": [ - - ], - "366673702533988363": [ - - ] - } -} diff --git a/bot/resources/easter/starter.json b/bot/resources/easter/starter.json deleted file mode 100644 index 31e2cbc9..00000000 --- a/bot/resources/easter/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/py_topics.json b/bot/resources/evergreen/py_topics.json new file mode 100644 index 00000000..d1035b7a --- /dev/null +++ b/bot/resources/evergreen/py_topics.json @@ -0,0 +1,58 @@ +{ + "python-channels": { + "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?" + ], + "630504881542791169": [ + + ], + "650401909852864553": [ + + ], + "342318764227821568": [ + + ], + "366673247892275221": [ + + ], + "343944376055103488": [ + + ], + "470884583684964352": [ + + ], + "660625198390837248": [ + + ], + "545603026732318730": [ + + ], + "716325106619777044": [ + + ], + "728390945384431688": [ + + ], + "366674035876167691": [ + + ], + "463035728335732738": [ + + ], + "463035462760792066": [ + + ], + "491523972836360192": [ + + ], + "338993628049571840": [ + + ], + "366673702533988363": [ + + ] + } +} diff --git a/bot/resources/evergreen/starter.json b/bot/resources/evergreen/starter.json new file mode 100644 index 00000000..31e2cbc9 --- /dev/null +++ b/bot/resources/evergreen/starter.json @@ -0,0 +1,24 @@ +{ + "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?" + ] +} -- cgit v1.2.3 From 3317f00e7dcd7fee1bda79fd5b82f2d9fbd2e1cc Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 10 Aug 2020 13:50:10 -0700 Subject: Finalized whitelist for allowed channels .topic can be used in. Changed resource path to evergreen, added WHITELISTED_CHANNELS to PY_TOPICS channels. --- bot/exts/evergreen/conversationstarters.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index 54ed70c1..4df3f068 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -6,28 +6,36 @@ from discord import Embed from discord.ext import commands from bot.utils.decorators import override_in_channel +from bot.constants import WHITELISTED_CHANNELS -with Path("bot/resources/easter/starter.json").open("r", encoding="utf8") as f: +with Path("bot/resources/evergreen/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: +with Path("bot/resources/evergreen/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()] + + # All the allowed channels that the ".topic" command is allowed to be executed in. + ALL_ALLOWED_CHANNELS = [int(channel_id) for channel_id in PY_TOPICS.keys()].extend(WHITELISTED_CHANNELS) class ConvoStarters(commands.Cog): - """Easter conversation topics.""" + """Evergreen conversation topics.""" def __init__(self, bot: commands.Bot): self.bot = bot @commands.command() - @override_in_channel(ALL_PYTHON_CHANNELS) + @override_in_channel(ALL_ALLOWED_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 + + If in a Python channel, a python-related topic will be given. + + Otherwise, a random conversation topic will be recieved by the user. + """ try: # Fetching topics. channel_topics = PY_TOPICS[str(ctx.channel.id)] -- cgit v1.2.3 From 77cafe8a048bfaca2b1defcedb55761acfd6f5fc Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 10 Aug 2020 13:51:51 -0700 Subject: Linted. --- bot/exts/evergreen/conversationstarters.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index 4df3f068..974a361e 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -5,8 +5,8 @@ from pathlib import Path from discord import Embed from discord.ext import commands -from bot.utils.decorators import override_in_channel from bot.constants import WHITELISTED_CHANNELS +from bot.utils.decorators import override_in_channel with Path("bot/resources/evergreen/starter.json").open("r", encoding="utf8") as f: @@ -30,8 +30,9 @@ class ConvoStarters(commands.Cog): @commands.command() @override_in_channel(ALL_ALLOWED_CHANNELS) 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. + If in a Python channel, a python-related topic will be given. Otherwise, a random conversation topic will be recieved by the user. -- cgit v1.2.3 From 141e82af3b5506135a60de8608ec96cc11739097 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 10 Aug 2020 14:18:42 -0700 Subject: ALL_ALLOWED_CHANNELS now is a list of channel IDs instead of None. --- bot/exts/evergreen/conversationstarters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index 974a361e..8a07eea2 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -18,7 +18,7 @@ with Path("bot/resources/evergreen/py_topics.json").open("r", encoding="utf8") a PY_TOPICS = json.load(f)["python-channels"] # All the allowed channels that the ".topic" command is allowed to be executed in. - ALL_ALLOWED_CHANNELS = [int(channel_id) for channel_id in PY_TOPICS.keys()].extend(WHITELISTED_CHANNELS) + ALL_ALLOWED_CHANNELS = [int(channel_id) for channel_id in PY_TOPICS.keys()] + list(WHITELISTED_CHANNELS) class ConvoStarters(commands.Cog): -- cgit v1.2.3 From df51b8c11a3a42ae13dd00d8b994d5f1d70638e7 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 10 Aug 2020 14:31:11 -0700 Subject: Gave the Embed the burple color. --- bot/exts/evergreen/conversationstarters.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index 8a07eea2..179fe478 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -2,7 +2,7 @@ import json import random from pathlib import Path -from discord import Embed +from discord import Color, Embed from discord.ext import commands from bot.constants import WHITELISTED_CHANNELS @@ -55,7 +55,9 @@ class ConvoStarters(commands.Cog): 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) -- cgit v1.2.3 From 1c50a8180809561413ef5cfe73fc0fbc770f8fdc Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Mon, 10 Aug 2020 14:43:53 -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(-) diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index 179fe478..757ec059 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -56,7 +56,7 @@ class ConvoStarters(commands.Cog): "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 + color=Color.blurple() ) await ctx.send(embed=embed) -- cgit v1.2.3 From f489a87f7f1d66983b1e495427883837c57332fe Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 17 Aug 2020 03:16:10 -0700 Subject: Changed from json to yaml config so comments can be included. --- bot/resources/evergreen/py_topics.json | 58 --------------------------- bot/resources/evergreen/py_topics.yaml | 73 ++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 58 deletions(-) delete mode 100644 bot/resources/evergreen/py_topics.json create mode 100644 bot/resources/evergreen/py_topics.yaml diff --git a/bot/resources/evergreen/py_topics.json b/bot/resources/evergreen/py_topics.json deleted file mode 100644 index d1035b7a..00000000 --- a/bot/resources/evergreen/py_topics.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "python-channels": { - "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?" - ], - "630504881542791169": [ - - ], - "650401909852864553": [ - - ], - "342318764227821568": [ - - ], - "366673247892275221": [ - - ], - "343944376055103488": [ - - ], - "470884583684964352": [ - - ], - "660625198390837248": [ - - ], - "545603026732318730": [ - - ], - "716325106619777044": [ - - ], - "728390945384431688": [ - - ], - "366674035876167691": [ - - ], - "463035728335732738": [ - - ], - "463035462760792066": [ - - ], - "491523972836360192": [ - - ], - "338993628049571840": [ - - ], - "366673702533988363": [ - - ] - } -} diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml new file mode 100644 index 00000000..f67ce4d6 --- /dev/null +++ b/bot/resources/evergreen/py_topics.yaml @@ -0,0 +1,73 @@ +# Conversation starters for python-related channels. + +# python-general +# 267624335836053506: +476190141161930755: + - 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? + +# async +630504881542791169: + - + +# computer-science +650401909852864553: + - + +# databases +342318764227821568: + - + +# data-science +366673247892275221: + - + +# discord.py +343944376055103488: + - + +# esoteric-python +470884583684964352: + - + +# game-development +660625198390837248: + - + +# microcontrollers +545603026732318730: + - + +# networking +716325106619777044: + - + +# python-extensions +728390945384431688: + - + +# security +366674035876167691: + - + +# software-testing +463035728335732738: + - + +# tools-and-devops +463035462760792066: + - + +# unix +491523972836360192: + - + +# user-interfaces +338993628049571840: + - + +# web-development +366673702533988363: + - -- cgit v1.2.3 From 1075d3c6355c70cdbc27135e2da53fd1e234d8a0 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 17 Aug 2020 03:16:43 -0700 Subject: Updated dependencies to include yaml config parser. --- Pipfile | 1 + Pipfile.lock | 86 ++++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 53 insertions(+), 34 deletions(-) diff --git a/Pipfile b/Pipfile index b4fc1dc6..38044a0a 100644 --- a/Pipfile +++ b/Pipfile @@ -12,6 +12,7 @@ fuzzywuzzy = "~=0.17" pillow = "~=6.2" pytz = "~=2019.2" sentry-sdk = "~=0.14.2" +PyYAML = "~=5.3.1" [dev-packages] flake8 = "~=3.8" diff --git a/Pipfile.lock b/Pipfile.lock index c720a36d..74931967 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "608dbc82dfdab7596c3e1eb18e05f90d596230b29af25c7e7a2c351196a6d045" + "sha256": "dfd24795dcdab1a05fd774b5034b195b69d6d6ed52fd6810db9c89247f8e0a43" }, "pipfile-spec": 6, "requires": { @@ -84,36 +84,36 @@ }, "cffi": { "hashes": [ - "sha256:267adcf6e68d77ba154334a3e4fc921b8e63cbb38ca00d33d40655d4228502bc", - "sha256:26f33e8f6a70c255767e3c3f957ccafc7f1f706b966e110b855bfe944511f1f9", - "sha256:3cd2c044517f38d1b577f05927fb9729d3396f1d44d0c659a445599e79519792", - "sha256:4a03416915b82b81af5502459a8a9dd62a3c299b295dcdf470877cb948d655f2", - "sha256:4ce1e995aeecf7cc32380bc11598bfdfa017d592259d5da00fc7ded11e61d022", - "sha256:4f53e4128c81ca3212ff4cf097c797ab44646a40b42ec02a891155cd7a2ba4d8", - "sha256:4fa72a52a906425416f41738728268072d5acfd48cbe7796af07a923236bcf96", - "sha256:66dd45eb9530e3dde8f7c009f84568bc7cac489b93d04ac86e3111fb46e470c2", - "sha256:6923d077d9ae9e8bacbdb1c07ae78405a9306c8fd1af13bfa06ca891095eb995", - "sha256:833401b15de1bb92791d7b6fb353d4af60dc688eaa521bd97203dcd2d124a7c1", - "sha256:8416ed88ddc057bab0526d4e4e9f3660f614ac2394b5e019a628cdfff3733849", - "sha256:892daa86384994fdf4856cb43c93f40cbe80f7f95bb5da94971b39c7f54b3a9c", - "sha256:98be759efdb5e5fa161e46d404f4e0ce388e72fbf7d9baf010aff16689e22abe", - "sha256:a6d28e7f14ecf3b2ad67c4f106841218c8ab12a0683b1528534a6c87d2307af3", - "sha256:b1d6ebc891607e71fd9da71688fcf332a6630b7f5b7f5549e6e631821c0e5d90", - "sha256:b2a2b0d276a136146e012154baefaea2758ef1f56ae9f4e01c612b0831e0bd2f", - "sha256:b87dfa9f10a470eee7f24234a37d1d5f51e5f5fa9eeffda7c282e2b8f5162eb1", - "sha256:bac0d6f7728a9cc3c1e06d4fcbac12aaa70e9379b3025b27ec1226f0e2d404cf", - "sha256:c991112622baee0ae4d55c008380c32ecfd0ad417bcd0417ba432e6ba7328caa", - "sha256:cda422d54ee7905bfc53ee6915ab68fe7b230cacf581110df4272ee10462aadc", - "sha256:d3148b6ba3923c5850ea197a91a42683f946dba7e8eb82dfa211ab7e708de939", - "sha256:d6033b4ffa34ef70f0b8086fd4c3df4bf801fee485a8a7d4519399818351aa8e", - "sha256:ddff0b2bd7edcc8c82d1adde6dbbf5e60d57ce985402541cd2985c27f7bec2a0", - "sha256:e23cb7f1d8e0f93addf0cae3c5b6f00324cccb4a7949ee558d7b6ca973ab8ae9", - "sha256:effd2ba52cee4ceff1a77f20d2a9f9bf8d50353c854a282b8760ac15b9833168", - "sha256:f90c2267101010de42f7273c94a1f026e56cbc043f9330acd8a80e64300aba33", - "sha256:f960375e9823ae6a07072ff7f8a85954e5a6434f97869f50d0e41649a1c8144f", - "sha256:fcf32bf76dc25e30ed793145a57426064520890d7c02866eb93d3e4abe516948" - ], - "version": "==1.14.1" + "sha256:0da50dcbccd7cb7e6c741ab7912b2eff48e85af217d72b57f80ebc616257125e", + "sha256:12a453e03124069b6896107ee133ae3ab04c624bb10683e1ed1c1663df17c13c", + "sha256:15419020b0e812b40d96ec9d369b2bc8109cc3295eac6e013d3261343580cc7e", + "sha256:15a5f59a4808f82d8ec7364cbace851df591c2d43bc76bcbe5c4543a7ddd1bf1", + "sha256:23e44937d7695c27c66a54d793dd4b45889a81b35c0751ba91040fe825ec59c4", + "sha256:29c4688ace466a365b85a51dcc5e3c853c1d283f293dfcc12f7a77e498f160d2", + "sha256:57214fa5430399dffd54f4be37b56fe22cedb2b98862550d43cc085fb698dc2c", + "sha256:577791f948d34d569acb2d1add5831731c59d5a0c50a6d9f629ae1cefd9ca4a0", + "sha256:6539314d84c4d36f28d73adc1b45e9f4ee2a89cdc7e5d2b0a6dbacba31906798", + "sha256:65867d63f0fd1b500fa343d7798fa64e9e681b594e0a07dc934c13e76ee28fb1", + "sha256:672b539db20fef6b03d6f7a14b5825d57c98e4026401fce838849f8de73fe4d4", + "sha256:6843db0343e12e3f52cc58430ad559d850a53684f5b352540ca3f1bc56df0731", + "sha256:7057613efefd36cacabbdbcef010e0a9c20a88fc07eb3e616019ea1692fa5df4", + "sha256:76ada88d62eb24de7051c5157a1a78fd853cca9b91c0713c2e973e4196271d0c", + "sha256:837398c2ec00228679513802e3744d1e8e3cb1204aa6ad408b6aff081e99a487", + "sha256:8662aabfeab00cea149a3d1c2999b0731e70c6b5bac596d95d13f643e76d3d4e", + "sha256:95e9094162fa712f18b4f60896e34b621df99147c2cee216cfa8f022294e8e9f", + "sha256:99cc66b33c418cd579c0f03b77b94263c305c389cb0c6972dac420f24b3bf123", + "sha256:9b219511d8b64d3fa14261963933be34028ea0e57455baf6781fe399c2c3206c", + "sha256:ae8f34d50af2c2154035984b8b5fc5d9ed63f32fe615646ab435b05b132ca91b", + "sha256:b9aa9d8818c2e917fa2c105ad538e222a5bce59777133840b93134022a7ce650", + "sha256:bf44a9a0141a082e89c90e8d785b212a872db793a0080c20f6ae6e2a0ebf82ad", + "sha256:c0b48b98d79cf795b0916c57bebbc6d16bb43b9fc9b8c9f57f4cf05881904c75", + "sha256:da9d3c506f43e220336433dffe643fbfa40096d408cb9b7f2477892f369d5f82", + "sha256:e4082d832e36e7f9b2278bc774886ca8207346b99f278e54c9de4834f17232f7", + "sha256:e4b9b7af398c32e408c00eb4e0d33ced2f9121fd9fb978e6c1b57edd014a7d15", + "sha256:e613514a82539fc48291d01933951a13ae93b6b444a88782480be32245ed4afa", + "sha256:f5033952def24172e60493b68717792e3aebb387a8d186c43c020d9363ee7281" + ], + "version": "==1.14.2" }, "chardet": { "hashes": [ @@ -259,6 +259,23 @@ "index": "pypi", "version": "==2019.3" }, + "pyyaml": { + "hashes": [ + "sha256:06a0d7ba600ce0b2d2fe2e78453a470b5a6e000a985dd4a4e54e436cc36b0e97", + "sha256:240097ff019d7c70a4922b6869d8a86407758333f02203e0fc6ff79c5dcede76", + "sha256:4f4b913ca1a7319b33cfb1369e91e50354d6f07a135f3b901aca02aa95940bd2", + "sha256:69f00dca373f240f842b2931fb2c7e14ddbacd1397d57157a9b005a6a9942648", + "sha256:73f099454b799e05e5ab51423c7bcf361c58d3206fa7b0d555426b1f4d9a3eaf", + "sha256:74809a57b329d6cc0fdccee6318f44b9b8649961fa73144a98735b0aaf029f1f", + "sha256:7739fc0fa8205b3ee8808aea45e968bc90082c10aef6ea95e855e10abf4a37b2", + "sha256:95f71d2af0ff4227885f7a6605c37fd53d3a106fcab511b8860ecca9fcf400ee", + "sha256:b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d", + "sha256:cc8955cfbfc7a115fa81d85284ee61147059a753344bc51098f3ccd69b0d7e0c", + "sha256:d13155f591e6fcc1ec3b30685d50bf0711574e2c0dfffd7644babf8b5102ca1a" + ], + "index": "pypi", + "version": "==5.3.1" + }, "sentry-sdk": { "hashes": [ "sha256:0e5e947d0f7a969314aa23669a94a9712be5a688ff069ff7b9fc36c66adc160c", @@ -453,11 +470,11 @@ }, "identify": { "hashes": [ - "sha256:110ed090fec6bce1aabe3c72d9258a9de82207adeaa5a05cd75c635880312f9a", - "sha256:ccd88716b890ecbe10920659450a635d2d25de499b9a638525a48b48261d989b" + "sha256:69c4769f085badafd0e04b1763e847258cbbf6d898e8678ebffc91abdb86f6c6", + "sha256:d6ae6daee50ba1b493e9ca4d36a5edd55905d2cf43548fdc20b2a14edef102e7" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.4.25" + "version": "==1.4.28" }, "mccabe": { "hashes": [ @@ -526,6 +543,7 @@ "sha256:cc8955cfbfc7a115fa81d85284ee61147059a753344bc51098f3ccd69b0d7e0c", "sha256:d13155f591e6fcc1ec3b30685d50bf0711574e2c0dfffd7644babf8b5102ca1a" ], + "index": "pypi", "version": "==5.3.1" }, "six": { -- cgit v1.2.3 From b7779d9af8aaf207252a6adb8a6f2214f6c2ed16 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 17 Aug 2020 03:18:15 -0700 Subject: Changed from json to yaml extraction of channel topics. --- bot/exts/evergreen/conversationstarters.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index 757ec059..c559c2f8 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -1,4 +1,5 @@ import json +import yaml import random from pathlib import Path @@ -13,12 +14,15 @@ with Path("bot/resources/evergreen/starter.json").open("r", encoding="utf8") as STARTERS = json.load(f)["starters"] -with Path("bot/resources/evergreen/py_topics.json").open("r", encoding="utf8") as f: +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. - PY_TOPICS = json.load(f)["python-channels"] + PY_TOPICS = yaml.load(f, Loader=yaml.FullLoader) + + # Removing `None` from lists of topics, if not a list, it is changed to an empty one. + 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 = [int(channel_id) for channel_id in PY_TOPICS.keys()] + list(WHITELISTED_CHANNELS) + ALL_ALLOWED_CHANNELS = [channel_id for channel_id in PY_TOPICS.keys()] + list(WHITELISTED_CHANNELS) class ConvoStarters(commands.Cog): @@ -39,7 +43,7 @@ class ConvoStarters(commands.Cog): """ try: # Fetching topics. - channel_topics = PY_TOPICS[str(ctx.channel.id)] + channel_topics = PY_TOPICS[ctx.channel.id] # If the channel isn't Python-related. except KeyError: -- cgit v1.2.3 From 3f3f713da2f72b54e095bbc2d5a39198b45ee6f8 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 17 Aug 2020 03:16:10 -0700 Subject: Revert "Changed from json to yaml config so comments can be included." This reverts commit f489a87f7f1d66983b1e495427883837c57332fe. --- bot/resources/evergreen/py_topics.json | 58 +++++++++++++++++++++++++++ bot/resources/evergreen/py_topics.yaml | 73 ---------------------------------- 2 files changed, 58 insertions(+), 73 deletions(-) create mode 100644 bot/resources/evergreen/py_topics.json delete mode 100644 bot/resources/evergreen/py_topics.yaml diff --git a/bot/resources/evergreen/py_topics.json b/bot/resources/evergreen/py_topics.json new file mode 100644 index 00000000..d1035b7a --- /dev/null +++ b/bot/resources/evergreen/py_topics.json @@ -0,0 +1,58 @@ +{ + "python-channels": { + "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?" + ], + "630504881542791169": [ + + ], + "650401909852864553": [ + + ], + "342318764227821568": [ + + ], + "366673247892275221": [ + + ], + "343944376055103488": [ + + ], + "470884583684964352": [ + + ], + "660625198390837248": [ + + ], + "545603026732318730": [ + + ], + "716325106619777044": [ + + ], + "728390945384431688": [ + + ], + "366674035876167691": [ + + ], + "463035728335732738": [ + + ], + "463035462760792066": [ + + ], + "491523972836360192": [ + + ], + "338993628049571840": [ + + ], + "366673702533988363": [ + + ] + } +} diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml deleted file mode 100644 index f67ce4d6..00000000 --- a/bot/resources/evergreen/py_topics.yaml +++ /dev/null @@ -1,73 +0,0 @@ -# Conversation starters for python-related channels. - -# python-general -# 267624335836053506: -476190141161930755: - - 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? - -# async -630504881542791169: - - - -# computer-science -650401909852864553: - - - -# databases -342318764227821568: - - - -# data-science -366673247892275221: - - - -# discord.py -343944376055103488: - - - -# esoteric-python -470884583684964352: - - - -# game-development -660625198390837248: - - - -# microcontrollers -545603026732318730: - - - -# networking -716325106619777044: - - - -# python-extensions -728390945384431688: - - - -# security -366674035876167691: - - - -# software-testing -463035728335732738: - - - -# tools-and-devops -463035462760792066: - - - -# unix -491523972836360192: - - - -# user-interfaces -338993628049571840: - - - -# web-development -366673702533988363: - - -- cgit v1.2.3 From 9c994c23f946f13202eb791d42cc22fdaa60912c Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 17 Aug 2020 03:21:55 -0700 Subject: Auto stash before revert of "Changed from json to yaml config so comments can be included." --- bot/resources/evergreen/py_topics.yaml | 72 ++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 bot/resources/evergreen/py_topics.yaml diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml new file mode 100644 index 00000000..49cf38b5 --- /dev/null +++ b/bot/resources/evergreen/py_topics.yaml @@ -0,0 +1,72 @@ +# Conversation starters for python-related channels. + +# 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? + +# async +630504881542791169: + - + +# computer-science +650401909852864553: + - + +# databases +342318764227821568: + - + +# data-science +366673247892275221: + - + +# discord.py +343944376055103488: + - + +# esoteric-python +470884583684964352: + - + +# game-development +660625198390837248: + - + +# microcontrollers +545603026732318730: + - + +# networking +716325106619777044: + - + +# python-extensions +728390945384431688: + - + +# security +366674035876167691: + - + +# software-testing +463035728335732738: + - + +# tools-and-devops +463035462760792066: + - + +# unix +491523972836360192: + - + +# user-interfaces +338993628049571840: + - + +# web-development +366673702533988363: + - -- cgit v1.2.3 From 809a4458e418d15288749c69b061990b6b737716 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Mon, 17 Aug 2020 03:36:57 -0700 Subject: Sorted imports to comply with flake8 standards. --- bot/exts/evergreen/conversationstarters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/evergreen/conversationstarters.py index c559c2f8..cfa8dbce 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/evergreen/conversationstarters.py @@ -1,8 +1,8 @@ import json -import yaml import random from pathlib import Path +import yaml from discord import Color, Embed from discord.ext import commands -- cgit v1.2.3 From 2cde858674fa6b4828f1a91028a62fb986c874f0 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Thu, 20 Aug 2020 22:38:34 +0100 Subject: Temporarily remove message functionality from Fun Remove message link functionality from uwu and randomcase due to a security vulnerability --- bot/exts/evergreen/fun.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 67a4bae5..b2c0aad9 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -49,8 +49,6 @@ class Fun(Cog): async def uwu_command(self, ctx: Context, *, text: str) -> None: """ Converts a given `text` into it's uwu equivalent. - - Also accepts a valid discord Message ID or link. """ conversion_func = functools.partial( utils.replace_many, replacements=UWU_WORDS, ignore_case=True, match_case=True @@ -69,8 +67,6 @@ class Fun(Cog): async def randomcase_command(self, ctx: Context, *, text: str) -> None: """ Randomly converts the casing of a given `text`. - - Also accepts a valid discord Message ID or link. """ def conversion_func(text: str) -> str: """Randomly converts the casing of a given string.""" @@ -97,12 +93,14 @@ class Fun(Cog): Union[Embed, None]: The embed if found in the valid Message, else None """ embed = None - message = await Fun._get_discord_message(ctx, text) - if isinstance(message, Message): - text = message.content - # Take first embed because we can't send multiple embeds - if message.embeds: - embed = message.embeds[0] + + # message = await Fun._get_discord_message(ctx, text) + # if isinstance(message, Message): + # text = message.content + # # Take first embed because we can't send multiple embeds + # if message.embeds: + # embed = message.embeds[0] + return (text, embed) @staticmethod -- cgit v1.2.3 From 09553df414dc225d2857c100a8cf02eaeeca4d47 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Thu, 20 Aug 2020 22:45:56 +0100 Subject: Update fun.py to satisfy the linter --- bot/exts/evergreen/fun.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index b2c0aad9..0a5d22f9 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -47,9 +47,7 @@ class Fun(Cog): @commands.command(name="uwu", aliases=("uwuwize", "uwuify",)) async def uwu_command(self, ctx: Context, *, text: str) -> None: - """ - Converts a given `text` into it's uwu equivalent. - """ + """Converts a given `text` into it's uwu equivalent.""" conversion_func = functools.partial( utils.replace_many, replacements=UWU_WORDS, ignore_case=True, match_case=True ) @@ -65,9 +63,7 @@ class Fun(Cog): @commands.command(name="randomcase", aliases=("rcase", "randomcaps", "rcaps",)) async def randomcase_command(self, ctx: Context, *, text: str) -> None: - """ - Randomly converts the casing of a given `text`. - """ + """Randomly converts the casing of a given `text`.""" def conversion_func(text: str) -> str: """Randomly converts the casing of a given string.""" return "".join( -- cgit v1.2.3 From e0caf6787d862ba605a734fdf9b9363cdf100b85 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Thu, 20 Aug 2020 22:49:36 +0100 Subject: Remove whitespace from fun.py --- bot/exts/evergreen/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 0a5d22f9..36a13ac0 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -89,7 +89,7 @@ class Fun(Cog): Union[Embed, None]: The embed if found in the valid Message, else None """ embed = None - + # message = await Fun._get_discord_message(ctx, text) # if isinstance(message, Message): # text = message.content -- cgit v1.2.3 From cb2eca7c5d4120006712fe2d7cf35988c6f8e024 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Fri, 21 Aug 2020 18:33:44 -0700 Subject: Added topics to py_topics.yaml, removed the json form of this file. --- bot/resources/evergreen/py_topics.json | 58 ---------------------------------- bot/resources/evergreen/py_topics.yaml | 21 +++++++++--- 2 files changed, 16 insertions(+), 63 deletions(-) delete mode 100644 bot/resources/evergreen/py_topics.json diff --git a/bot/resources/evergreen/py_topics.json b/bot/resources/evergreen/py_topics.json deleted file mode 100644 index d1035b7a..00000000 --- a/bot/resources/evergreen/py_topics.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "python-channels": { - "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?" - ], - "630504881542791169": [ - - ], - "650401909852864553": [ - - ], - "342318764227821568": [ - - ], - "366673247892275221": [ - - ], - "343944376055103488": [ - - ], - "470884583684964352": [ - - ], - "660625198390837248": [ - - ], - "545603026732318730": [ - - ], - "716325106619777044": [ - - ], - "728390945384431688": [ - - ], - "366674035876167691": [ - - ], - "463035728335732738": [ - - ], - "463035462760792066": [ - - ], - "491523972836360192": [ - - ], - "338993628049571840": [ - - ], - "366673702533988363": [ - - ] - } -} diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml index 49cf38b5..5a2e8d89 100644 --- a/bot/resources/evergreen/py_topics.yaml +++ b/bot/resources/evergreen/py_topics.yaml @@ -6,10 +6,16 @@ - 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? + - 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? # async 630504881542791169: - - + - Are there any frameworks you wish were async? # computer-science 650401909852864553: @@ -17,7 +23,7 @@ # databases 342318764227821568: - - + - Where do you get your best data? # data-science 366673247892275221: @@ -25,11 +31,15 @@ # discord.py 343944376055103488: - - + - What unique features does your bot contain, if any? + - What commands/features are you proud of making? + - What feature would you be the most interested in making? + - 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 470884583684964352: - - + - What's a common part of programming we can make harder? # game-development 660625198390837248: @@ -57,7 +67,8 @@ # tools-and-devops 463035462760792066: - - + - What editor would you recommend to a beginner? Why? + - What editor would you recommend to be the most efficient? Why? # unix 491523972836360192: -- cgit v1.2.3 From c25dbfc87e7822bf14cf9b34eb7602dc511d6a68 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sun, 23 Aug 2020 06:20:30 -0700 Subject: Added one more topic to #async. --- bot/resources/evergreen/py_topics.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/resources/evergreen/py_topics.yaml b/bot/resources/evergreen/py_topics.yaml index 5a2e8d89..ae5289a7 100644 --- a/bot/resources/evergreen/py_topics.yaml +++ b/bot/resources/evergreen/py_topics.yaml @@ -16,6 +16,7 @@ # async 630504881542791169: - Are there any frameworks you wish were async? + - How have coroutines changed the way you write Python? # computer-science 650401909852864553: -- cgit v1.2.3 From d6f91f87cccfa558e948f8c8bd7aa3870e056bd2 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 29 Aug 2020 00:48:51 -0700 Subject: Updated constants to include Wolfram configuration. --- bot/constants.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bot/constants.py b/bot/constants.py index bf6c5a40..4a97b9e0 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -17,6 +17,7 @@ __all__ = ( "Month", "Roles", "Tokens", + "Wolfram", "MODERATION_ROLES", "STAFF_ROLES", "WHITELISTED_CHANNELS", @@ -96,6 +97,7 @@ class Colours: soft_red = 0xcd6d6d yellow = 0xf9f586 purple = 0xb734eb + soft_orange = 0xf9cb54 class Emojis: @@ -187,6 +189,12 @@ class Tokens(NamedTuple): github = environ.get("GITHUB_TOKEN") +class Wolfram(NamedTuple): + user_limit_day = environ.get("WOLFRAM_USER_LIMIT_DAY", 10) + guild_limit_day = environ.get("WOLFRAM_GUILD_LIMIT_DAY", 67) + key = environ.get("WOLFRAM_API_KEY", None) + + # Default role combinations MODERATION_ROLES = Roles.moderator, Roles.admin, Roles.owner STAFF_ROLES = Roles.helpers, Roles.moderator, Roles.admin, Roles.owner -- cgit v1.2.3 From c373d4c8cfd1105ea590553a02c208511fc16bb8 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 29 Aug 2020 00:51:00 -0700 Subject: Migrated Wolfram cog from the Python bot in Python-Discord/bot. --- bot/exts/evergreen/wolfram.py | 280 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100644 bot/exts/evergreen/wolfram.py diff --git a/bot/exts/evergreen/wolfram.py b/bot/exts/evergreen/wolfram.py new file mode 100644 index 00000000..18ccc4e5 --- /dev/null +++ b/bot/exts/evergreen/wolfram.py @@ -0,0 +1,280 @@ +import logging +from io import BytesIO +from typing import Callable, List, Optional, Tuple +from urllib import parse + +import discord +from dateutil.relativedelta import relativedelta +from discord import Embed +from discord.ext import commands +from discord.ext.commands import BucketType, Cog, Context, check, group + +from bot.constants import Colours, STAFF_ROLES, Wolfram +from bot.utils.pagination import ImagePaginator +from bot.utils.time import humanize_delta + +log = logging.getLogger(__name__) + +APPID = Wolfram.key +DEFAULT_OUTPUT_FORMAT = "JSON" +QUERY = "http://api.wolframalpha.com/v2/{request}?{data}" +WOLF_IMAGE = "https://www.symbols.com/gi.php?type=1&id=2886&i=1" + +MAX_PODS = 20 + +# Allows for 10 wolfram calls pr user pr day +usercd = commands.CooldownMapping.from_cooldown(Wolfram.user_limit_day, 60 * 60 * 24, BucketType.user) + +# Allows for max api requests / days in month per day for the entire guild (Temporary) +guildcd = commands.CooldownMapping.from_cooldown(Wolfram.guild_limit_day, 60 * 60 * 24, BucketType.guild) + + +async def send_embed( + ctx: Context, + message_txt: str, + colour: int = Colours.soft_red, + footer: str = None, + img_url: str = None, + f: discord.File = None +) -> None: + """Generate & send a response embed with Wolfram as the author.""" + embed = Embed(colour=colour) + embed.description = message_txt + embed.set_author(name="Wolfram Alpha", + icon_url=WOLF_IMAGE, + url="https://www.wolframalpha.com/") + if footer: + embed.set_footer(text=footer) + + if img_url: + embed.set_image(url=img_url) + + await ctx.send(embed=embed, file=f) + + +def custom_cooldown(*ignore: List[int]) -> Callable: + """ + Implement per-user and per-guild cooldowns for requests to the Wolfram API. + + A list of roles may be provided to ignore the per-user cooldown + """ + async def predicate(ctx: Context) -> bool: + if ctx.invoked_with == 'help': + # if the invoked command is help we don't want to increase the ratelimits since it's not actually + # invoking the command/making a request, so instead just check if the user/guild are on cooldown. + guild_cooldown = not guildcd.get_bucket(ctx.message).get_tokens() == 0 # if guild is on cooldown + if not any(r.id in ignore for r in ctx.author.roles): # check user bucket if user is not ignored + return guild_cooldown and not usercd.get_bucket(ctx.message).get_tokens() == 0 + return guild_cooldown + + user_bucket = usercd.get_bucket(ctx.message) + + if all(role.id not in ignore for role in ctx.author.roles): + user_rate = user_bucket.update_rate_limit() + + if user_rate: + # Can't use api; cause: member limit + delta = relativedelta(seconds=int(user_rate)) + cooldown = humanize_delta(delta) + message = ( + "You've used up your limit for Wolfram|Alpha requests.\n" + f"Cooldown: {cooldown}" + ) + await send_embed(ctx, message) + return False + + guild_bucket = guildcd.get_bucket(ctx.message) + guild_rate = guild_bucket.update_rate_limit() + + # Repr has a token attribute to read requests left + log.debug(guild_bucket) + + if guild_rate: + # Can't use api; cause: guild limit + message = ( + "The max limit of requests for the server has been reached for today.\n" + f"Cooldown: {int(guild_rate)}" + ) + await send_embed(ctx, message) + return False + + return True + + return check(predicate) + + +async def get_pod_pages(ctx: Context, bot: commands.Bot, query: str) -> Optional[List[Tuple]]: + """Get the Wolfram API pod pages for the provided query.""" + async with ctx.channel.typing(): + url_str = parse.urlencode({ + "input": query, + "appid": APPID, + "output": DEFAULT_OUTPUT_FORMAT, + "format": "image,plaintext" + }) + request_url = QUERY.format(request="query", data=url_str) + + async with bot.http_session.get(request_url) as response: + json = await response.json(content_type='text/plain') + + result = json["queryresult"] + + if result["error"]: + # API key not set up correctly + if result["error"]["msg"] == "Invalid appid": + message = "Wolfram API key is invalid or missing." + log.warning( + "API key seems to be missing, or invalid when " + f"processing a wolfram request: {url_str}, Response: {json}" + ) + await send_embed(ctx, message) + return + + message = "Something went wrong internally with your request, please notify staff!" + log.warning(f"Something went wrong getting a response from wolfram: {url_str}, Response: {json}") + await send_embed(ctx, message) + return + + if not result["success"]: + message = f"I couldn't find anything for {query}." + await send_embed(ctx, message) + return + + if not result["numpods"]: + message = "Could not find any results." + await send_embed(ctx, message) + return + + pods = result["pods"] + pages = [] + for pod in pods[:MAX_PODS]: + subs = pod.get("subpods") + + for sub in subs: + title = sub.get("title") or sub.get("plaintext") or sub.get("id", "") + img = sub["img"]["src"] + pages.append((title, img)) + return pages + + +class Wolfram(Cog): + """Commands for interacting with the Wolfram|Alpha API.""" + + def __init__(self, bot: commands.Bot): + self.bot = bot + + @group(name="wolfram", aliases=("wolf", "wa"), invoke_without_command=True) + @custom_cooldown(*STAFF_ROLES) + async def wolfram_command(self, ctx: Context, *, query: str) -> None: + """Requests all answers on a single image, sends an image of all related pods.""" + url_str = parse.urlencode({ + "i": query, + "appid": APPID, + }) + query = QUERY.format(request="simple", data=url_str) + + # Give feedback that the bot is working. + async with ctx.channel.typing(): + async with self.bot.http_session.get(query) as response: + status = response.status + image_bytes = await response.read() + + f = discord.File(BytesIO(image_bytes), filename="image.png") + image_url = "attachment://image.png" + + if status == 501: + message = "Failed to get response" + footer = "" + color = Colours.soft_red + elif status == 400: + message = "No input found" + footer = "" + color = Colours.soft_red + elif status == 403: + message = "Wolfram API key is invalid or missing." + footer = "" + color = Colours.soft_red + else: + message = "" + footer = "View original for a bigger picture." + color = Colours.soft_orange + + # Sends a "blank" embed if no request is received, unsure how to fix + await send_embed(ctx, message, color, footer=footer, img_url=image_url, f=f) + + @wolfram_command.command(name="page", aliases=("pa", "p")) + @custom_cooldown(*STAFF_ROLES) + async def wolfram_page_command(self, ctx: Context, *, query: str) -> None: + """ + Requests a drawn image of given query. + + Keywords worth noting are, "like curve", "curve", "graph", "pokemon", etc. + """ + pages = await get_pod_pages(ctx, self.bot, query) + + if not pages: + return + + embed = Embed() + embed.set_author(name="Wolfram Alpha", + icon_url=WOLF_IMAGE, + url="https://www.wolframalpha.com/") + embed.colour = Colours.soft_orange + + await ImagePaginator.paginate(pages, ctx, embed) + + @wolfram_command.command(name="cut", aliases=("c",)) + @custom_cooldown(*STAFF_ROLES) + async def wolfram_cut_command(self, ctx: Context, *, query: str) -> None: + """ + Requests a drawn image of given query. + + Keywords worth noting are, "like curve", "curve", "graph", "pokemon", etc. + """ + pages = await get_pod_pages(ctx, self.bot, query) + + if not pages: + return + + if len(pages) >= 2: + page = pages[1] + else: + page = pages[0] + + await send_embed(ctx, page[0], colour=Colours.soft_orange, img_url=page[1]) + + @wolfram_command.command(name="short", aliases=("sh", "s")) + @custom_cooldown(*STAFF_ROLES) + async def wolfram_short_command(self, ctx: Context, *, query: str) -> None: + """Requests an answer to a simple question.""" + url_str = parse.urlencode({ + "i": query, + "appid": APPID, + }) + query = QUERY.format(request="result", data=url_str) + + # Give feedback that the bot is working. + async with ctx.channel.typing(): + async with self.bot.http_session.get(query) as response: + status = response.status + response_text = await response.text() + + if status == 501: + message = "Failed to get response" + color = Colours.soft_red + elif status == 400: + message = "No input found" + color = Colours.soft_red + elif response_text == "Error 1: Invalid appid": + message = "Wolfram API key is invalid or missing." + color = Colours.soft_red + else: + message = response_text + color = Colours.soft_orange + + await send_embed(ctx, message, color) + + +def setup(bot: commands.Bot) -> None: + """Load the Wolfram cog.""" + bot.add_cog(Wolfram(bot)) -- cgit v1.2.3 From 38bebb3c3086de21553dc6eb838fb1fdb1e348be Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 29 Aug 2020 00:51:48 -0700 Subject: Added necessary utility for Wolfram cog. --- bot/utils/time.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 bot/utils/time.py diff --git a/bot/utils/time.py b/bot/utils/time.py new file mode 100644 index 00000000..f37a025c --- /dev/null +++ b/bot/utils/time.py @@ -0,0 +1,66 @@ +from dateutil.relativedelta import relativedelta + + +def _stringify_time_unit(value: int, unit: str) -> str: + """ + Returns a string to represent a value and time unit, ensuring that it uses the right plural form of the unit. + + >>> _stringify_time_unit(1, "seconds") + "1 second" + >>> _stringify_time_unit(24, "hours") + "24 hours" + >>> _stringify_time_unit(0, "minutes") + "less than a minute" + """ + if unit == "seconds" and value == 0: + return "0 seconds" + elif value == 1: + return f"{value} {unit[:-1]}" + elif value == 0: + return f"less than a {unit[:-1]}" + else: + return f"{value} {unit}" + + +def humanize_delta(delta: relativedelta, precision: str = "seconds", max_units: int = 6) -> str: + """ + Returns a human-readable version of the relativedelta. + + precision specifies the smallest unit of time to include (e.g. "seconds", "minutes"). + max_units specifies the maximum number of units of time to include (e.g. 1 may include days but not hours). + """ + if max_units <= 0: + raise ValueError("max_units must be positive") + + units = ( + ("years", delta.years), + ("months", delta.months), + ("days", delta.days), + ("hours", delta.hours), + ("minutes", delta.minutes), + ("seconds", delta.seconds), + ) + + # Add the time units that are >0, but stop at accuracy or max_units. + time_strings = [] + unit_count = 0 + for unit, value in units: + if value: + time_strings.append(_stringify_time_unit(value, unit)) + unit_count += 1 + + if unit == precision or unit_count >= max_units: + break + + # Add the 'and' between the last two units, if necessary + if len(time_strings) > 1: + time_strings[-1] = f"{time_strings[-2]} and {time_strings[-1]}" + del time_strings[-2] + + # If nothing has been found, just make the value 0 precision, e.g. `0 days`. + if not time_strings: + humanized = _stringify_time_unit(0, precision) + else: + humanized = ", ".join(time_strings) + + return humanized -- cgit v1.2.3 From a3941cb820803c9408a392c3207fd0483fcf6a0e Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Sat, 29 Aug 2020 15:56:41 -0700 Subject: Update bot/exts/evergreen/wolfram.py Co-authored-by: Dennis Pham --- bot/exts/evergreen/wolfram.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bot/exts/evergreen/wolfram.py b/bot/exts/evergreen/wolfram.py index 18ccc4e5..4e1d284b 100644 --- a/bot/exts/evergreen/wolfram.py +++ b/bot/exts/evergreen/wolfram.py @@ -74,8 +74,7 @@ def custom_cooldown(*ignore: List[int]) -> Callable: if user_rate: # Can't use api; cause: member limit - delta = relativedelta(seconds=int(user_rate)) - cooldown = humanize_delta(delta) + cooldown = arrow.utcnow().shift(seconds=int(user_rate)).humanize(only_distance=True) message = ( "You've used up your limit for Wolfram|Alpha requests.\n" f"Cooldown: {cooldown}" -- cgit v1.2.3 From d472389b564ed5e343d40750b092680fcdf1e9fc Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 29 Aug 2020 16:35:45 -0700 Subject: Removed the time utility and replaced it with the arrow package. Alphabetized the "Colours" NamedTuple in the constants file. --- bot/constants.py | 10 +++---- bot/exts/evergreen/wolfram.py | 3 +- bot/utils/time.py | 66 ------------------------------------------- docker-compose.yml | 3 +- 4 files changed, 8 insertions(+), 74 deletions(-) delete mode 100644 bot/utils/time.py diff --git a/bot/constants.py b/bot/constants.py index 4a97b9e0..f841193a 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -67,7 +67,7 @@ class Channels(NamedTuple): off_topic_2 = 463035268514185226 python = 267624335836053506 reddit = 458224812528238616 - seasonalbot_commands = int(environ.get("CHANNEL_SEASONALBOT_COMMANDS", 607247579608121354)) + seasonalbot_commands = int(environ.get("CHANNEL_SEASONALBOT_COMMANDS", 704362727778418798)) seasonalbot_voice = int(environ.get("CHANNEL_SEASONALBOT_VOICE", 606259004230074378)) staff_lounge = 464905259261755392 verification = 352442727016693763 @@ -93,11 +93,11 @@ class Colours: dark_green = 0x1f8b4c orange = 0xe67e22 pink = 0xcf84e0 + purple = 0xb734eb soft_green = 0x68c290 + soft_orange = 0xf9cb54 soft_red = 0xcd6d6d yellow = 0xf9f586 - purple = 0xb734eb - soft_orange = 0xf9cb54 class Emojis: @@ -190,8 +190,8 @@ class Tokens(NamedTuple): class Wolfram(NamedTuple): - user_limit_day = environ.get("WOLFRAM_USER_LIMIT_DAY", 10) - guild_limit_day = environ.get("WOLFRAM_GUILD_LIMIT_DAY", 67) + user_limit_day = int(environ.get("WOLFRAM_USER_LIMIT_DAY", 10)) + guild_limit_day = int(environ.get("WOLFRAM_GUILD_LIMIT_DAY", 67)) key = environ.get("WOLFRAM_API_KEY", None) diff --git a/bot/exts/evergreen/wolfram.py b/bot/exts/evergreen/wolfram.py index 4e1d284b..898e8d2a 100644 --- a/bot/exts/evergreen/wolfram.py +++ b/bot/exts/evergreen/wolfram.py @@ -3,15 +3,14 @@ from io import BytesIO from typing import Callable, List, Optional, Tuple from urllib import parse +import arrow import discord -from dateutil.relativedelta import relativedelta from discord import Embed from discord.ext import commands from discord.ext.commands import BucketType, Cog, Context, check, group from bot.constants import Colours, STAFF_ROLES, Wolfram from bot.utils.pagination import ImagePaginator -from bot.utils.time import humanize_delta log = logging.getLogger(__name__) diff --git a/bot/utils/time.py b/bot/utils/time.py deleted file mode 100644 index f37a025c..00000000 --- a/bot/utils/time.py +++ /dev/null @@ -1,66 +0,0 @@ -from dateutil.relativedelta import relativedelta - - -def _stringify_time_unit(value: int, unit: str) -> str: - """ - Returns a string to represent a value and time unit, ensuring that it uses the right plural form of the unit. - - >>> _stringify_time_unit(1, "seconds") - "1 second" - >>> _stringify_time_unit(24, "hours") - "24 hours" - >>> _stringify_time_unit(0, "minutes") - "less than a minute" - """ - if unit == "seconds" and value == 0: - return "0 seconds" - elif value == 1: - return f"{value} {unit[:-1]}" - elif value == 0: - return f"less than a {unit[:-1]}" - else: - return f"{value} {unit}" - - -def humanize_delta(delta: relativedelta, precision: str = "seconds", max_units: int = 6) -> str: - """ - Returns a human-readable version of the relativedelta. - - precision specifies the smallest unit of time to include (e.g. "seconds", "minutes"). - max_units specifies the maximum number of units of time to include (e.g. 1 may include days but not hours). - """ - if max_units <= 0: - raise ValueError("max_units must be positive") - - units = ( - ("years", delta.years), - ("months", delta.months), - ("days", delta.days), - ("hours", delta.hours), - ("minutes", delta.minutes), - ("seconds", delta.seconds), - ) - - # Add the time units that are >0, but stop at accuracy or max_units. - time_strings = [] - unit_count = 0 - for unit, value in units: - if value: - time_strings.append(_stringify_time_unit(value, unit)) - unit_count += 1 - - if unit == precision or unit_count >= max_units: - break - - # Add the 'and' between the last two units, if necessary - if len(time_strings) > 1: - time_strings[-1] = f"{time_strings[-2]} and {time_strings[-1]}" - del time_strings[-2] - - # If nothing has been found, just make the value 0 precision, e.g. `0 days`. - if not time_strings: - humanized = _stringify_time_unit(0, precision) - else: - humanized = ", ".join(time_strings) - - return humanized diff --git a/docker-compose.yml b/docker-compose.yml index 6cf5e9bd..8e5a9d53 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,12 +10,13 @@ services: restart: always environment: - - SEASONALBOT_TOKEN=yourtokenhere + - SEASONALBOT_TOKEN=NzQyMTI3NjUwMjM5NDE0MzUy.XzBmOw.F4UiLeZ1wH0yALV4_aov1Ol_kpg - SEASONALBOT_DEBUG=true # - SEASONALBOT_GUILD= # - SEASONALBOT_ADMIN_ROLE_ID= # - CHANNEL_ANNOUNCEMENTS= # - CHANNEL_DEVLOG= + - WOLFRAM_API_KEY=5WKXAG-W9X9TUG3J5 volumes: - /opt/pythondiscord/seasonalbot/log:/bot/bot/log -- cgit v1.2.3 From f2550a04ce9fc70e4a44990ab410975aeba68c40 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 29 Aug 2020 16:39:41 -0700 Subject: Accidently commited tokens. All have been reset. --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8e5a9d53..6cf5e9bd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,13 +10,12 @@ services: restart: always environment: - - SEASONALBOT_TOKEN=NzQyMTI3NjUwMjM5NDE0MzUy.XzBmOw.F4UiLeZ1wH0yALV4_aov1Ol_kpg + - SEASONALBOT_TOKEN=yourtokenhere - SEASONALBOT_DEBUG=true # - SEASONALBOT_GUILD= # - SEASONALBOT_ADMIN_ROLE_ID= # - CHANNEL_ANNOUNCEMENTS= # - CHANNEL_DEVLOG= - - WOLFRAM_API_KEY=5WKXAG-W9X9TUG3J5 volumes: - /opt/pythondiscord/seasonalbot/log:/bot/bot/log -- cgit v1.2.3 From 54020cf937e4144e72fed16ba164c71f8fec83ce Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 29 Aug 2020 16:46:26 -0700 Subject: Reverted the SeasonalBot commands channel. --- bot/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/constants.py b/bot/constants.py index f841193a..a436f17d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -67,7 +67,7 @@ class Channels(NamedTuple): off_topic_2 = 463035268514185226 python = 267624335836053506 reddit = 458224812528238616 - seasonalbot_commands = int(environ.get("CHANNEL_SEASONALBOT_COMMANDS", 704362727778418798)) + seasonalbot_commands = int(environ.get("CHANNEL_SEASONALBOT_COMMANDS", 607247579608121354)) seasonalbot_voice = int(environ.get("CHANNEL_SEASONALBOT_VOICE", 606259004230074378)) staff_lounge = 464905259261755392 verification = 352442727016693763 -- cgit v1.2.3 From 2f1b550f1974fe5fb56e56042c3ebf51375dcf50 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 29 Aug 2020 16:58:11 -0700 Subject: Removed None from environ.get() in Wolfram NamedTuple to keep consistency throughout constants.py --- bot/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/constants.py b/bot/constants.py index a436f17d..295bb90b 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -192,7 +192,7 @@ class Tokens(NamedTuple): class Wolfram(NamedTuple): user_limit_day = int(environ.get("WOLFRAM_USER_LIMIT_DAY", 10)) guild_limit_day = int(environ.get("WOLFRAM_GUILD_LIMIT_DAY", 67)) - key = environ.get("WOLFRAM_API_KEY", None) + key = environ.get("WOLFRAM_API_KEY") # Default role combinations -- cgit v1.2.3 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 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(-) 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(-) 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(-) 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 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(-) 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(-) 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(-) 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(-) 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(-) 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(-) 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(-) 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(-) 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(-) 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(-) 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 From d4446fb7587f5948e3979f995d1364b4503948ee Mon Sep 17 00:00:00 2001 From: AtieP <62116490+AtieP@users.noreply.github.com> Date: Sun, 13 Sep 2020 19:34:12 +0200 Subject: Apply suggestions from code review Fix grammar errors Co-authored-by: Dennis Pham --- bot/resources/evergreen/trivia_quiz.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bot/resources/evergreen/trivia_quiz.json b/bot/resources/evergreen/trivia_quiz.json index 067b8fb5..8f0a4114 100644 --- a/bot/resources/evergreen/trivia_quiz.json +++ b/bot/resources/evergreen/trivia_quiz.json @@ -222,25 +222,25 @@ "id": 131, "question": "In what country is the Ebro river located?", "answer": "Spain", - "info": "The Ebro river is a river located in Spain. It is 930 kilometers long and it's the second longest river that ends on the Mediterranean Sea." + "info": "The Ebro river is located in Spain. It is 930 kilometers long and it's the second longest river that ends on the Mediterranean Sea." }, { "id": 132, "question": "What year was the IBM PC model 5150 introduced into the market?", "answer": "1981", - "info": "The IBM PC was introduced in the market on 1981. It used the Intel 8088, with a clock speed of 4.77 MHz, along with the MDA and CGA as a video card." + "info": "The IBM PC was introduced into the market in 1981. It used the Intel 8088, with a clock speed of 4.77 MHz, along with the MDA and CGA as a video card." }, { "id": 133, "question": "What's the world's largest urban area?", "answer": "Tokyo", - "info": "Tokio is the most populated city in the world, with 37 million of people. It is located on Japan." + "info": "Tokyo is the most populated city in the world, with a population of 37 million people. It is located in Japan." }, { "id": 134, - "question": "How many planets there are on the Solar system?", + "question": "How many planets are there in the Solar system?", "answer": "8", - "info": "On the Solar system there are 8 planets: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune. Pluto isn't considered a planet on the Solar System anymore." + "info": "In the Solar system, there are 8 planets: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune. Pluto isn't considered a planet in the Solar System anymore." }, { "id": 135, -- cgit v1.2.3 From c8ba498d34fbbc9cd8ac49092d19fafe1f97cefa Mon Sep 17 00:00:00 2001 From: Gustav Odinger Date: Wed, 16 Sep 2020 23:50:10 +0200 Subject: Update .roll to use new dice emojis - Resolves #440 --- bot/constants.py | 12 ++++++------ bot/exts/evergreen/fun.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bot/constants.py b/bot/constants.py index 295bb90b..6605882d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -108,12 +108,12 @@ class Emojis: trashcan = "<:trashcan:637136429717389331>" ok_hand = ":ok_hand:" - terning1 = "<:terning1:431249668983488527>" - terning2 = "<:terning2:462339216987127808>" - terning3 = "<:terning3:431249694467948544>" - terning4 = "<:terning4:579980271475228682>" - terning5 = "<:terning5:431249716328792064>" - terning6 = "<:terning6:431249726705369098>" + dice_1 = "<:dice_1:755891608859443290>" + dice_2 = "<:dice_2:755891608741740635>" + dice_3 = "<:dice_3:755891608251138158>" + dice_4 = "<:dice_4:755891607882039327>" + dice_5 = "<:dice_5:755891608091885627>" + dice_6 = "<:dice_6:755891607680843838>" issue = "<:IssueOpen:629695470327037963>" issue_closed = "<:IssueClosed:629695470570307614>" diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 36a13ac0..1a7ebb90 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -41,7 +41,7 @@ class Fun(Cog): elif num_rolls < 1: output = ":no_entry: You must roll at least once." for _ in range(num_rolls): - terning = f"terning{random.randint(1, 6)}" + terning = f"dice_{random.randint(1, 6)}" output += getattr(Emojis, terning, '') await ctx.send(output) -- cgit v1.2.3 From f1ac62822d070d5df3a2cc9d13dc018149c55898 Mon Sep 17 00:00:00 2001 From: Gustav Odinger Date: Thu, 17 Sep 2020 00:32:55 +0200 Subject: Update variable name from terning to dice --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 1a7ebb90..b0240c45 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -41,8 +41,8 @@ class Fun(Cog): elif num_rolls < 1: output = ":no_entry: You must roll at least once." for _ in range(num_rolls): - terning = f"dice_{random.randint(1, 6)}" - output += getattr(Emojis, terning, '') + dice = f"dice_{random.randint(1, 6)}" + output += getattr(Emojis, dice, '') await ctx.send(output) @commands.command(name="uwu", aliases=("uwuwize", "uwuify",)) -- cgit v1.2.3 From c501cdf879d039e7871fda93925c0c5d3d46b8e3 Mon Sep 17 00:00:00 2001 From: Senjan21 <53477086+Senjan21@users.noreply.github.com> Date: Thu, 17 Sep 2020 19:53:41 +0200 Subject: fix `reddit` command to use new emojis. --- bot/exts/evergreen/reddit.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bot/exts/evergreen/reddit.py b/bot/exts/evergreen/reddit.py index fe204419..49127bea 100644 --- a/bot/exts/evergreen/reddit.py +++ b/bot/exts/evergreen/reddit.py @@ -68,9 +68,9 @@ class Reddit(commands.Cog): # ----------------------------------------------------------- # This code below is bound of change when the emojis are added. - upvote_emoji = self.bot.get_emoji(638729835245731840) - comment_emoji = self.bot.get_emoji(638729835073765387) - user_emoji = self.bot.get_emoji(638729835442602003) + upvote_emoji = self.bot.get_emoji(755845219890757644) + comment_emoji = self.bot.get_emoji(755845255001014384) + user_emoji = self.bot.get_emoji(755845303822974997) text_emoji = self.bot.get_emoji(676030265910493204) video_emoji = self.bot.get_emoji(676030265839190047) image_emoji = self.bot.get_emoji(676030265734201344) -- cgit v1.2.3 From 98718712ab38ecb98970ade58fd1afd6796f8718 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Fri, 18 Sep 2020 20:30:56 +0800 Subject: Make the encryption function top-level This makes caesar_func a top-level function and renames it to caesar_cipher. --- bot/exts/evergreen/fun.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 5a499270..3fd0f275 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -28,6 +28,26 @@ UWU_WORDS = { } +def caesar_cipher(text: str, offset: int) -> Iterable[str]: + """ + Implements a lazy Caesar Cipher algorithm. + + Encrypts a `text` given a specific integer `offset`. The sign + of the `offset` dictates the direction in which it shifts to, + with a negative value shifting to the left, and a positive + value shifting to the right. + """ + for char in text: + if not char.isascii() or not char.isalpha() or char.isspace(): + yield char + continue + + case_start = 65 if char.isupper() else 97 + true_offset = (ord(char) - case_start + offset) % 26 + + yield chr(case_start + true_offset) + + class Fun(Cog): """A collection of general commands for fun.""" @@ -126,21 +146,9 @@ class Fun(Cog): if left_shift: offset = -offset - def caesar_func(text: str) -> Iterable[str]: - """Implements a lazy Caesar Cipher algorithm.""" - for char in text: - if not char.isascii() or not char.isalpha() or char.isspace(): - yield char - continue - - case_start = 65 if char.isupper() else 97 - true_offset = (ord(char) - case_start + offset) % 26 - - yield chr(case_start + true_offset) - def conversion_func(text: str) -> str: """Encrypts the given string using the Caesar Cipher.""" - return "".join(caesar_func(text)) + return "".join(caesar_cipher(text, offset)) is_message = isinstance(msg, Message) -- cgit v1.2.3 From d6b331080d57fb122eb63644382717f2fc4860c7 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Fri, 18 Sep 2020 20:39:38 +0800 Subject: Refactor methods to use _get_text_and_embed This changes the converters used by caesarcipher_encrypt and caesarcipher_decrypt in order to accomodate for the manual conversion that _get_text_and_embed does, which allows for this feature to be easily disabled. --- bot/exts/evergreen/fun.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 3fd0f275..8235d072 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -131,7 +131,7 @@ class Fun(Cog): await ctx.send(embed=embed) @staticmethod - async def _caesar_cipher(ctx: Context, offset: int, msg: Union[Message, str], left_shift: bool = False) -> None: + async def _caesar_cipher(ctx: Context, offset: int, msg: str, left_shift: bool = False) -> None: """ Given a positive integer `offset`, translates and sends the given `msg`. @@ -150,10 +150,7 @@ class Fun(Cog): """Encrypts the given string using the Caesar Cipher.""" return "".join(caesar_cipher(text, offset)) - is_message = isinstance(msg, Message) - - text = msg.content if is_message else msg - embed = msg.embeds[0] if is_message and msg.embeds else None + text, embed = await Fun._get_text_and_embed(ctx, msg) if embed is not None: embed = Fun._convert_embed(conversion_func, embed) @@ -166,7 +163,7 @@ class Fun(Cog): await ctx.send(content=converted_text, embed=embed) @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift", "enc",)) - async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: + async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: str) -> None: """ Given a positive integer `offset`, encrypt the given `msg`. @@ -177,7 +174,7 @@ class Fun(Cog): await self._caesar_cipher(ctx, offset, msg, left_shift=False) @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift", "dec",)) - async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: + async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: str) -> None: """ Given a positive integer `offset`, decrypt the given `msg`. -- cgit v1.2.3 From 0567a6fe099465b2a36df7818113fadc8ff1c7d7 Mon Sep 17 00:00:00 2001 From: Kieran Siek Date: Fri, 18 Sep 2020 23:00:23 +0800 Subject: Fix typo in casercipher help. --- bot/exts/evergreen/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 8235d072..c5f8f9c8 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -117,7 +117,7 @@ class Fun(Cog): """ Translates a message using the Caesar Cipher. - See `decrpyt`, `encrypt`, and `info` subcommands. + See `decrypt`, `encrypt`, and `info` subcommands. """ if ctx.invoked_subcommand is None: await ctx.invoke(self.bot.get_command("help"), "caesarcipher") -- cgit v1.2.3 From dc63f50d2445c628806e9ac4f08d5ece6c72b18a Mon Sep 17 00:00:00 2001 From: kosayoda Date: Fri, 18 Sep 2020 23:33:56 +0800 Subject: Stop users from viewing messages they shouldn't. Using a user token, a user could fetch the message ID of a message in any channel, which may leak information when potential Message objects are automatically converted and parsed. Now, the bot will only retrive text from a valid Message object if the user has read permissions for the message the channel is in. --- bot/exts/evergreen/fun.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 2f575c1c..e6cdf716 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -181,18 +181,22 @@ class Fun(Cog): """ Attempts to extract the text and embed from a possible link to a discord Message. + Does not retrieve the text and embed from the Message if it is in a channel the user does + not have read permissions in. + Returns a tuple of: str: If `text` is a valid discord Message, the contents of the message, else `text`. Union[Embed, None]: The embed if found in the valid Message, else None """ embed = None - # message = await Fun._get_discord_message(ctx, text) - # if isinstance(message, Message): - # text = message.content - # # Take first embed because we can't send multiple embeds - # if message.embeds: - # embed = message.embeds[0] + msg = await Fun._get_discord_message(ctx, text) + # Ensure the user has read permissions for the channel the message is in + if isinstance(msg, Message) and ctx.author.permissions_in(msg.channel).read_messages: + text = msg.content + # Take first embed because we can't send multiple embeds + if msg.embeds: + embed = msg.embeds[0] return (text, embed) -- cgit v1.2.3 From a13f5737cdd947ac297f7af790d0c614aab0474a Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 19 Sep 2020 14:52:54 -0700 Subject: Updated issue/pr command to get multiple links. --- bot/exts/evergreen/issues.py | 84 ++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index 0f83731b..58ffe408 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -23,51 +23,59 @@ class Issues(commands.Cog): @commands.command(aliases=("pr",)) @override_in_channel(WHITELISTED_CHANNELS + (Channels.dev_contrib,)) async def issue( - self, ctx: commands.Context, number: int, repository: str = "seasonalbot", user: str = "python-discord" + self, ctx: commands.Context, numbers: commands.Greedy[int], repository: str = "seasonalbot", + user: str = "python-discord" ) -> None: - """Command to retrieve issues from a GitHub repository.""" - url = f"https://api.github.com/repos/{user}/{repository}/issues/{number}" - merge_url = f"https://api.github.com/repos/{user}/{repository}/pulls/{number}/merge" - - log.trace(f"Querying GH issues API: {url}") - async with self.bot.http_session.get(url) as r: - json_data = await r.json() - - if r.status in BAD_RESPONSE: - log.warning(f"Received response {r.status} from: {url}") - return await ctx.send(f"[{str(r.status)}] {BAD_RESPONSE.get(r.status)}") - - # The initial API request is made to the issues API endpoint, which will return information - # if the issue or PR is present. However, the scope of information returned for PRs differs - # from issues: if the 'issues' key is present in the response then we can pull the data we - # need from the initial API call. - if "issues" in json_data.get("html_url"): - if json_data.get("state") == "open": - icon_url = Emojis.issue - else: - icon_url = Emojis.issue_closed - - # If the 'issues' key is not contained in the API response and there is no error code, then - # we know that a PR has been requested and a call to the pulls API endpoint is necessary - # to get the desired information for the PR. - else: - log.trace(f"PR provided, querying GH pulls API for additional information: {merge_url}") - async with self.bot.http_session.get(merge_url) as m: + """Command to retrieve issue(s) from a GitHub repository.""" + links = [] + + for number in set(numbers): + # Convert from list to set to remove duplicates, if any. + url = f"https://api.github.com/repos/{user}/{repository}/issues/{number}" + merge_url = f"https://api.github.com/repos/{user}/{repository}/pulls/{number}/merge" + + log.trace(f"Querying GH issues API: {url}") + async with self.bot.http_session.get(url) as r: + json_data = await r.json() + + if r.status in BAD_RESPONSE: + log.warning(f"Received response {r.status} from: {url}") + return await ctx.send(f"[{str(r.status)}] #{number} {BAD_RESPONSE.get(r.status)}") + + # The initial API request is made to the issues API endpoint, which will return information + # if the issue or PR is present. However, the scope of information returned for PRs differs + # from issues: if the 'issues' key is present in the response then we can pull the data we + # need from the initial API call. + if "issues" in json_data.get("html_url"): if json_data.get("state") == "open": - icon_url = Emojis.pull_request - # When the status is 204 this means that the state of the PR is merged - elif m.status == 204: - icon_url = Emojis.merge + icon_url = Emojis.issue else: - icon_url = Emojis.pull_request_closed + icon_url = Emojis.issue_closed - issue_url = json_data.get("html_url") - description_text = f"[{repository}] #{number} {json_data.get('title')}" + # If the 'issues' key is not contained in the API response and there is no error code, then + # we know that a PR has been requested and a call to the pulls API endpoint is necessary + # to get the desired information for the PR. + else: + log.trace(f"PR provided, querying GH pulls API for additional information: {merge_url}") + async with self.bot.http_session.get(merge_url) as m: + if json_data.get("state") == "open": + icon_url = Emojis.pull_request + # When the status is 204 this means that the state of the PR is merged + elif m.status == 204: + icon_url = Emojis.merge + else: + icon_url = Emojis.pull_request_closed + + issue_url = json_data.get("html_url") + links.append([icon_url, f"[{repository}] #{number} {json_data.get('title')}", issue_url]) + + description_list = ['{0} [{1}]({2})'.format(*link) for link in links] resp = discord.Embed( colour=Colours.bright_green, - description=f"{icon_url} [{description_text}]({issue_url})" + description='\n'.join(description_list) ) - resp.set_author(name="GitHub", url=issue_url) + + resp.set_author(name="GitHub", url=f"https://github.com/python-discord/{repository}") await ctx.send(embed=resp) -- cgit v1.2.3 From 7a29cce2d06303965a89b789b352d4a5d9637f28 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 19 Sep 2020 15:06:24 -0700 Subject: Replaced single quotes with double, set the repo link to be user-defined --- bot/exts/evergreen/issues.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index 58ffe408..2f086f59 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -69,13 +69,13 @@ class Issues(commands.Cog): issue_url = json_data.get("html_url") links.append([icon_url, f"[{repository}] #{number} {json_data.get('title')}", issue_url]) - description_list = ['{0} [{1}]({2})'.format(*link) for link in links] + description_list = ["{0} [{1}]({2})".format(*link) for link in links] resp = discord.Embed( colour=Colours.bright_green, description='\n'.join(description_list) ) - resp.set_author(name="GitHub", url=f"https://github.com/python-discord/{repository}") + resp.set_author(name="GitHub", url=f"https://github.com/{user}/{repository}") await ctx.send(embed=resp) -- cgit v1.2.3 From 733a634784d848fd3b6a1c575aa7d3a0f8be44c9 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sat, 19 Sep 2020 15:08:11 -0700 Subject: Described how links are shown in the embed. --- bot/exts/evergreen/issues.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index 2f086f59..d909ae6e 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -69,6 +69,7 @@ class Issues(commands.Cog): issue_url = json_data.get("html_url") links.append([icon_url, f"[{repository}] #{number} {json_data.get('title')}", issue_url]) + # Issue/PR format: emoji to show if open/closed/merged, number and the title as a singular link. description_list = ["{0} [{1}]({2})".format(*link) for link in links] resp = discord.Embed( colour=Colours.bright_green, -- cgit v1.2.3 From 24b788d11bec461718b540d5d9fec2785afa5d23 Mon Sep 17 00:00:00 2001 From: Den4200 Date: Sat, 19 Sep 2020 20:31:26 -0400 Subject: Allow `issue` command in #dev-branding --- bot/constants.py | 1 + bot/exts/evergreen/issues.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bot/constants.py b/bot/constants.py index 6605882d..fa428a61 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -52,6 +52,7 @@ class Channels(NamedTuple): devalerts = 460181980097675264 devlog = int(environ.get("CHANNEL_DEVLOG", 622895325144940554)) dev_contrib = 635950537262759947 + dev_branding = 753252897059373066 help_0 = 303906576991780866 help_1 = 303906556754395136 help_2 = 303906514266226689 diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index d909ae6e..97baac6a 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -21,9 +21,12 @@ class Issues(commands.Cog): self.bot = bot @commands.command(aliases=("pr",)) - @override_in_channel(WHITELISTED_CHANNELS + (Channels.dev_contrib,)) + @override_in_channel(WHITELISTED_CHANNELS + (Channels.dev_contrib, Channels.dev_branding)) async def issue( - self, ctx: commands.Context, numbers: commands.Greedy[int], repository: str = "seasonalbot", + self, + ctx: commands.Context, + numbers: commands.Greedy[int], + repository: str = "seasonalbot", user: str = "python-discord" ) -> None: """Command to retrieve issue(s) from a GitHub repository.""" -- cgit v1.2.3 From 91ca04e823eff28907f4018b851bf78a1ffb085e Mon Sep 17 00:00:00 2001 From: Den4200 Date: Sat, 19 Sep 2020 20:36:54 -0400 Subject: Limit maximum PRs/issues to 10 per invocation --- bot/exts/evergreen/issues.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index 97baac6a..2a9359b7 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -1,9 +1,10 @@ import logging +import random import discord from discord.ext import commands -from bot.constants import Channels, Colours, Emojis, WHITELISTED_CHANNELS +from bot.constants import Channels, Colours, Emojis, ERROR_REPLIES, WHITELISTED_CHANNELS from bot.utils.decorators import override_in_channel log = logging.getLogger(__name__) @@ -13,6 +14,8 @@ BAD_RESPONSE = { 403: "Rate limit has been hit! Please try again later!" } +MAX_REQUESTS = 10 + class Issues(commands.Cog): """Cog that allows users to retrieve issues from GitHub.""" @@ -31,6 +34,16 @@ class Issues(commands.Cog): ) -> None: """Command to retrieve issue(s) from a GitHub repository.""" links = [] + numbers = set(numbers) + + if len(numbers) > MAX_REQUESTS: + embed = discord.Embed( + title=random.choice(ERROR_REPLIES), + color=Colours.soft_red, + description=f"Too many issues/PRs! (maximum of {MAX_REQUESTS})" + ) + await ctx.send(embed=embed) + return for number in set(numbers): # Convert from list to set to remove duplicates, if any. -- cgit v1.2.3 From d777222ccfad97f17a44b1deb342e5e89bca9946 Mon Sep 17 00:00:00 2001 From: Den4200 Date: Sat, 19 Sep 2020 20:37:36 -0400 Subject: Invoke help command when no PRs/issues are given --- bot/exts/evergreen/issues.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index 2a9359b7..e128ae50 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -36,6 +36,10 @@ class Issues(commands.Cog): links = [] numbers = set(numbers) + if not numbers: + await ctx.invoke(self.bot.get_command('help'), 'issue') + return + if len(numbers) > MAX_REQUESTS: embed = discord.Embed( title=random.choice(ERROR_REPLIES), -- cgit v1.2.3 From 157cc184c075287eb24a765b15430f2530d44bae Mon Sep 17 00:00:00 2001 From: Den4200 Date: Sat, 19 Sep 2020 20:38:30 -0400 Subject: Authenticate with the GitHub API to allow for more requests --- bot/exts/evergreen/issues.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index e128ae50..15c97473 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -4,7 +4,7 @@ import random import discord from discord.ext import commands -from bot.constants import Channels, Colours, Emojis, ERROR_REPLIES, WHITELISTED_CHANNELS +from bot.constants import Channels, Colours, Emojis, ERROR_REPLIES, Tokens, WHITELISTED_CHANNELS from bot.utils.decorators import override_in_channel log = logging.getLogger(__name__) @@ -16,6 +16,10 @@ BAD_RESPONSE = { MAX_REQUESTS = 10 +REQUEST_HEADERS = dict() +if GITHUB_TOKEN := Tokens.github: + REQUEST_HEADERS["Authorization"] = f"token {GITHUB_TOKEN}" + class Issues(commands.Cog): """Cog that allows users to retrieve issues from GitHub.""" @@ -30,7 +34,7 @@ class Issues(commands.Cog): ctx: commands.Context, numbers: commands.Greedy[int], repository: str = "seasonalbot", - user: str = "python-discord" + user: str = "python-discord" ) -> None: """Command to retrieve issue(s) from a GitHub repository.""" links = [] @@ -55,7 +59,7 @@ class Issues(commands.Cog): merge_url = f"https://api.github.com/repos/{user}/{repository}/pulls/{number}/merge" log.trace(f"Querying GH issues API: {url}") - async with self.bot.http_session.get(url) as r: + async with self.bot.http_session.get(url, headers=REQUEST_HEADERS) as r: json_data = await r.json() if r.status in BAD_RESPONSE: -- cgit v1.2.3 From fc5837770a0a1b49986768455a36d82193fbaadd Mon Sep 17 00:00:00 2001 From: Den4200 Date: Sat, 19 Sep 2020 20:48:12 -0400 Subject: Fix order of imports --- bot/exts/evergreen/issues.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/evergreen/issues.py b/bot/exts/evergreen/issues.py index 15c97473..5a5c82e7 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/evergreen/issues.py @@ -4,7 +4,7 @@ import random import discord from discord.ext import commands -from bot.constants import Channels, Colours, Emojis, ERROR_REPLIES, Tokens, WHITELISTED_CHANNELS +from bot.constants import Channels, Colours, ERROR_REPLIES, Emojis, Tokens, WHITELISTED_CHANNELS from bot.utils.decorators import override_in_channel log = logging.getLogger(__name__) -- cgit v1.2.3 From 27d29c0981b5e846d6b5b130d2b07a4927950dab Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Mon, 21 Sep 2020 18:31:13 +1000 Subject: Prevent uwu output from pinging globally allowed roles. --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index b0240c45..5d4743e4 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -5,7 +5,7 @@ from typing import Callable, Tuple, Union from discord import Embed, Message from discord.ext import commands -from discord.ext.commands import Bot, Cog, Context, MessageConverter +from discord.ext.commands import Bot, Cog, Context, MessageConverter, clean_content from bot import utils from bot.constants import Emojis @@ -46,7 +46,7 @@ class Fun(Cog): await ctx.send(output) @commands.command(name="uwu", aliases=("uwuwize", "uwuify",)) - async def uwu_command(self, ctx: Context, *, text: str) -> None: + async def uwu_command(self, ctx: Context, *, text: clean_content(fix_channel_mentions=True)) -> None: """Converts a given `text` into it's uwu equivalent.""" conversion_func = functools.partial( utils.replace_many, replacements=UWU_WORDS, ignore_case=True, match_case=True -- cgit v1.2.3 From 1c0afb81dbd690c4051ee90f59d63bb171d1656f Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Mon, 21 Sep 2020 20:12:58 +1000 Subject: Use clean_content when fetching linked msgs for fun commands. --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 1668982b..de6a92c6 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -87,7 +87,7 @@ class Fun(Cog): await ctx.send(content=converted_text, embed=embed) @commands.command(name="randomcase", aliases=("rcase", "randomcaps", "rcaps",)) - async def randomcase_command(self, ctx: Context, *, text: str) -> None: + async def randomcase_command(self, ctx: Context, *, text: clean_content(fix_channel_mentions=True)) -> None: """Randomly converts the casing of a given `text`.""" def conversion_func(text: str) -> str: """Randomly converts the casing of a given string.""" @@ -193,7 +193,7 @@ class Fun(Cog): msg = await Fun._get_discord_message(ctx, text) # Ensure the user has read permissions for the channel the message is in if isinstance(msg, Message) and ctx.author.permissions_in(msg.channel).read_messages: - text = msg.content + text = msg.clean_content # Take first embed because we can't send multiple embeds if msg.embeds: embed = msg.embeds[0] -- cgit v1.2.3