aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/evergreen/snakes
diff options
context:
space:
mode:
Diffstat (limited to 'bot/exts/evergreen/snakes')
-rw-r--r--bot/exts/evergreen/snakes/_converter.py4
-rw-r--r--bot/exts/evergreen/snakes/_snakes_cog.py10
-rw-r--r--bot/exts/evergreen/snakes/_utils.py46
3 files changed, 30 insertions, 30 deletions
diff --git a/bot/exts/evergreen/snakes/_converter.py b/bot/exts/evergreen/snakes/_converter.py
index 75212107..765b983d 100644
--- a/bot/exts/evergreen/snakes/_converter.py
+++ b/bot/exts/evergreen/snakes/_converter.py
@@ -1,7 +1,7 @@
import json
import logging
import random
-from typing import Iterable, List
+from collections.abc import Iterable
import discord
from discord.ext.commands import Context, Converter
@@ -27,7 +27,7 @@ class Snake(Converter):
if name == "python":
return "Python (programming language)"
- def get_potential(iterable: Iterable, *, threshold: int = 80) -> List[str]:
+ def get_potential(iterable: Iterable, *, threshold: int = 80) -> list[str]:
nonlocal name
potential = []
diff --git a/bot/exts/evergreen/snakes/_snakes_cog.py b/bot/exts/evergreen/snakes/_snakes_cog.py
index 225df948..04804222 100644
--- a/bot/exts/evergreen/snakes/_snakes_cog.py
+++ b/bot/exts/evergreen/snakes/_snakes_cog.py
@@ -9,7 +9,7 @@ import textwrap
import urllib
from functools import partial
from io import BytesIO
-from typing import Any, Dict, List, Optional
+from typing import Any, Optional
import async_timeout
from PIL import Image, ImageDraw, ImageFont
@@ -284,7 +284,7 @@ class Snakes(Cog):
async with self.bot.http_session.get(url, params=params) as response:
return await response.json()
- def _get_random_long_message(self, messages: List[str], retries: int = 10) -> str:
+ def _get_random_long_message(self, messages: list[str], retries: int = 10) -> str:
"""
Fetch a message that's at least 3 words long, if possible to do so in retries attempts.
@@ -299,7 +299,7 @@ class Snakes(Cog):
return long_message
- async def _get_snek(self, name: str) -> Dict[str, Any]:
+ async def _get_snek(self, name: str) -> dict[str, Any]:
"""
Fetches all the data from a wikipedia article about a snake.
@@ -401,11 +401,11 @@ class Snakes(Cog):
return snake_info
- async def _get_snake_name(self) -> Dict[str, str]:
+ async def _get_snake_name(self) -> dict[str, str]:
"""Gets a random snake name."""
return random.choice(self.snake_names)
- async def _validate_answer(self, ctx: Context, message: Message, answer: str, options: list) -> None:
+ async def _validate_answer(self, ctx: Context, message: Message, answer: str, options: dict[str, str]) -> None:
"""Validate the answer using a reaction event loop."""
def predicate(reaction: Reaction, user: Member) -> bool:
"""Test if the the answer is valid and can be evaluated."""
diff --git a/bot/exts/evergreen/snakes/_utils.py b/bot/exts/evergreen/snakes/_utils.py
index a3ff3d12..b5f13c53 100644
--- a/bot/exts/evergreen/snakes/_utils.py
+++ b/bot/exts/evergreen/snakes/_utils.py
@@ -6,7 +6,6 @@ import math
import random
from itertools import product
from pathlib import Path
-from typing import List, Tuple
from PIL import Image
from PIL.ImageDraw import ImageDraw
@@ -99,25 +98,25 @@ BOARD = {
16: 6
}
-DEFAULT_SNAKE_COLOR: int = 0x15c7ea
-DEFAULT_BACKGROUND_COLOR: int = 0
-DEFAULT_IMAGE_DIMENSIONS: Tuple[int] = (200, 200)
-DEFAULT_SNAKE_LENGTH: int = 22
-DEFAULT_SNAKE_WIDTH: int = 8
-DEFAULT_SEGMENT_LENGTH_RANGE: Tuple[int] = (7, 10)
-DEFAULT_IMAGE_MARGINS: Tuple[int] = (50, 50)
-DEFAULT_TEXT: str = "snek\nit\nup"
-DEFAULT_TEXT_POSITION: Tuple[int] = (
+DEFAULT_SNAKE_COLOR = 0x15c7ea
+DEFAULT_BACKGROUND_COLOR = 0
+DEFAULT_IMAGE_DIMENSIONS = (200, 200)
+DEFAULT_SNAKE_LENGTH = 22
+DEFAULT_SNAKE_WIDTH = 8
+DEFAULT_SEGMENT_LENGTH_RANGE = (7, 10)
+DEFAULT_IMAGE_MARGINS = (50, 50)
+DEFAULT_TEXT = "snek\nit\nup"
+DEFAULT_TEXT_POSITION = (
10,
10
)
-DEFAULT_TEXT_COLOR: int = 0xf2ea15
+DEFAULT_TEXT_COLOR = 0xf2ea15
X = 0
Y = 1
ANGLE_RANGE = math.pi * 2
-def get_resource(file: str) -> List[dict]:
+def get_resource(file: str) -> list[dict]:
"""Load Snake resources JSON."""
return json.loads((SNAKE_RESOURCES / f"{file}.json").read_text("utf-8"))
@@ -144,7 +143,7 @@ class PerlinNoiseFactory(object):
Licensed under ISC
"""
- def __init__(self, dimension: int, octaves: int = 1, tile: Tuple[int] = (), unbias: bool = False):
+ def __init__(self, dimension: int, octaves: int = 1, tile: tuple[int, ...] = (), unbias: bool = False):
"""
Create a new Perlin noise factory in the given number of dimensions.
@@ -172,7 +171,7 @@ class PerlinNoiseFactory(object):
self.gradient = {}
- def _generate_gradient(self) -> Tuple[float, ...]:
+ def _generate_gradient(self) -> tuple[float, ...]:
"""
Generate a random unit vector at each grid point.
@@ -282,13 +281,14 @@ class PerlinNoiseFactory(object):
def create_snek_frame(
perlin_factory: PerlinNoiseFactory, perlin_lookup_vertical_shift: float = 0,
- image_dimensions: Tuple[int] = DEFAULT_IMAGE_DIMENSIONS, image_margins: Tuple[int] = DEFAULT_IMAGE_MARGINS,
+ image_dimensions: tuple[int, int] = DEFAULT_IMAGE_DIMENSIONS,
+ image_margins: tuple[int, int] = DEFAULT_IMAGE_MARGINS,
snake_length: int = DEFAULT_SNAKE_LENGTH,
snake_color: int = DEFAULT_SNAKE_COLOR, bg_color: int = DEFAULT_BACKGROUND_COLOR,
- segment_length_range: Tuple[int] = DEFAULT_SEGMENT_LENGTH_RANGE, snake_width: int = DEFAULT_SNAKE_WIDTH,
- text: str = DEFAULT_TEXT, text_position: Tuple[int] = DEFAULT_TEXT_POSITION,
- text_color: Tuple[int] = DEFAULT_TEXT_COLOR
-) -> Image:
+ segment_length_range: tuple[int, int] = DEFAULT_SEGMENT_LENGTH_RANGE, snake_width: int = DEFAULT_SNAKE_WIDTH,
+ text: str = DEFAULT_TEXT, text_position: tuple[float, float] = DEFAULT_TEXT_POSITION,
+ text_color: int = DEFAULT_TEXT_COLOR
+) -> Image.Image:
"""
Creates a single random snek frame using Perlin noise.
@@ -297,7 +297,7 @@ def create_snek_frame(
"""
start_x = random.randint(image_margins[X], image_dimensions[X] - image_margins[X])
start_y = random.randint(image_margins[Y], image_dimensions[Y] - image_margins[Y])
- points = [(start_x, start_y)]
+ points: list[tuple[float, float]] = [(start_x, start_y)]
for index in range(0, snake_length):
angle = perlin_factory.get_plain_noise(
@@ -311,8 +311,8 @@ def create_snek_frame(
))
# normalize bounds
- min_dimensions = [start_x, start_y]
- max_dimensions = [start_x, start_y]
+ min_dimensions: list[float] = [start_x, start_y]
+ max_dimensions: list[float] = [start_x, start_y]
for point in points:
min_dimensions[X] = min(point[X], min_dimensions[X])
min_dimensions[Y] = min(point[Y], min_dimensions[Y])
@@ -706,7 +706,7 @@ class SnakeAndLaddersGame:
"""Clean up the finished game object."""
del self.snakes.active_sal[self.channel]
- def _board_coordinate_from_index(self, index: int) -> Tuple[int, int]:
+ def _board_coordinate_from_index(self, index: int) -> tuple[int, int]:
"""Convert the tile number to the x/y coordinates for graphical purposes."""
y_level = 9 - math.floor((index - 1) / 10)
is_reversed = math.floor((index - 1) / 10) % 2 != 0