Skip to content
Open
Changes from 2 commits
Commits
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
33 changes: 28 additions & 5 deletions bot/exts/info/pep.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from datetime import UTC, datetime, timedelta
from typing import TypedDict
from rapidfuzz import process

from discord import Colour, Embed
from discord import Colour, Embed, app_commands, Interaction
from discord.ext.commands import Cog, Context, command

from bot.bot import Bot
from bot.log import get_logger
from bot.utils.messages import send_or_reply

Check failure on line 10 in bot/exts/info/pep.py

View workflow job for this annotation

GitHub Actions / lint-test / lint-test

Ruff (I001)

bot/exts/info/pep.py:1:1: I001 Import block is un-sorted or un-formatted

log = get_logger(__name__)

Expand Down Expand Up @@ -72,10 +73,7 @@

return embed

@command(name="pep", aliases=("get_pep", "p"))
async def pep_command(self, ctx: Context, pep_number: int) -> None:
"""Fetches information about a PEP and sends it to the channel."""
# Refresh the PEP data up to every hour, as e.g. the PEP status might have changed.
async def get_pep_embed(self, pep_number: int) -> Embed:

Check failure on line 76 in bot/exts/info/pep.py

View workflow job for this annotation

GitHub Actions / lint-test / lint-test

Ruff (D102)

bot/exts/info/pep.py:76:15: D102 Missing docstring in public method
if (
self.last_refreshed_peps is None or (
(self.last_refreshed_peps + timedelta(hours=1)) <= datetime.now(tz=UTC)
Expand All @@ -93,9 +91,34 @@
description=f"PEP {pep_number} does not exist.",
colour=Colour.red(),
)
return embed

@command(name="pep", aliases=("get_pep", "p"))
async def pep_command(self, ctx: Context, pep_number: int) -> None:
"""Fetches information about a PEP and sends it to the channel."""
# Refresh the PEP data up to every hour, as e.g. the PEP status might have changed.
embed = await self.get_pep_embed(pep_number)
await send_or_reply(ctx, embed)

@app_commands.command(name="pep")
@app_commands.guild_only()
@app_commands.describe(pep_number="The pep number or the autocompleted pep")
async def pep_slash_command(self, interaction: Interaction, pep_number: int) -> bool:

Check failure on line 106 in bot/exts/info/pep.py

View workflow job for this annotation

GitHub Actions / lint-test / lint-test

Ruff (D102)

bot/exts/info/pep.py:106:15: D102 Missing docstring in public method
embed = await self.get_pep_embed(pep_number)
await interaction.response.send_message(embed=embed)

@pep_slash_command.autocomplete("pep_number")
async def pep_slash_command_autocomplete(self, interaction: Interaction, current: str) -> list[app_commands.Choice]:

Check failure on line 111 in bot/exts/info/pep.py

View workflow job for this annotation

GitHub Actions / lint-test / lint-test

Ruff (D102)

bot/exts/info/pep.py:111:15: D102 Missing docstring in public method
if self.last_refreshed_peps is None:
await self.refresh_pep_data()
Comment thread
ChrisLovering marked this conversation as resolved.
Outdated

choices = {pep_id: pep_info["title"] for pep_id, pep_info in self.peps.items()}
Comment thread
ChrisLovering marked this conversation as resolved.
Outdated

# list[('pep_title', similarity, pep_number)]
result = process.extract(query=current, choices=choices, limit=10)
return [app_commands.Choice(name=f"{pep[2]} - {pep[0]}", value=pep[2]) for pep in result]


async def setup(bot: Bot) -> None:
"""Load the PEP cog."""
await bot.add_cog(PythonEnhancementProposals(bot))
Loading