Merge pull request #138 from bobloy/audiotrivia_develop

Handle track errors gracefully
pull/143/head
bobloy 4 years ago committed by GitHub
commit c428fa3131
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,8 +1,12 @@
"""Module to manage audio trivia sessions."""
import asyncio
import logging
import lavalink
from redbot.cogs.trivia import TriviaSession
from redbot.core.utils.chat_formatting import bold
log = logging.getLogger("red.fox_v3.audiotrivia.audiosession")
class AudioSession(TriviaSession):
@ -23,9 +27,9 @@ class AudioSession(TriviaSession):
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`.
"""
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"]
@ -36,8 +40,8 @@ class AudioSession(TriviaSession):
self.count += 1
await self.player.stop()
msg = "**Question number {}!**\n\nName this audio!".format(self.count)
await self.ctx.send(msg)
msg = bold(f"Question number {self.count}!") + "\n\nName this audio!"
await self.ctx.maybe_send_embed(msg)
# print("Audio question: {}".format(question))
# await self.ctx.invoke(self.audio.play(ctx=self.ctx, query=question))
@ -45,7 +49,12 @@ class AudioSession(TriviaSession):
# await self.ctx.invoke(self.player.play, query=question)
query = question.strip("<>")
tracks = await self.player.get_tracks(query)
load_result = await self.player.load_tracks(query)
if load_result.has_error:
await self.ctx.maybe_send_embed(f"Track has error, skipping. See logs for details")
log.info(f"Track has error: {load_result.exception_message}")
continue # Skip tracks with error
tracks = load_result.tracks
seconds = tracks[0].length / 1000
if self.settings["repeat"] and seconds < delay:

@ -1,4 +1,5 @@
import datetime
import logging
import pathlib
from typing import List
@ -15,7 +16,7 @@ from redbot.core.utils.chat_formatting import box
from .audiosession import AudioSession
# from redbot.cogs.audio.utils import userlimit
log = logging.getLogger("red.fox_v3.audiotrivia")
class AudioTrivia(Trivia):
@ -166,7 +167,10 @@ class AudioTrivia(Trivia):
# Delay in audiosettings overwrites delay in settings
combined_settings = {**settings, **audiosettings}
session = AudioSession.start(
ctx=ctx, question_list=trivia_dict, settings=combined_settings, player=lavaplayer,
ctx=ctx,
question_list=trivia_dict,
settings=combined_settings,
player=lavaplayer,
)
self.trivia_sessions.append(session)
LOG.debug("New audio trivia session; #%s in %d", ctx.channel, ctx.guild.id)

Loading…
Cancel
Save