Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
321f8ea
Expand docs, move async Reminder error handling, and replace Tags coo…
MysticMia May 16, 2025
5b3b9e2
Replace all Interaction type function annotations Interaction[Bot]
MysticMia May 16, 2025
06654e0
Fix flake8 errors (line too long, missing imports after moving remind…
MysticMia May 16, 2025
2155c01
Wrap every file I could find at 79 characters. Took a few hours D:
MysticMia May 20, 2025
6c5c66f
Move generate_roll from cogs/funaddons.py to new roll.py file, and ad…
MysticMia May 1, 2025
0f1d5c3
Update _parse_dice_roll function so roll.py has 100% test coverage
MysticMia May 1, 2025
b394103
Split dictionary into multiple functions, and begin transition to new…
MysticMia May 2, 2025
ff30f5a
Add new client function to allow cleaner inline command arguments str…
MysticMia May 20, 2025
3eb61dc
Rename progress bar .step and .progress methods to reduce ambiguity.
MysticMia May 20, 2025
ad9a555
Clean up PageView typing, __init__, and wrap lines
MysticMia May 20, 2025
8cca9c4
v2 Replace all Interaction type function annotations Interaction[Bot]
MysticMia May 20, 2025
e91b8a2
Make API urls use 'params' instead of manually putting them in the url.
MysticMia May 20, 2025
a8057e8
Ensure wolfram queries can actually use special characters
MysticMia May 22, 2025
c49deb9
Fix broken DMsCheckFailure error and change itx.user.nick to getattr.
MysticMia May 22, 2025
88cc794
Remove page_update_function from PageView and improve documentation
MysticMia May 22, 2025
a70fa50
Fix more discord.Interaction to discord.Interaction[Bot]
MysticMia May 22, 2025
6e83715
Revamp dictionary command
MysticMia May 22, 2025
aed6097
Make API calls async (aiohttp vs requests), so they can be run async.
MysticMia May 23, 2025
1fbdd25
Ensure all dictionaries work as intended (ephemeral, page numbers, bu…
MysticMia May 23, 2025
582b55f
Merge branch 'remove-complexity' into local
MysticMia May 23, 2025
7adc152
Set flake default line width to 79 characters, and apply to last files.
MysticMia May 23, 2025
bd1fe6f
Turn NameUsage GetTopPageView into a PageView (+update GetNameModal)
MysticMia May 23, 2025
0849f1c
fix compliments and fix devrequest not mentioning developer role.
MysticMia May 24, 2025
5ca98fe
Fix remindme with yyyy-mm-dd time format, and split function.
MysticMia May 24, 2025
618451e
Fix remindme with yyyy-mm-dd time format, and split function.
MysticMia May 24, 2025
e1e1050
Fix circular import for permission_checks and move is_staff to .checks
MysticMia May 24, 2025
9f25ff5
Make flake8 by default ignore the rina_docs directory
MysticMia May 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# can also be more harsh :D
# flake8 . --count --ignore=W503,W504 --show-source --statistics --exclude venv,rina_docs
# flake8 . --count --ignore=W503,W504 --show-source --statistics
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --max-complexity=10 --statistics
- name: Test with pytest
Expand Down
Empty file added dir
Empty file.
332 changes: 158 additions & 174 deletions extensions/addons/cogs/funaddons.py

Large diffs are not rendered by default.

280 changes: 190 additions & 90 deletions extensions/addons/cogs/otheraddons.py

Large diffs are not rendered by default.

357 changes: 247 additions & 110 deletions extensions/addons/cogs/searchaddons.py

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions extensions/addons/equaldexregion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EqualDexRegion:
:ivar issues: A list or dictionary of issues related to the laws of
the country.

.. ISO Code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements
.. ISO Code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements # noqa
"""
def __init__(self, data: dict):
"""
Expand All @@ -26,4 +26,7 @@ def __init__(self, data: dict):
self.name: str = data['name']
self.continent = data['continent']
self.url: str = data['url']
self.issues: dict[str, list | dict[str, dict[str]]] = data['issues']
self.issues: dict[
str,
list[str] | dict[str, dict[str, str]]
] = data['issues']
87 changes: 87 additions & 0 deletions extensions/addons/roll.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import collections.abc
import random


def _parse_dice_roll(query: str) -> tuple[int, int | None]:
"""Split the query into dice and faces components."""
# print(query)
parts: list[str | int] = query.split("d")
# 2d4 = ["2","4"]
# 2d3d4 = ["2","3","4"] (huh?)
# 4 = 4
# [] (huh?)
if len(parts) > 2:
raise ValueError("Can't have more than 1 'd' in the "
"query of your die!")
elif len(parts) == 2:
return (
_parse_number("dice", parts[0]),
_parse_number("faces", parts[1])
)
else:
assert len(parts) == 1
# length of `parts` can't be zero if .split() is provided with a
# delimiter. "".split("d") will return a list with
# 1 string: [""]. Only .split() with a whitespace string and
# without split parameters can return an empty list:
# "abcdef".split() -> []
return _parse_number("dice", parts[0]), None


def _parse_number(source: str, value: str) -> int:
"""Parse a string to integer with error handling."""
try:
return int(value)
except ValueError:
raise ValueError(f"Invalid number format for {source}: {value}")


def _validate_dice_and_faces(
dice: int, faces: int
) -> bool:
"""Confirm the values of the dice are within range"""
if faces <= 0:
raise ValueError("Faces count must be positive")
if dice >= 1000000:
raise OverflowError(
f"Sorry, if I let you roll `{dice:,}` dice, the universe will "
f"implode, and Rina will stop responding to commands. "
f"Please stay below 1 million dice..."
)
if faces >= 1000000:
raise OverflowError(
f"Uh.. At that point, you're basically rolling a sphere. Even "
f"earth has less than `{faces:,}` faces. Please bowl with a "
f"sphere of fewer than 1 million faces..."
)

return True


def generate_roll(query: str) -> collections.abc.Generator[int]:
"""
A helper command to generate a dice roll from a dice string
representation "2d6"

:param query: The string representing the dice roll.
:return: A list of outcomes following from the dice roll. 2d6 will
return a list with 2 integers, ranging from 1-6.
:raise ValueError: If the given query does not match the format
"1d2" where "1" and "2" are numbers; or if "2" is negative.
:raise OverflowError: If the number of dice or faces
exceeds 1 000 000.
"""
dice, faces = _parse_dice_roll(query) # raises ValueError
if faces is None:
# it's a constant, not a dice roll
yield dice
return
negative = dice < 0
if negative:
dice = -dice

_validate_dice_and_faces(dice, faces) # raises ValueError, OverflowError

negativity_modifier = -1 if negative else 1
for _ in range(dice):
yield negativity_modifier * random.randint(1, faces)
4 changes: 2 additions & 2 deletions extensions/addons/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = ['SendPublicButtonMath', 'EqualDexAdditionalInfo']

from extensions.addons.views.math_sendpublicbutton import SendPublicButtonMath
from extensions.addons.views.equaldex_additionalinfo import EqualDexAdditionalInfo
from .math_sendpublicbutton import SendPublicButtonMath
from .equaldex_additionalinfo import EqualDexAdditionalInfo
16 changes: 12 additions & 4 deletions extensions/addons/views/math_sendpublicbutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ def __init__(self, timeout=180):
self.timeout = timeout

@discord.ui.button(label='Send Publicly', style=discord.ButtonStyle.gray)
async def send_publicly(self, itx: discord.Interaction[Bot], _button: discord.ui.Button):
async def send_publicly(
self,
itx: discord.Interaction[Bot],
_button: discord.ui.Button
):
self.value = 1
await itx.response.edit_message(content="Sent successfully!")
cmd_mention = itx.client.get_command_mention("math")
await itx.followup.send(f"**{itx.user.mention} shared a {cmd_mention} output:**\n" + itx.message.content,
ephemeral=False, allowed_mentions=discord.AllowedMentions.none())
cmd_math = itx.client.get_command_mention("math")
await itx.followup.send(
f"**{itx.user.mention} shared a {cmd_math} output:**\n"
+ itx.message.content,
ephemeral=False,
allowed_mentions=discord.AllowedMentions.none()
)
10 changes: 6 additions & 4 deletions extensions/changechannel/cogs/changechannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import discord.app_commands as app_commands
import discord.ext.commands as commands

from extensions.settings.objects import ModuleKeys
from resources.checks import module_enabled_check
from resources.customs import Bot

from extensions.settings.objects import ModuleKeys


class ChangeChannel(commands.Cog):
Expand All @@ -14,11 +16,11 @@ class ChangeChannel(commands.Cog):
@module_enabled_check(ModuleKeys.change_channel)
async def changechannel(
self,
itx: discord.Interaction,
itx: discord.Interaction[Bot],
destination: discord.TextChannel
):
itx.response: discord.InteractionResponse # noqa
itx.followup: discord.Webhook # noqa
itx.response: discord.InteractionResponse[Bot] # type: ignore
itx.followup: discord.Webhook # type: ignore

if destination.id == itx.channel.id:
await itx.response.send_message(
Expand Down
Loading