Merge pull request #142 from bobloy/audiotrivia_develop
Audiotrivia better error detection and some games list fixed
This commit is contained in:
commit
b04e82fa1d
@ -3,6 +3,7 @@ import asyncio
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import lavalink
|
import lavalink
|
||||||
|
from lavalink.enums import LoadType
|
||||||
from redbot.cogs.trivia import TriviaSession
|
from redbot.cogs.trivia import TriviaSession
|
||||||
from redbot.core.utils.chat_formatting import bold
|
from redbot.core.utils.chat_formatting import bold
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ class AudioSession(TriviaSession):
|
|||||||
|
|
||||||
msg = bold(f"Question number {self.count}!") + "\n\nName this audio!"
|
msg = bold(f"Question number {self.count}!") + "\n\nName this audio!"
|
||||||
await self.ctx.maybe_send_embed(msg)
|
await self.ctx.maybe_send_embed(msg)
|
||||||
|
log.debug(f"Audio question: {question}")
|
||||||
# print("Audio question: {}".format(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))
|
||||||
@ -50,22 +52,27 @@ class AudioSession(TriviaSession):
|
|||||||
# await self.ctx.invoke(self.player.play, query=question)
|
# await self.ctx.invoke(self.player.play, query=question)
|
||||||
query = question.strip("<>")
|
query = question.strip("<>")
|
||||||
load_result = await self.player.load_tracks(query)
|
load_result = await self.player.load_tracks(query)
|
||||||
if load_result.has_error:
|
log.debug(f"{load_result.load_type=}")
|
||||||
|
if load_result.has_error or load_result.load_type != LoadType.TRACK_LOADED:
|
||||||
await self.ctx.maybe_send_embed(f"Track has error, skipping. See logs for details")
|
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}")
|
log.info(f"Track has error: {load_result.exception_message}")
|
||||||
continue # Skip tracks with error
|
continue # Skip tracks with error
|
||||||
tracks = load_result.tracks
|
tracks = load_result.tracks
|
||||||
seconds = tracks[0].length / 1000
|
|
||||||
|
track = tracks[0]
|
||||||
|
seconds = track.length / 1000
|
||||||
|
|
||||||
if self.settings["repeat"] and seconds < delay:
|
if self.settings["repeat"] and seconds < delay:
|
||||||
|
# Append it until it's longer than the delay
|
||||||
tot_length = seconds + 0
|
tot_length = seconds + 0
|
||||||
while tot_length < delay:
|
while tot_length < delay:
|
||||||
self.player.add(self.ctx.author, tracks[0])
|
self.player.add(self.ctx.author, track)
|
||||||
tot_length += seconds
|
tot_length += seconds
|
||||||
else:
|
else:
|
||||||
self.player.add(self.ctx.author, tracks[0])
|
self.player.add(self.ctx.author, track)
|
||||||
|
|
||||||
if not self.player.current:
|
if not self.player.current:
|
||||||
|
log.debug("Pressing play")
|
||||||
await self.player.play()
|
await self.player.play()
|
||||||
|
|
||||||
continue_ = await self.wait_for_answer(answers, delay, timeout)
|
continue_ = await self.wait_for_answer(answers, delay, timeout)
|
||||||
|
@ -84,24 +84,24 @@ class AudioTrivia(Trivia):
|
|||||||
self.audio: Audio = self.bot.get_cog("Audio")
|
self.audio: Audio = self.bot.get_cog("Audio")
|
||||||
|
|
||||||
if self.audio is None:
|
if self.audio is None:
|
||||||
await ctx.send("Audio is not loaded. Load it and try again")
|
await ctx.maybe_send_embed("Audio is not loaded. Load it and try again")
|
||||||
return
|
return
|
||||||
|
|
||||||
categories = [c.lower() for c in categories]
|
categories = [c.lower() for c in categories]
|
||||||
session = self._get_trivia_session(ctx.channel)
|
session = self._get_trivia_session(ctx.channel)
|
||||||
if session is not None:
|
if session is not None:
|
||||||
await ctx.send("There is already an ongoing trivia session in this channel.")
|
await ctx.maybe_send_embed("There is already an ongoing trivia session in this channel.")
|
||||||
return
|
return
|
||||||
status = await self.audio.config.status()
|
status = await self.audio.config.status()
|
||||||
notify = await self.audio.config.guild(ctx.guild).notify()
|
notify = await self.audio.config.guild(ctx.guild).notify()
|
||||||
|
|
||||||
if status:
|
if status:
|
||||||
await ctx.send(
|
await ctx.maybe_send_embed(
|
||||||
f"It is recommended to disable audio status with `{ctx.prefix}audioset status`"
|
f"It is recommended to disable audio status with `{ctx.prefix}audioset status`"
|
||||||
)
|
)
|
||||||
|
|
||||||
if notify:
|
if notify:
|
||||||
await ctx.send(
|
await ctx.maybe_send_embed(
|
||||||
f"It is recommended to disable audio notify with `{ctx.prefix}audioset notify`"
|
f"It is recommended to disable audio notify with `{ctx.prefix}audioset notify`"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -110,12 +110,12 @@ class AudioTrivia(Trivia):
|
|||||||
if not ctx.author.voice.channel.permissions_for(
|
if not ctx.author.voice.channel.permissions_for(
|
||||||
ctx.me
|
ctx.me
|
||||||
).connect or self.audio.is_vc_full(ctx.author.voice.channel):
|
).connect or self.audio.is_vc_full(ctx.author.voice.channel):
|
||||||
return await ctx.send("I don't have permission to connect to your channel.")
|
return await ctx.maybe_send_embed("I don't have permission to connect to your channel.")
|
||||||
await lavalink.connect(ctx.author.voice.channel)
|
await lavalink.connect(ctx.author.voice.channel)
|
||||||
lavaplayer = lavalink.get_player(ctx.guild.id)
|
lavaplayer = lavalink.get_player(ctx.guild.id)
|
||||||
lavaplayer.store("connect", datetime.datetime.utcnow())
|
lavaplayer.store("connect", datetime.datetime.utcnow())
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return await ctx.send("Connect to a voice channel first.")
|
return await ctx.maybe_send_embed("Connect to a voice channel first.")
|
||||||
|
|
||||||
lavaplayer = lavalink.get_player(ctx.guild.id)
|
lavaplayer = lavalink.get_player(ctx.guild.id)
|
||||||
lavaplayer.store("channel", ctx.channel.id) # What's this for? I dunno
|
lavaplayer.store("channel", ctx.channel.id) # What's this for? I dunno
|
||||||
@ -123,7 +123,7 @@ class AudioTrivia(Trivia):
|
|||||||
await self.audio.set_player_settings(ctx)
|
await self.audio.set_player_settings(ctx)
|
||||||
|
|
||||||
if not ctx.author.voice or ctx.author.voice.channel != lavaplayer.channel:
|
if not ctx.author.voice or ctx.author.voice.channel != lavaplayer.channel:
|
||||||
return await ctx.send(
|
return await ctx.maybe_send_embed(
|
||||||
"You must be in the voice channel to use the audiotrivia command."
|
"You must be in the voice channel to use the audiotrivia command."
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -135,13 +135,13 @@ class AudioTrivia(Trivia):
|
|||||||
try:
|
try:
|
||||||
dict_ = self.get_audio_list(category)
|
dict_ = self.get_audio_list(category)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
await ctx.send(
|
await ctx.maybe_send_embed(
|
||||||
"Invalid category `{0}`. See `{1}audiotrivia list`"
|
"Invalid category `{0}`. See `{1}audiotrivia list`"
|
||||||
" for a list of trivia categories."
|
" for a list of trivia categories."
|
||||||
"".format(category, ctx.prefix)
|
"".format(category, ctx.prefix)
|
||||||
)
|
)
|
||||||
except InvalidListError:
|
except InvalidListError:
|
||||||
await ctx.send(
|
await ctx.maybe_send_embed(
|
||||||
"There was an error parsing the trivia list for"
|
"There was an error parsing the trivia list for"
|
||||||
" the `{}` category. It may be formatted"
|
" the `{}` category. It may be formatted"
|
||||||
" incorrectly.".format(category)
|
" incorrectly.".format(category)
|
||||||
@ -152,7 +152,7 @@ class AudioTrivia(Trivia):
|
|||||||
continue
|
continue
|
||||||
return
|
return
|
||||||
if not trivia_dict:
|
if not trivia_dict:
|
||||||
await ctx.send(
|
await ctx.maybe_send_embed(
|
||||||
"The trivia list was parsed successfully, however it appears to be empty!"
|
"The trivia list was parsed successfully, however it appears to be empty!"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
AUTHOR: Plab
|
AUTHOR: Plab
|
||||||
https://www.youtube.com/watch?v=--bWm9hhoZo:
|
https://www.youtube.com/watch?v=f9O2Rjn1azc:
|
||||||
- Transistor
|
- Transistor
|
||||||
https://www.youtube.com/watch?v=-4nCbgayZNE:
|
https://www.youtube.com/watch?v=PgUhYFkVdSY:
|
||||||
- Dark Cloud 2
|
- Dark Cloud 2
|
||||||
- Dark Cloud II
|
- Dark Cloud II
|
||||||
https://www.youtube.com/watch?v=-64NlME4lJU:
|
https://www.youtube.com/watch?v=1T1RZttyMwU:
|
||||||
- Mega Man 7
|
- Mega Man 7
|
||||||
- Mega Man VII
|
- Mega Man VII
|
||||||
https://www.youtube.com/watch?v=-AesqnudNuw:
|
https://www.youtube.com/watch?v=AdDbbzuq1vY:
|
||||||
- Mega Man 9
|
- Mega Man 9
|
||||||
- Mega Man IX
|
- Mega Man IX
|
||||||
https://www.youtube.com/watch?v=-BmGDtP2t7M:
|
https://www.youtube.com/watch?v=-BmGDtP2t7M:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user