aboutsummaryrefslogtreecommitdiffstats
path: root/bot/seasons/evergreen/snakes/snakes_cog.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot/seasons/evergreen/snakes/snakes_cog.py')
-rw-r--r--bot/seasons/evergreen/snakes/snakes_cog.py95
1 files changed, 53 insertions, 42 deletions
diff --git a/bot/seasons/evergreen/snakes/snakes_cog.py b/bot/seasons/evergreen/snakes/snakes_cog.py
index 74d2ab4f..3ffdf1bf 100644
--- a/bot/seasons/evergreen/snakes/snakes_cog.py
+++ b/bot/seasons/evergreen/snakes/snakes_cog.py
@@ -134,12 +134,11 @@ CARD = {
class Snakes(Cog):
"""
- Commands related to snakes. These were created by our
- community during the first code jam.
+ Commands related to snakes, created by our community during the first code jam.
More information can be found in the code-jam-1 repo.
- https://gitlab_bot_repo.com/discord-python/code-jams/code-jam-1
+ https://github.com/python-discord/code-jam-1
"""
wiki_brief = re.compile(r'(.*?)(=+ (.*?) =+)', flags=re.DOTALL)
@@ -156,9 +155,8 @@ class Snakes(Cog):
# region: Helper methods
@staticmethod
def _beautiful_pastel(hue):
- """
- Returns random bright pastels.
- """
+ """Returns random bright pastels."""
+
light = random.uniform(0.7, 0.85)
saturation = 1
@@ -178,6 +176,7 @@ class Snakes(Cog):
Written by juan and Someone during the first code jam.
"""
+
snake = Image.open(buffer)
# Get the size of the snake icon, configure the height of the image box (yes, it changes)
@@ -254,9 +253,8 @@ class Snakes(Cog):
@staticmethod
def _snakify(message):
- """
- Sssnakifffiesss a sstring.
- """
+ """Sssnakifffiesss a sstring."""
+
# Replace fricatives with exaggerated snake fricatives.
simple_fricatives = [
"f", "s", "z", "h",
@@ -278,9 +276,8 @@ class Snakes(Cog):
return message
async def _fetch(self, session, url, params=None):
- """
- Asyncronous web request helper method.
- """
+ """Asynchronous web request helper method."""
+
if params is None:
params = {}
@@ -290,11 +287,11 @@ class Snakes(Cog):
def _get_random_long_message(self, messages, retries=10):
"""
- Fetch a message that's at least 3 words long,
- but only if it is possible to do so in retries
- attempts. Else, just return whatever the last
- message is.
+ Fetch a message that's at least 3 words long, if possible to do so in retries attempts.
+
+ Else, just return whatever the last message is.
"""
+
long_message = random.choice(messages)
if len(long_message.split()) < 3 and retries > 0:
return self._get_random_long_message(
@@ -306,14 +303,16 @@ class Snakes(Cog):
async def _get_snek(self, name: str) -> Dict[str, Any]:
"""
- Goes online and fetches all the data from a wikipedia article
- about a snake. Builds a dict that the .get() method can use.
+ Fetches all the data from a wikipedia article about a snake.
+
+ Builds a dict that the .get() method can use.
Created by Ava and eivl.
:param name: The name of the snake to get information for - omit for a random snake
:return: A dict containing information on a snake
"""
+
snake_info = {}
async with aiohttp.ClientSession() as session:
@@ -412,20 +411,21 @@ class Snakes(Cog):
async def _get_snake_name(self) -> Dict[str, str]:
"""
Gets a random snake name.
+
:return: A random snake name, as a string.
"""
return random.choice(self.snake_names)
async def _validate_answer(self, ctx: Context, message: Message, answer: str, options: list):
"""
- Validate the answer using a reaction event loop
+ Validate the answer using a reaction event loop.
+
:return:
"""
def predicate(reaction, user):
- """
- Test if the the answer is valid and can be evaluated.
- """
+ """Test if the the answer is valid and can be evaluated."""
+
return (
reaction.message.id == message.id # The reaction is attached to the question we asked.
and user == ctx.author # It's the user who triggered the quiz.
@@ -465,7 +465,7 @@ class Snakes(Cog):
@locked()
async def antidote_command(self, ctx: Context):
"""
- Antidote - Can you create the antivenom before the patient dies?
+ Antidote! Can you create the antivenom before the patient dies?
Rules: You have 4 ingredients for each antidote, you only have 10 attempts
Once you synthesize the antidote, you will be presented with 4 markers
@@ -480,9 +480,7 @@ class Snakes(Cog):
"""
def predicate(reaction_: Reaction, user_: Member):
- """
- Make sure that this reaction is what we want to operate on
- """
+ """Make sure that this reaction is what we want to operate on."""
return (
all((
@@ -610,7 +608,7 @@ class Snakes(Cog):
@snakes_group.command(name='draw')
async def draw_command(self, ctx: Context):
"""
- Draws a random snek using Perlin noise
+ Draws a random snek using Perlin noise.
Written by Momo and kel.
Modified by juan and lemon.
@@ -652,12 +650,14 @@ class Snakes(Cog):
async def get_command(self, ctx: Context, *, name: Snake = None):
"""
Fetches information about a snake from Wikipedia.
+
:param ctx: Context object passed from discord.py
:param name: Optional, the name of the snake to get information
for - omit for a random snake
Created by Ava and eivl.
"""
+
with ctx.typing():
if name is None:
name = await Snake.random()
@@ -702,11 +702,12 @@ class Snakes(Cog):
@locked()
async def guess_command(self, ctx):
"""
- Snake identifying game!
+ Snake identifying game.
Made by Ava and eivl.
Modified by lemon.
"""
+
with ctx.typing():
image = None
@@ -736,10 +737,11 @@ class Snakes(Cog):
@snakes_group.command(name='hatch')
async def hatch_command(self, ctx: Context):
"""
- Hatches your personal snake
+ Hatches your personal snake.
Written by Momo and kel.
"""
+
# Pick a random snake to hatch.
snake_name = random.choice(list(utils.snakes.keys()))
snake_image = utils.snakes[snake_name]
@@ -772,6 +774,7 @@ class Snakes(Cog):
Written by Samuel.
Modified by gdude.
"""
+
url = "http://www.omdbapi.com/"
page = random.randint(1, 27)
@@ -842,6 +845,7 @@ class Snakes(Cog):
This was created by Mushy and Cardium,
and modified by Urthas and lemon.
"""
+
# Prepare a question.
question = random.choice(self.snake_quizzes)
answer = question["answerkey"]
@@ -862,6 +866,8 @@ class Snakes(Cog):
@snakes_group.command(name='name', aliases=('name_gen',))
async def name_command(self, ctx: Context, *, name: str = None):
"""
+ Snakifies a username.
+
Slices the users name at the last vowel (or second last if the name
ends with a vowel), and then combines it with a random snake name,
which is sliced at the first vowel (or second if the name starts with
@@ -880,6 +886,7 @@ class Snakes(Cog):
This was written by Iceman, and modified for inclusion into the bot by lemon.
"""
+
snake_name = await self._get_snake_name()
snake_name = snake_name['name']
snake_prefix = ""
@@ -932,11 +939,12 @@ class Snakes(Cog):
@locked()
async def sal_command(self, ctx: Context):
"""
- Play a game of Snakes and Ladders!
+ Play a game of Snakes and Ladders.
Written by Momo and kel.
Modified by lemon.
"""
+
# check if there is already a game in this channel
if ctx.channel in self.active_sal:
await ctx.send(f"{ctx.author.mention} A game is already in progress in this channel.")
@@ -949,10 +957,8 @@ class Snakes(Cog):
@snakes_group.command(name='about')
async def about_command(self, ctx: Context):
- """
- A command that shows an embed with information about the event,
- it's participants, and its winners.
- """
+ """Show an embed with information about the event, its participants, and its winners."""
+
contributors = [
"<@!245270749919576066>",
"<@!396290259907903491>",
@@ -996,10 +1002,11 @@ class Snakes(Cog):
@snakes_group.command(name='card')
async def card_command(self, ctx: Context, *, name: Snake = None):
"""
- Create an interesting little card from a snake!
+ Create an interesting little card from a snake.
Created by juan and Someone during the first code jam.
"""
+
# Get the snake data we need
if not name:
name_obj = await self._get_snake_name()
@@ -1034,11 +1041,12 @@ class Snakes(Cog):
@snakes_group.command(name='fact')
async def fact_command(self, ctx: Context):
"""
- Gets a snake-related fact
+ Gets a snake-related fact.
Written by Andrew and Prithaj.
Modified by lemon.
"""
+
question = random.choice(self.snake_facts)["fact"]
embed = Embed(
title="Snake fact",
@@ -1049,9 +1057,8 @@ class Snakes(Cog):
@snakes_group.command(name='help')
async def help_command(self, ctx: Context):
- """
- This just invokes the help command on this cog.
- """
+ """Invokes the help command for the Snakes Cog."""
+
log.debug(f"{ctx.author} requested info about the snakes cog")
return await ctx.invoke(self.bot.get_command("help"), "Snakes")
@@ -1059,6 +1066,7 @@ class Snakes(Cog):
async def snakify_command(self, ctx: Context, *, message: str = None):
"""
How would I talk if I were a snake?
+
:param ctx: context
:param message: If this is passed, it will snakify the message.
If not, it will snakify a random message from
@@ -1067,6 +1075,7 @@ class Snakes(Cog):
Written by Momo and kel.
Modified by lemon.
"""
+
with ctx.typing():
embed = Embed()
user = ctx.message.author
@@ -1100,13 +1109,14 @@ class Snakes(Cog):
@snakes_group.command(name='video', aliases=('get_video',))
async def video_command(self, ctx: Context, *, search: str = None):
"""
- Gets a YouTube video about snakes
+ Gets a YouTube video about snakes.
:param ctx: Context object passed from discord.py
:param search: Optional, a name of a snake. Used to search for videos with that name
Written by Andrew and Prithaj.
"""
+
# Are we searching for anything specific?
if search:
query = search + ' snake'
@@ -1141,12 +1151,12 @@ class Snakes(Cog):
@snakes_group.command(name='zen')
async def zen_command(self, ctx: Context):
"""
- Gets a random quote from the Zen of Python,
- except as if spoken by a snake.
+ Gets a random quote from the Zen of Python, except as if spoken by a snake.
Written by Prithaj and Andrew.
Modified by lemon.
"""
+
embed = Embed(
title="Zzzen of Pythhon",
color=SNAKE_COLOR
@@ -1168,6 +1178,7 @@ class Snakes(Cog):
@card_command.error
@video_command.error
async def command_error(self, ctx, error):
+ """Local error handler for the Snake Cog."""
embed = Embed()
embed.colour = Colour.red()