Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions src/bot/cogs/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
from discord.app_commands import Choice


WEBPAGE_CHOICES: tuple[Choice[str], ...] = (
Choice(name="Home", value=""),
Choice(name="Getting started", value="getting-started/"),
Choice(name="Resources", value="resources/"),
Choice(name="Projects", value="projects/"),
Choice(name="Rules", value="rules/"),
Choice(name="Code Adventure", value="code-adventure/"),
Choice(name="Learning path", value="resources/learning-path/"),
Choice(name="Codeblocks", value="rules/channels/#__tabbed_2_1"),
)

LATEX_COLORS = {
"emerald": "Emerald",
"violet": "Violet",
Expand Down
47 changes: 47 additions & 0 deletions src/bot/cogs/features/link_to.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Command that links to the official server site.
"""

import logging

from discord import Interaction, app_commands
from discord.ext import commands

from ..constants import WEBPAGE_CHOICES

logger = logging.getLogger(__name__)

SITE_LINK: str = "https://www.practicalpython.org/"


class LinkTo(commands.Cog):
"""Creates a link to the server website or one of its pages."""

def __init__(self, bot: commands.Bot):
self.bot = bot

@app_commands.command(description="Links to the official server site.")
@app_commands.describe(page="Site page to link to.")
@app_commands.choices(page=WEBPAGE_CHOICES)
async def link_to(
self, interaction: Interaction, *, page: app_commands.Choice[str] | None = None
) -> None:
"""
Send message with desired link.

Parameters
----------
page : app_commands.Choice[str] | None
Selected site page or the homepage as default.
"""
logger.info(
"%s used the %s command.", interaction.user.name, interaction.command.name
)

page = page or WEBPAGE_CHOICES[0]
await interaction.response.send_message(f"{page.name}: {SITE_LINK}{page.value}")


async def setup(bot: commands.Bot) -> None:
"""Required."""
await bot.add_cog(LinkTo(bot))
Loading