mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-09 20:58:54 -05:00
!play can now search and queues by default if something is playing
Permission checks for playlist start
This commit is contained in:
parent
d1a39a2861
commit
3859092278
@ -579,8 +579,6 @@ class Audio:
|
|||||||
r'^(https?\:\/\/)?(www\.|m\.)?(youtube\.com|youtu\.?be)\/.+$')
|
r'^(https?\:\/\/)?(www\.|m\.)?(youtube\.com|youtu\.?be)\/.+$')
|
||||||
if yt_link.match(url):
|
if yt_link.match(url):
|
||||||
return True
|
return True
|
||||||
if yt_link.match(url):
|
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# TODO: _next_songs_in_queue
|
# TODO: _next_songs_in_queue
|
||||||
@ -1006,9 +1004,11 @@ class Audio:
|
|||||||
except UnauthorizedConnect:
|
except UnauthorizedConnect:
|
||||||
await self.bot.say("I don't have permissions to join your"
|
await self.bot.say("I don't have permissions to join your"
|
||||||
" voice channel.")
|
" voice channel.")
|
||||||
|
return
|
||||||
except UnauthorizedSpeak:
|
except UnauthorizedSpeak:
|
||||||
await self.bot.say("I don't have permissions to speak in your"
|
await self.bot.say("I don't have permissions to speak in your"
|
||||||
" voice channel.")
|
" voice channel.")
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
await self._join_voice_channel(voice_channel)
|
await self._join_voice_channel(voice_channel)
|
||||||
else: # We are connected but not to the right channel
|
else: # We are connected but not to the right channel
|
||||||
@ -1056,8 +1056,9 @@ class Audio:
|
|||||||
await self.bot.say("Nothing playing, nothing to pause.")
|
await self.bot.say("Nothing playing, nothing to pause.")
|
||||||
|
|
||||||
@commands.command(pass_context=True, no_pm=True)
|
@commands.command(pass_context=True, no_pm=True)
|
||||||
async def play(self, ctx, url):
|
async def play(self, ctx, url_or_search_terms):
|
||||||
"""Plays a song"""
|
"""Plays a link / searches and play"""
|
||||||
|
url = url_or_search_terms
|
||||||
server = ctx.message.server
|
server = ctx.message.server
|
||||||
author = ctx.message.author
|
author = ctx.message.author
|
||||||
voice_channel = author.voice_channel
|
voice_channel = author.voice_channel
|
||||||
@ -1065,8 +1066,8 @@ class Audio:
|
|||||||
# Checking if playing in current server
|
# Checking if playing in current server
|
||||||
|
|
||||||
if self.is_playing(server):
|
if self.is_playing(server):
|
||||||
await self.bot.say("I'm already playing a song on this server!")
|
await self._queue.callback(self, ctx, url)
|
||||||
return # TODO: Possibly execute queue?
|
return # Default to queue
|
||||||
|
|
||||||
# Checking already connected, will join if not
|
# Checking already connected, will join if not
|
||||||
|
|
||||||
@ -1082,9 +1083,11 @@ class Audio:
|
|||||||
except UnauthorizedConnect:
|
except UnauthorizedConnect:
|
||||||
await self.bot.say("I don't have permissions to join your"
|
await self.bot.say("I don't have permissions to join your"
|
||||||
" voice channel.")
|
" voice channel.")
|
||||||
|
return
|
||||||
except UnauthorizedSpeak:
|
except UnauthorizedSpeak:
|
||||||
await self.bot.say("I don't have permissions to speak in your"
|
await self.bot.say("I don't have permissions to speak in your"
|
||||||
" voice channel.")
|
" voice channel.")
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
await self._join_voice_channel(voice_channel)
|
await self._join_voice_channel(voice_channel)
|
||||||
else: # We are connected but not to the right channel
|
else: # We are connected but not to the right channel
|
||||||
@ -1099,11 +1102,12 @@ class Audio:
|
|||||||
await self.bot.say("I'm already downloading a file!")
|
await self.bot.say("I'm already downloading a file!")
|
||||||
return
|
return
|
||||||
|
|
||||||
if caller == "yt_search":
|
if "." in url:
|
||||||
url = "[SEARCH:]" + url
|
if not self._valid_playable_url(url):
|
||||||
elif not self._valid_playable_url(url):
|
|
||||||
await self.bot.say("That's not a valid URL.")
|
await self.bot.say("That's not a valid URL.")
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
url = "[SEARCH:]" + url
|
||||||
|
|
||||||
self._stop_player(server)
|
self._stop_player(server)
|
||||||
self._clear_queue(server)
|
self._clear_queue(server)
|
||||||
@ -1253,6 +1257,7 @@ class Audio:
|
|||||||
async def playlist_start(self, ctx, name):
|
async def playlist_start(self, ctx, name):
|
||||||
"""Plays a playlist."""
|
"""Plays a playlist."""
|
||||||
server = ctx.message.server
|
server = ctx.message.server
|
||||||
|
author = ctx.message.author
|
||||||
voice_channel = ctx.message.author.voice_channel
|
voice_channel = ctx.message.author.voice_channel
|
||||||
|
|
||||||
caller = inspect.currentframe().f_back.f_code.co_name
|
caller = inspect.currentframe().f_back.f_code.co_name
|
||||||
@ -1263,8 +1268,22 @@ class Audio:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self._playlist_exists(server, name):
|
if self._playlist_exists(server, name):
|
||||||
# TODO: permissions checks...
|
|
||||||
if not self.voice_connected(server):
|
if not self.voice_connected(server):
|
||||||
|
try:
|
||||||
|
can_connect = self.has_connect_perm(author, server)
|
||||||
|
except AuthorNotConnected:
|
||||||
|
await self.bot.say("You must join a voice channel before I can"
|
||||||
|
" play anything.")
|
||||||
|
return
|
||||||
|
except UnauthorizedConnect:
|
||||||
|
await self.bot.say("I don't have permissions to join your"
|
||||||
|
" voice channel.")
|
||||||
|
return
|
||||||
|
except UnauthorizedSpeak:
|
||||||
|
await self.bot.say("I don't have permissions to speak in your"
|
||||||
|
" voice channel.")
|
||||||
|
return
|
||||||
|
else:
|
||||||
await self._join_voice_channel(voice_channel)
|
await self._join_voice_channel(voice_channel)
|
||||||
self._clear_queue(server)
|
self._clear_queue(server)
|
||||||
playlist = self._load_playlist(server, name,
|
playlist = self._load_playlist(server, name,
|
||||||
@ -1304,9 +1323,12 @@ class Audio:
|
|||||||
" queue to modify. This should never"
|
" queue to modify. This should never"
|
||||||
" happen.")
|
" happen.")
|
||||||
|
|
||||||
|
if "." in url:
|
||||||
if not self._valid_playable_url(url):
|
if not self._valid_playable_url(url):
|
||||||
await self.bot.say("Invalid URL.")
|
await self.bot.say("That's not a valid URL.")
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
url = "[SEARCH:]" + url
|
||||||
|
|
||||||
# We have a queue to modify
|
# We have a queue to modify
|
||||||
if self.queue[server.id]["PLAYLIST"]:
|
if self.queue[server.id]["PLAYLIST"]:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user