tux.cogs.fun.fact
¶
Classes:
Name | Description |
---|---|
Fact | |
Classes¶
Fact(bot: Tux)
¶
Bases: Cog
Methods:
Name | Description |
---|---|
fact | Get a fun fact by category or random. |
Source code in tux/cogs/fun/fact.py
Functions¶
_load_facts() -> None
¶
Load facts from the facts.toml file.
Source code in tux/cogs/fun/fact.py
Python
def _load_facts(self) -> None:
"""Load facts from the facts.toml file."""
facts_path = workspace_root / "assets" / "data" / "facts.toml"
try:
data = tomllib.loads(facts_path.read_text(encoding="utf-8"))
self.facts_data = data.get("facts", {})
logger.info(f"Loaded the following fact categories from facts.toml: {list(self.facts_data.keys())}")
except FileNotFoundError:
logger.warning(f"Facts file not found at {facts_path}")
self.facts_data = {}
except Exception as e:
logger.error(f"Error loading facts: {e}")
self.facts_data = {}
fact(ctx: commands.Context[Tux], fact_type: str = 'random') -> None
async
¶
Get a fun fact by category or random.
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.autocomplete(fact_type=fact_type_autocomplete)
async def fact(self, ctx: commands.Context[Tux], fact_type: str = "random") -> None:
"""Get a fun fact by category or random."""
res = await self._fetch_fact(fact_type)
if res:
fact, category = res
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 ({category})",
description=fact,
custom_author_text="Click here to submit more facts!",
custom_author_text_url="https://github.com/allthingslinux/tux/blob/main/assets/data/facts.toml",
)
else:
names = [
await handle_substitution(self.bot, data.get("name", key.title()))
for key, data in self.facts_data.items()
]
embed = EmbedCreator.create_embed(
bot=self.bot,
embed_type=EmbedCreator.ERROR,
user_name=ctx.author.name,
user_display_avatar=ctx.author.display_avatar.url,
title="Category Not Found",
description=f"Invalid category '{fact_type}'. Available: {', '.join(names)}",
)
await ctx.send(embed=embed)