Handle some edge cases in !queue

This commit is contained in:
Joscha 2018-08-11 16:36:56 +00:00
parent 7b8fe5509d
commit 4f2ca9c5b6

View file

@ -275,22 +275,19 @@ class ArgonDJBot(yaboli.Bot):
@yaboli.command("queue", "q")
async def command_queue(self, room, message, argstr):
lines = []
video_ids = []
lines_parse_error = []
args = self.parse_args(argstr)
if not args:
await room.send("No videos specified", message.mid)
return
for arg in args:
if arg == "-id": continue
match = re.match(self.YOUTUBE_RE, arg)
if match:
video_ids.append(match.group(self.YOUTUBE_RE_GROUP))
else:
lines.append(f"Could not parse {arg!r}")
lines_parse_error.append(f"Could not parse {arg!r}")
lines = []
lines_api_error = []
videos = await self.yt.get_videos(video_ids)
for vid in video_ids:
video = videos.get(vid)
@ -300,10 +297,15 @@ class ArgonDJBot(yaboli.Bot):
info = Playlist.format_list_entry(video, position, until)
lines.extend(info)
else:
lines_api_error.append(f"Video with id {vid} could not be accessed via the API")
text = "\n".join(lines + lines_parse_error + lines_api_error)
if not lines:
await room.send("No valid videos specified\n" + text, message.mid)
return
text = "\n".join(lines)
await room.send(text, message.mid)
self.playlist.play(room)
@yaboli.command("skip", "s")