tux.cogs.fun.fact
¶
Classes:
Name | Description |
---|---|
Fact | |
Classes¶
Fact(bot: Tux)
¶
Bases: Cog
Methods:
Name | Description |
---|---|
fact | Get a random fun fact from the specified category. |
Functions¶
fact(ctx: commands.Context[Tux], *, fact_type: str = FactType.RANDOM.value) -> None
async
¶
Get a random fun fact from the specified category.
{0}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ctx | Context[Tux] | The context in which the command is being invoked. | required |
fact_type | str | The category of fact to retrieve. {0} | RANDOM.value |
Source code in tux/cogs/fun/fact.py
Python
@commands.hybrid_command(name="fact", aliases=["funfact"])
@app_commands.describe(fact_type="Select the category of fact to retrieve")
@app_commands.choices(fact_type=[app_commands.Choice(name=ft.value, value=ft.value) for ft in FactType])
@docstring_parameter(
f"Available categories: {', '.join([ft.value for ft in FactType])}. Default category is {FactType.RANDOM.value}.",
)
async def fact(self, ctx: commands.Context[Tux], *, fact_type: str = FactType.RANDOM.value) -> None:
"""
Get a random fun fact from the specified category.
{0}
Parameters
----------
ctx : commands.Context[Tux]
The context in which the command is being invoked.
fact_type : str
The category of fact to retrieve. {0}
"""
# Map selected name back to enum (case-insensitive)
mapping = {ft.value.lower(): ft for ft in FactType}
key = fact_type.lower()
if key not in mapping:
opts = ", ".join(ft.value for ft in FactType)
await ctx.send(f"Invalid category '{fact_type}'. Available: {opts}.")
return
sel = mapping[key]
# Pick a random fact
facts = fact_type_map.get(sel, [])
description = random.choice(facts) if facts else "No facts available for this category."
embed = EmbedCreator.create_embed(
bot=self.bot,
embed_type=EmbedCreator.INFO,
user_name=ctx.author.name,
user_display_avatar=ctx.author.display_avatar.url,
title=f"Fun Fact ({sel.value})",
description=description,
custom_author_text="Click here to submit more facts!",
custom_author_text_url="https://github.com/allthingslinux/tux/blob/main/tux/cogs/fun/fact.py",
custom_author_icon_url="https://github.com/allthingslinux/tux/blob/main/assets/emojis/tux_info.png?raw=true",
)
# Send the fact embed
await ctx.send(embed=embed)