trivia: per-category fallbacks, always show model attribution
Lint / Shell (shellcheck) (push) Successful in 10s
Lint / JS (eslint) (push) Successful in 8s
Lint / Python (ruff) (push) Successful in 5s
Lint / Python deps (pip-audit) (push) Successful in 1m14s
Lint / Secret scan (gitleaks) (push) Successful in 10s

- Replace flat fallback list with per-category fallback dict so
  !trivia music never shows a gaming question when AI is down
- Always show "via <model>" tag on AI questions; show warning tag
  on static fallbacks so users know AI was unavailable

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-22 00:05:29 -04:00
parent 876c7d26d4
commit fb39b17473
+107 -25
View File
@@ -814,28 +814,106 @@ _TRIVIA_CATEGORIES = {
"tv": "television, TV shows, sitcoms, dramas, streaming originals, characters, actors",
}
_TRIVIA_FALLBACKS = [
{"q": "What year was the original Super Mario Bros. released?", "options": ["1983", "1985", "1987", "1990"], "answer": 1},
{"q": "Which game features the quote 'The cake is a lie'?", "options": ["Half-Life 2", "Portal", "BioShock", "Minecraft"], "answer": 1},
{"q": "What is the max level in League of Legends?", "options": ["16", "18", "20", "25"], "answer": 1},
{"q": "How many Ender Dragon eggs can exist in a vanilla Minecraft world?", "options": ["1", "2", "Unlimited", "0"], "answer": 0},
{"q": "What was the first battle royale game to hit mainstream popularity?", "options": ["Fortnite", "PUBG", "H1Z1", "Apex Legends"], "answer": 2},
{"q": "In Minecraft, what is the rarest ore?", "options": ["Diamond", "Emerald", "Ancient Debris", "Lapis Lazuli"], "answer": 1},
{"q": "What is the name of the main character in The Legend of Zelda?", "options": ["Zelda", "Link", "Ganondorf", "Epona"], "answer": 1},
{"q": "What type of animal is Sonic?", "options": ["Fox", "Hedgehog", "Rabbit", "Echidna"], "answer": 1},
{"q": "What does GG stand for in gaming?", "options": ["Get Good", "Good Game", "Go Go", "Great Going"], "answer": 1},
{"q": "Which company developed Valorant?", "options": ["Blizzard", "Valve", "Riot Games", "Epic Games"], "answer": 2},
{"q": "What is the highest rank in Valorant?", "options": ["Immortal", "Diamond", "Radiant", "Challenger"], "answer": 2},
{"q": "What does HTTP stand for?", "options": ["HyperText Transfer Protocol", "High Tech Transfer Program", "HyperText Transmission Process", "Home Tool Transfer Protocol"], "answer": 0},
{"q": "What year was Discord founded?", "options": ["2013", "2015", "2017", "2019"], "answer": 1},
{"q": "What programming language has a logo that is a snake?", "options": ["Java", "Ruby", "Python", "Go"], "answer": 2},
{"q": "How many bits are in a byte?", "options": ["4", "8", "16", "32"], "answer": 1},
{"q": "What does 'RGB' stand for?", "options": ["Really Good Build", "Red Green Blue", "Red Gold Black", "Rapid Gaming Boost"], "answer": 1},
{"q": "What does 'AFK' stand for?", "options": ["A Free Kill", "Away From Keyboard", "Always Fun Killing", "Another Fake Knockdown"], "answer": 1},
{"q": "What animal is the Linux mascot?", "options": ["Fox", "Penguin", "Cat", "Dog"], "answer": 1},
{"q": "What does 'NPC' stand for?", "options": ["Non-Player Character", "New Player Content", "Normal Playing Conditions", "Never Played Competitively"], "answer": 0},
{"q": "In what year was the first iPhone released?", "options": ["2005", "2006", "2007", "2008"], "answer": 2},
]
_TRIVIA_FALLBACKS: dict[str, list[dict]] = {
"gaming": [
{"q": "What year was the original Super Mario Bros. released?", "options": ["1983", "1985", "1987", "1990"], "answer": 1},
{"q": "Which game features the quote 'The cake is a lie'?", "options": ["Half-Life 2", "Portal", "BioShock", "Minecraft"], "answer": 1},
{"q": "What is the name of the main character in The Legend of Zelda?", "options": ["Zelda", "Link", "Ganondorf", "Epona"], "answer": 1},
{"q": "What type of animal is Sonic the Hedgehog?", "options": ["Fox", "Hedgehog", "Rabbit", "Echidna"], "answer": 1},
{"q": "Which company developed Valorant?", "options": ["Blizzard", "Valve", "Riot Games", "Epic Games"], "answer": 2},
],
"tech": [
{"q": "What does HTTP stand for?", "options": ["HyperText Transfer Protocol", "High Tech Transfer Program", "HyperText Transmission Process", "Home Tool Transfer Protocol"], "answer": 0},
{"q": "What programming language has a logo that is a snake?", "options": ["Java", "Ruby", "Python", "Go"], "answer": 2},
{"q": "How many bits are in a byte?", "options": ["4", "8", "16", "32"], "answer": 1},
{"q": "What animal is the Linux mascot?", "options": ["Fox", "Penguin", "Cat", "Dog"], "answer": 1},
{"q": "In what year was the first iPhone released?", "options": ["2005", "2006", "2007", "2008"], "answer": 2},
],
"music": [
{"q": "Which band released the album 'Dark Side of the Moon'?", "options": ["Led Zeppelin", "The Beatles", "Pink Floyd", "The Rolling Stones"], "answer": 2},
{"q": "How many strings does a standard guitar have?", "options": ["4", "5", "6", "7"], "answer": 2},
{"q": "Which artist is known as the 'Queen of Pop'?", "options": ["Beyoncé", "Madonna", "Lady Gaga", "Rihanna"], "answer": 1},
{"q": "What decade did hip-hop music originate?", "options": ["1960s", "1970s", "1980s", "1990s"], "answer": 1},
{"q": "Which band had a hit with 'Bohemian Rhapsody'?", "options": ["The Who", "Queen", "Aerosmith", "Bon Jovi"], "answer": 1},
],
"movies": [
{"q": "Which film won the first Academy Award for Best Picture?", "options": ["Wings", "Sunrise", "The Jazz Singer", "Metropolis"], "answer": 0},
{"q": "Who directed Jurassic Park?", "options": ["James Cameron", "George Lucas", "Steven Spielberg", "Ridley Scott"], "answer": 2},
{"q": "What year was the original Star Wars released?", "options": ["1975", "1977", "1979", "1981"], "answer": 1},
{"q": "Which actor plays Iron Man in the MCU?", "options": ["Chris Evans", "Chris Hemsworth", "Robert Downey Jr.", "Mark Ruffalo"], "answer": 2},
{"q": "What is the highest-grossing film of all time (unadjusted)?", "options": ["Avengers: Endgame", "Avatar", "Titanic", "Avatar: The Way of Water"], "answer": 1},
],
"science": [
{"q": "What is the chemical symbol for gold?", "options": ["Go", "Gd", "Au", "Ag"], "answer": 2},
{"q": "How many planets are in our solar system?", "options": ["7", "8", "9", "10"], "answer": 1},
{"q": "What is the speed of light in a vacuum (approximately)?", "options": ["300,000 km/s", "150,000 km/s", "500,000 km/s", "1,000,000 km/s"], "answer": 0},
{"q": "What is the powerhouse of the cell?", "options": ["Nucleus", "Ribosome", "Mitochondria", "Golgi apparatus"], "answer": 2},
{"q": "What gas do plants absorb during photosynthesis?", "options": ["Oxygen", "Nitrogen", "Carbon dioxide", "Hydrogen"], "answer": 2},
],
"general": [
{"q": "How many continents are on Earth?", "options": ["5", "6", "7", "8"], "answer": 2},
{"q": "What is the capital of Japan?", "options": ["Osaka", "Kyoto", "Hiroshima", "Tokyo"], "answer": 3},
{"q": "How many sides does a hexagon have?", "options": ["5", "6", "7", "8"], "answer": 1},
{"q": "What language has the most native speakers in the world?", "options": ["English", "Spanish", "Mandarin Chinese", "Hindi"], "answer": 2},
{"q": "In which year did World War II end?", "options": ["1943", "1944", "1945", "1946"], "answer": 2},
],
"anime": [
{"q": "Which studio produced Spirited Away?", "options": ["Toei Animation", "Madhouse", "Studio Ghibli", "Gainax"], "answer": 2},
{"q": "What is the name of the main character in Naruto?", "options": ["Sasuke", "Naruto Uzumaki", "Kakashi", "Sakura"], "answer": 1},
{"q": "In Dragon Ball Z, what level is above Super Saiyan?", "options": ["Super Saiyan 2", "Ultra Instinct", "Super Saiyan God", "Super Saiyan Blue"], "answer": 0},
{"q": "What is the survey corps symbol in Attack on Titan?", "options": ["A red eagle", "Wings of freedom", "A shield", "A crossed sword"], "answer": 1},
{"q": "Which anime features the 'Ackerman' family?", "options": ["Demon Slayer", "Attack on Titan", "Fullmetal Alchemist", "One Piece"], "answer": 1},
],
"sports": [
{"q": "How many players are on a standard soccer team on the field?", "options": ["9", "10", "11", "12"], "answer": 2},
{"q": "In which city are the Olympic Games traditionally held every four years (summer)?", "options": ["Athens", "Paris", "Los Angeles", "Various cities"], "answer": 3},
{"q": "How many points is a touchdown worth in American football?", "options": ["3", "6", "7", "2"], "answer": 1},
{"q": "What country has won the most FIFA World Cup titles?", "options": ["Germany", "Argentina", "Italy", "Brazil"], "answer": 3},
{"q": "How many sets are in a standard tennis match for men at a Grand Slam?", "options": ["3", "5", "4", "2"], "answer": 1},
],
"food": [
{"q": "What is the main ingredient in guacamole?", "options": ["Tomato", "Avocado", "Lime", "Onion"], "answer": 1},
{"q": "Which country did sushi originate from?", "options": ["China", "Korea", "Japan", "Thailand"], "answer": 2},
{"q": "What type of pastry is a croissant?", "options": ["Choux", "Shortcrust", "Laminated", "Filo"], "answer": 2},
{"q": "What spice gives curry its yellow color?", "options": ["Cumin", "Coriander", "Turmeric", "Paprika"], "answer": 2},
{"q": "How many cups are in a gallon?", "options": ["8", "12", "16", "20"], "answer": 2},
],
"history": [
{"q": "Who was the first President of the United States?", "options": ["John Adams", "Thomas Jefferson", "George Washington", "Benjamin Franklin"], "answer": 2},
{"q": "In what year did the Berlin Wall fall?", "options": ["1987", "1989", "1991", "1993"], "answer": 1},
{"q": "Which empire was ruled by Julius Caesar?", "options": ["Greek", "Ottoman", "Roman", "Byzantine"], "answer": 2},
{"q": "What ancient wonder was located in Alexandria, Egypt?", "options": ["The Colossus", "The Lighthouse", "The Hanging Gardens", "The Mausoleum"], "answer": 1},
{"q": "In which year did the Titanic sink?", "options": ["1910", "1912", "1914", "1916"], "answer": 1},
],
"geography": [
{"q": "What is the longest river in the world?", "options": ["Amazon", "Mississippi", "Yangtze", "Nile"], "answer": 3},
{"q": "What is the capital of Australia?", "options": ["Sydney", "Melbourne", "Brisbane", "Canberra"], "answer": 3},
{"q": "Which country has the most natural lakes?", "options": ["Russia", "United States", "Canada", "Finland"], "answer": 2},
{"q": "What is the smallest country in the world by area?", "options": ["Monaco", "San Marino", "Liechtenstein", "Vatican City"], "answer": 3},
{"q": "On which continent is the Sahara Desert?", "options": ["Asia", "South America", "Australia", "Africa"], "answer": 3},
],
"nature": [
{"q": "What is the fastest land animal?", "options": ["Lion", "Cheetah", "Pronghorn", "Greyhound"], "answer": 1},
{"q": "How many hearts does an octopus have?", "options": ["1", "2", "3", "4"], "answer": 2},
{"q": "What is the tallest type of tree in the world?", "options": ["Douglas Fir", "Giant Sequoia", "Coast Redwood", "Sitka Spruce"], "answer": 2},
{"q": "What percentage of Earth's surface is covered by water?", "options": ["51%", "61%", "71%", "81%"], "answer": 2},
{"q": "Which animal has the longest lifespan?", "options": ["Elephant", "Greenland Shark", "Giant Tortoise", "Bowhead Whale"], "answer": 1},
],
"mythology": [
{"q": "Who is the Greek god of the sea?", "options": ["Zeus", "Hades", "Poseidon", "Apollo"], "answer": 2},
{"q": "In Norse mythology, what is the name of the world tree?", "options": ["Bifrost", "Asgard", "Yggdrasil", "Valhalla"], "answer": 2},
{"q": "Who is the Egyptian god of the dead?", "options": ["Ra", "Anubis", "Osiris", "Horus"], "answer": 2},
{"q": "In Greek mythology, who flew too close to the sun?", "options": ["Daedalus", "Icarus", "Orpheus", "Prometheus"], "answer": 1},
{"q": "What is the name of Thor's hammer in Norse mythology?", "options": ["Gungnir", "Mjolnir", "Excalibur", "Fragarach"], "answer": 1},
],
"tv": [
{"q": "How many seasons does Breaking Bad have?", "options": ["3", "4", "5", "6"], "answer": 2},
{"q": "In The Office (US), what is the name of the paper company?", "options": ["Dundler Mifflin", "Dunder Mifflin", "Dundy Mifflin", "Dunder Miffing"], "answer": 1},
{"q": "What network airs Game of Thrones?", "options": ["Netflix", "Showtime", "HBO", "AMC"], "answer": 2},
{"q": "How many episodes are in the first season of Stranger Things?", "options": ["6", "7", "8", "9"], "answer": 2},
{"q": "What is the name of the pub in It's Always Sunny in Philadelphia?", "options": ["Paddy's Bar", "Paddy's Pub", "The Irish Rover", "Paddy's Tavern"], "answer": 1},
],
}
# Per-category cache of recently asked question texts (avoids duplicates)
@@ -913,9 +991,13 @@ async def cmd_trivia(client: AsyncClient, room_id: str, sender: str, args: str):
return
question = await _generate_trivia_question(category)
from_llm = question is not None
if question is None:
question = random.choice(_TRIVIA_FALLBACKS)
# LLM unavailable — fall back to a category-appropriate static question
pool = _TRIVIA_FALLBACKS.get(category) or _TRIVIA_FALLBACKS["general"]
question = random.choice(pool)
from_llm = False
else:
from_llm = True
labels = ["\U0001f1e6", "\U0001f1e7", "\U0001f1e8", "\U0001f1e9"] # A B C D regional indicators
label_letters = ["A", "B", "C", "D"]
@@ -930,7 +1012,7 @@ async def cmd_trivia(client: AsyncClient, room_id: str, sender: str, args: str):
f'<em>{question["q"]}</em><br>'
f'<ul>{options_html}</ul>'
f'React with A/B/C/D — answer revealed in 30s!'
+ (f'<br><sup><em>via {_model_label(ASK_MODEL)}</em></sup>' if from_llm else "")
f'<br><sup><em>{"via " + _model_label(ASK_MODEL) if from_llm else "⚠️ AI unavailable — using cached question"}</em></sup>'
)
resp = await send_html(client, room_id, plain, html)