|
|
@ -1,21 +1,21 @@
|
|
|
|
"""Module to manage audio trivia sessions."""
|
|
|
|
"""Module to manage audio trivia sessions."""
|
|
|
|
import asyncio
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
from redbot.cogs.audio import Audio
|
|
|
|
import lavalink
|
|
|
|
from redbot.cogs.trivia import TriviaSession
|
|
|
|
from redbot.cogs.trivia import TriviaSession
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AudioSession(TriviaSession):
|
|
|
|
class AudioSession(TriviaSession):
|
|
|
|
"""Class to run a session of audio trivia"""
|
|
|
|
"""Class to run a session of audio trivia"""
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, ctx, question_list: dict, settings: dict, audio_cog: Audio):
|
|
|
|
def __init__(self, ctx, question_list: dict, settings: dict, player: lavalink.Player):
|
|
|
|
super().__init__(ctx, question_list, settings)
|
|
|
|
super().__init__(ctx, question_list, settings)
|
|
|
|
|
|
|
|
|
|
|
|
self.audio = audio_cog
|
|
|
|
self.player = player
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def start(cls, ctx, question_list, settings, audio_cog: Audio = None):
|
|
|
|
def start(cls, ctx, question_list, settings, player: lavalink.Player = None):
|
|
|
|
session = cls(ctx, question_list, settings, audio_cog)
|
|
|
|
session = cls(ctx, question_list, settings, player)
|
|
|
|
loop = ctx.bot.loop
|
|
|
|
loop = ctx.bot.loop
|
|
|
|
session._task = loop.create_task(session.run())
|
|
|
|
session._task = loop.create_task(session.run())
|
|
|
|
return session
|
|
|
|
return session
|
|
|
@ -36,12 +36,17 @@ class AudioSession(TriviaSession):
|
|
|
|
self.count += 1
|
|
|
|
self.count += 1
|
|
|
|
msg = "**Question number {}!**\n\nName this audio!".format(self.count)
|
|
|
|
msg = "**Question number {}!**\n\nName this audio!".format(self.count)
|
|
|
|
await self.ctx.send(msg)
|
|
|
|
await self.ctx.send(msg)
|
|
|
|
print(question)
|
|
|
|
# print("Audio question: {}".format(question))
|
|
|
|
|
|
|
|
|
|
|
|
# await self.ctx.invoke(self.audio.play(ctx=self.ctx, query=question))
|
|
|
|
# await self.ctx.invoke(self.audio.play(ctx=self.ctx, query=question))
|
|
|
|
await self.ctx.invoke(self.audio.play, query=question)
|
|
|
|
# ctx_copy = copy(self.ctx)
|
|
|
|
|
|
|
|
|
|
|
|
print("after audio.play")
|
|
|
|
# await self.ctx.invoke(self.player.play, query=question)
|
|
|
|
|
|
|
|
query = question.strip("<>")
|
|
|
|
|
|
|
|
tracks = await self.player.get_tracks(query)
|
|
|
|
|
|
|
|
self.player.add(self.ctx.author, tracks[0])
|
|
|
|
|
|
|
|
if not self.player.current:
|
|
|
|
|
|
|
|
await self.player.play()
|
|
|
|
|
|
|
|
|
|
|
|
continue_ = await self.wait_for_answer(answers, delay, timeout)
|
|
|
|
continue_ = await self.wait_for_answer(answers, delay, timeout)
|
|
|
|
if continue_ is False:
|
|
|
|
if continue_ is False:
|
|
|
@ -55,4 +60,4 @@ class AudioSession(TriviaSession):
|
|
|
|
|
|
|
|
|
|
|
|
async def end_game(self):
|
|
|
|
async def end_game(self):
|
|
|
|
await super().end_game()
|
|
|
|
await super().end_game()
|
|
|
|
await self.ctx.invoke(self.audio.disconnect)
|
|
|
|
await self.ctx.invoke(self.player.disconnect)
|
|
|
|