1
Fork 0
mirror of https://github.com/allthingslinux/tux.git synced 2024-10-02 16:43:12 +00:00

feat(guide.py): add new guide.py file to provide server guide functionality

feat(tools.py): add new tools.py file to provide various tool commands
refactor(tldr.py): remove redundant docstring, rename tldr function to slash_tldr
feat(tldr.py): add prefix_tldr function to support prefix command for TLDR pages

refactor(wiki.py): remove unused import 'app_commands' from discord
style(wiki.py): remove explicit command descriptions for 'arch' and 'atl' commands for cleaner code
docs(wiki.py): simplify function docstrings for 'arch_wiki' and 'atl_wiki' methods for better readability
This commit is contained in:
kzndotsh 2024-07-13 19:40:25 +00:00
parent 9cd1c3e0af
commit e464051cdc
4 changed files with 32 additions and 15 deletions

View file

@ -9,10 +9,6 @@ from tux.utils.embeds import EmbedCreator
class Tldr(commands.Cog):
"""
A discord cog to fetch and display TLDR pages for CLI commands.
"""
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
@ -47,12 +43,11 @@ class Tldr(commands.Cog):
return filtered_commands[:25]
@app_commands.command(name="tldr", description="Show a TLDR page for a CLI command")
@app_commands.describe(command="The CLI command to show the TLDR for")
@app_commands.command(name="tldr")
@app_commands.autocomplete(command=get_autocomplete)
async def tldr(self, interaction: discord.Interaction, command: str) -> None:
async def slash_tldr(self, interaction: discord.Interaction, command: str) -> None:
"""
Fetches and displays a TLDR page of a CLI command.
Show a TLDR page for a CLI command
Parameters:
-----------
@ -74,6 +69,31 @@ class Tldr(commands.Cog):
logger.info(f"{interaction.user} requested TLDR for {command}")
@commands.command(name="tldr")
async def prefix_tldr(self, ctx: commands.Context[commands.Bot], command: str) -> None:
"""
Show a TLDR page for a CLI command
Parameters:
-----------
ctx : commands.Context[commands.Bot]
The context object for the command.
command : str
The command to retrieve the TLDR page for.
"""
tldr_page = self.get_tldr_page(command)
embed = EmbedCreator.create_info_embed(
title=f"TLDR for {command}",
description=tldr_page,
ctx=ctx,
)
await ctx.reply(embed=embed)
logger.info(f"{ctx.author} requested TLDR for {command}")
def get_tldr_page(self, command: str) -> str:
"""
Retrieves the TLDR page for a given command.

View file

@ -1,5 +1,4 @@
import httpx
from discord import app_commands
from discord.ext import commands
from loguru import logger
@ -87,11 +86,10 @@ class Wiki(commands.Cog):
if ctx.invoked_subcommand is None:
await ctx.send_help("wiki")
@wiki.command(name="arch", description="Search the Arch Wiki.")
@app_commands.describe(query="The search query.")
@wiki.command(name="arch")
async def arch_wiki(self, ctx: commands.Context[commands.Bot], query: str) -> None:
"""
Search the Arch Wiki for a given query and return the title and URL of the first search result.
Search the Arch Linux Wiki
Parameters
----------
@ -115,11 +113,10 @@ class Wiki(commands.Cog):
await ctx.reply(embed=embed)
@wiki.command(name="atl", description="Search the All Things Linux Wiki.")
@app_commands.describe(query="The search query.")
@wiki.command(name="atl")
async def atl_wiki(self, ctx: commands.Context[commands.Bot], query: str) -> None:
"""
Search the All Things Linux Wiki for a given query and return the title and URL of the first search result.
Search the All Things Linux Wiki
Parameters
----------