parent
eecfb821a0
commit
f9606e1c9e
@ -0,0 +1,5 @@
|
|||||||
|
from .audiotrivia import AudioTrivia
|
||||||
|
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(AudioTrivia(bot))
|
@ -0,0 +1,46 @@
|
|||||||
|
"""Module to manage audio trivia sessions."""
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from redbot.cogs.audio import Audio
|
||||||
|
from redbot.cogs.trivia import TriviaSession
|
||||||
|
|
||||||
|
|
||||||
|
class AudioSession(TriviaSession):
|
||||||
|
"""Class to run a session of audio trivia"""
|
||||||
|
|
||||||
|
def __init__(self, ctx, question_list: dict, settings: dict, audio_cog: Audio):
|
||||||
|
super().__init__(ctx, question_list, settings)
|
||||||
|
|
||||||
|
self.audio = audio_cog
|
||||||
|
|
||||||
|
async def run(self):
|
||||||
|
"""Run the audio trivia session.
|
||||||
|
|
||||||
|
In order for the trivia session to be stopped correctly, this should
|
||||||
|
only be called internally by `TriviaSession.start`.
|
||||||
|
"""
|
||||||
|
await self._send_startup_msg()
|
||||||
|
max_score = self.settings["max_score"]
|
||||||
|
delay = self.settings["delay"]
|
||||||
|
timeout = self.settings["timeout"]
|
||||||
|
for question, answers in self._iter_questions():
|
||||||
|
async with self.ctx.typing():
|
||||||
|
await asyncio.sleep(3)
|
||||||
|
self.count += 1
|
||||||
|
msg = "**Question number {}!**\n\nName this audio!".format(self.count)
|
||||||
|
await self.ctx.send(msg)
|
||||||
|
await self.audio.play(self.ctx, question)
|
||||||
|
|
||||||
|
continue_ = await self.wait_for_answer(answers, delay, timeout)
|
||||||
|
if continue_ is False:
|
||||||
|
break
|
||||||
|
if any(score >= max_score for score in self.scores.values()):
|
||||||
|
await self.end_game()
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
await self.ctx.send("There are no more questions!")
|
||||||
|
await self.end_game()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
|||||||
|
from redbot.cogs.trivia import LOG
|
||||||
|
from redbot.cogs.trivia.trivia import InvalidListError, Trivia
|
||||||
|
from redbot.core import Config, checks
|
||||||
|
from redbot.core import commands
|
||||||
|
from redbot.core.bot import Red
|
||||||
|
from .audiosession import AudioSession
|
||||||
|
|
||||||
|
|
||||||
|
class AudioTrivia(Trivia):
|
||||||
|
"""
|
||||||
|
Custom commands
|
||||||
|
Creates commands used to display text and adjust roles
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, bot: Red):
|
||||||
|
super().__init__()
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.group()
|
||||||
|
@commands.guild_only()
|
||||||
|
async def audiotrivia(self, ctx: commands.Context, *categories: str):
|
||||||
|
"""Start trivia session on the specified category.
|
||||||
|
|
||||||
|
You may list multiple categories, in which case the trivia will involve
|
||||||
|
questions from all of them.
|
||||||
|
"""
|
||||||
|
if not categories:
|
||||||
|
await ctx.send_help()
|
||||||
|
return
|
||||||
|
categories = [c.lower() for c in categories]
|
||||||
|
session = self._get_trivia_session(ctx.channel)
|
||||||
|
if session is not None:
|
||||||
|
await ctx.send("There is already an ongoing trivia session in this channel.")
|
||||||
|
return
|
||||||
|
trivia_dict = {}
|
||||||
|
authors = []
|
||||||
|
for category in reversed(categories):
|
||||||
|
# We reverse the categories so that the first list's config takes
|
||||||
|
# priority over the others.
|
||||||
|
try:
|
||||||
|
dict_ = self.get_trivia_list(category)
|
||||||
|
except FileNotFoundError:
|
||||||
|
await ctx.send(
|
||||||
|
"Invalid category `{0}`. See `{1}trivia list`"
|
||||||
|
" for a list of trivia categories."
|
||||||
|
"".format(category, ctx.prefix)
|
||||||
|
)
|
||||||
|
except InvalidListError:
|
||||||
|
await ctx.send(
|
||||||
|
"There was an error parsing the trivia list for"
|
||||||
|
" the `{}` category. It may be formatted"
|
||||||
|
" incorrectly.".format(category)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
trivia_dict.update(dict_)
|
||||||
|
authors.append(trivia_dict.pop("AUTHOR", None))
|
||||||
|
continue
|
||||||
|
return
|
||||||
|
if not trivia_dict:
|
||||||
|
await ctx.send(
|
||||||
|
"The trivia list was parsed successfully, however it appears to be empty!"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
settings = await self.conf.guild(ctx.guild).all()
|
||||||
|
config = trivia_dict.pop("CONFIG", None)
|
||||||
|
if config and settings["allow_override"]:
|
||||||
|
settings.update(config)
|
||||||
|
settings["lists"] = dict(zip(categories, reversed(authors)))
|
||||||
|
session = AudioSession.start(ctx, trivia_dict, settings)
|
||||||
|
self.trivia_sessions.append(session)
|
||||||
|
LOG.debug("New audio trivia session; #%s in %d", ctx.channel, ctx.guild.id)
|
@ -0,0 +1,5 @@
|
|||||||
|
https://www.youtube.com/watch?v=DYWi8qdvWCk:
|
||||||
|
- AK47
|
||||||
|
- AK 47
|
||||||
|
https://www.youtube.com/watch?v=DmuK9Wml88E:
|
||||||
|
- P90
|
@ -0,0 +1,4 @@
|
|||||||
|
https://www.youtube.com/watch?v=FrceWR4XnVU:
|
||||||
|
- shovel knight
|
||||||
|
https://www.youtube.com/watch?v=Fn0khIn2wfc:
|
||||||
|
- super mario world
|
@ -0,0 +1,4 @@
|
|||||||
|
https://www.youtube.com/watch?v=hfyE220BsD0:
|
||||||
|
- holiday
|
||||||
|
https://www.youtube.com/watch?v=Hh3U9iPKeXQ:
|
||||||
|
- sultans of swing
|
@ -0,0 +1,4 @@
|
|||||||
|
https://www.youtube.com/watch?v=Hi1kUdreiWk:
|
||||||
|
- Jinx
|
||||||
|
https://www.youtube.com/watch?v=PNYHFluhOGI:
|
||||||
|
- Teemo
|
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"author": [
|
||||||
|
"Bobloy"
|
||||||
|
],
|
||||||
|
"bot_version": [
|
||||||
|
3,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"description": "Start an Audio Trivia game",
|
||||||
|
"hidden": false,
|
||||||
|
"install_msg": "Thank you for installing Audio trivia! Get started with `[p]help AudioTrivia`",
|
||||||
|
"requirements": [],
|
||||||
|
"short": "Start an Audio Trivia game",
|
||||||
|
"tags": [
|
||||||
|
"fox",
|
||||||
|
"bobloy",
|
||||||
|
"games"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in new issue