diff --git a/config/config.py b/config/config.py index aef54c94..19b70038 100644 --- a/config/config.py +++ b/config/config.py @@ -18,7 +18,6 @@ VC_TIMOUT_DEFAULT = True #default template setting for VC timeout true= yes, timeout false= no timeout ALLOW_VC_TIMEOUT_EDIT = True #allow or disallow editing the vc_timeout guild setting - STARTUP_MESSAGE = "Starting Bot..." STARTUP_COMPLETE_MESSAGE = "Startup Complete" @@ -44,7 +43,8 @@ SONGINFO_DISLIKES = "Dislikes: " SONGINFO_NOW_PLAYING = "Now Playing" SONGINFO_QUEUE_ADDED = "Added to queue" -SONGINFO_SONGINFO = "Song info" +SONGINFO_SONGINFO = "Now playing" +SONGINFO_UNKNOWN_SITE = "Unknown site :question:" SONGINFO_ERROR = "Error: Unsupported site or age restricted content. To enable age restricted content check the documentation/wiki." SONGINFO_PLAYLIST_QUEUED = "Queued playlist :page_with_curl:" SONGINFO_UNKNOWN_DURATION = "Unknown" @@ -90,4 +90,4 @@ HELP_CHANGECHANNEL_SHORT = "Change the bot channel" HELP_CHANGECHANNEL_LONG = "Change the bot channel to the VC you are in" -ABSOLUTE_PATH = '' #do not modify \ No newline at end of file +ABSOLUTE_PATH = '' #do not modify diff --git a/musicbot/audiocontroller.py b/musicbot/audiocontroller.py index e46ff35f..07950c9b 100644 --- a/musicbot/audiocontroller.py +++ b/musicbot/audiocontroller.py @@ -31,6 +31,8 @@ def __init__(self, bot, guild): self.timer = utils.Timer(self.timeout_handler) + self.ctx = None + @property def volume(self): return self._volume @@ -96,6 +98,11 @@ async def play_song(self, song): self.guild.voice_client.play(discord.FFmpegPCMAudio( song.base_url, before_options='-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5'), after=lambda e: self.next_song(e)) + + sett = utils.guild_to_settings[self.guild] + + if self.ctx is not None and sett.get("announce_tracks"): + await self.ctx.invoke(self.bot.get_command('songinfo')) self.guild.voice_client.source = discord.PCMVolumeTransformer( self.guild.voice_client.source) @@ -327,6 +334,7 @@ async def timeout_handler(self): await self.udisconnect() async def uconnect(self, ctx): + self.ctx = ctx if not ctx.author.voice: await ctx.send(config.NO_GUILD_MESSAGE) diff --git a/musicbot/commands/music.py b/musicbot/commands/music.py index 2bed1a23..270a7b61 100644 --- a/musicbot/commands/music.py +++ b/musicbot/commands/music.py @@ -48,10 +48,12 @@ async def _play_song(self, ctx, *, track: str): if song.origin == linkutils.Origins.Default: - if audiocontroller.current_song != None and len(audiocontroller.playlist.playque) == 0: - await ctx.send(embed=song.info.format_output(config.SONGINFO_NOW_PLAYING)) - else: + sett = utils.guild_to_settings[ctx.guild] + + if audiocontroller.current_song == None or len(audiocontroller.playlist.playque) != 0: await ctx.send(embed=song.info.format_output(config.SONGINFO_QUEUE_ADDED)) + elif not sett.get("announce_tracks"): + await ctx.send(embed=song.info.format_output(config.SONGINFO_NOW_PLAYING)) elif song.origin == linkutils.Origins.Playlist: await ctx.send(config.SONGINFO_PLAYLIST_QUEUED) @@ -128,20 +130,29 @@ async def _queue(self, ctx): playlist = utils.guild_to_audiocontroller[current_guild].playlist - # Embeds are limited to 25 fields + # Embeds are limited to 4096 characters, this is well under that if config.MAX_SONG_PRELOAD > 25: config.MAX_SONG_PRELOAD = 25 - embed = discord.Embed(title=":scroll: Queue [{}]".format( - len(playlist.playque)), color=config.EMBED_COLOR, inline=False) + total_runtime = utils.format_time( + sum([int(song.info.duration if song.info.duration else 0) for song in list(playlist.playque)])) + + embed = discord.Embed(title=":scroll: {} songs in queue | {} total length".format( + len(playlist.playque), total_runtime), color=config.EMBED_COLOR, inline=False) + in_queue_formats = [] for counter, song in enumerate(list(playlist.playque)[:config.MAX_SONG_PRELOAD], start=1): if song.info.title is None: - embed.add_field(name="{}.".format(str(counter)), value="[{}]({})".format( - song.info.webpage_url, song.info.webpage_url), inline=False) + in_queue_formats.append("`{}.` [{}]({}) `{}`".format( + str(counter), song.info.webpage_url, song.info.webpage_url, + utils.format_time(song.info.duration))) else: - embed.add_field(name="{}.".format(str(counter)), value="[{}]({})".format( - song.info.title, song.info.webpage_url), inline=False) + in_queue_formats.append("`{}.` [{}]({}) `{}`".format( + str(counter), song.info.title, song.info.webpage_url, + utils.format_time(song.info.duration))) + + if len(in_queue_formats): + embed.description = '\n'.join(in_queue_formats) await ctx.send(embed=embed) diff --git a/musicbot/settings.py b/musicbot/settings.py index c7bf73a6..3a680d3f 100644 --- a/musicbot/settings.py +++ b/musicbot/settings.py @@ -23,7 +23,8 @@ def __init__(self, guild): "user_must_be_in_vc": True, "button_emote": "", "default_volume": 100, - "vc_timeout": config.VC_TIMOUT_DEFAULT + "vc_timeout": config.VC_TIMOUT_DEFAULT, + "announce_tracks": False } self.reload() @@ -136,6 +137,7 @@ async def process_setting(self, setting, value, ctx): 'button_emote': lambda: self.button_emote(setting, value, ctx), 'default_volume': lambda: self.default_volume(setting, value, ctx), 'vc_timeout': lambda: self.vc_timeout(setting, value, ctx), + 'announce_tracks': lambda: self.announce_tracks(setting, value, ctx), } func = switcher.get(setting) @@ -246,3 +248,11 @@ async def vc_timeout(self, setting, value, ctx): else: await ctx.send("`Error: Value must be True/False`\nUsage: {}set {} True/False".format(config.BOT_PREFIX, setting)) return False + + async def announce_tracks(self, setting, value, ctx): + if value.lower() == "true": + self.config[setting] = True + elif value.lower() == "false": + self.config[setting] = False + else: + await ctx.send("`Error: Value must be True/False`\nUsage: {}set {} True/False".format(config.BOT_PREFIX, setting)) diff --git a/musicbot/utils.py b/musicbot/utils.py index 8544d02c..a810d79a 100644 --- a/musicbot/utils.py +++ b/musicbot/utils.py @@ -78,6 +78,22 @@ async def play_check(ctx): return False +def format_time(duration): + if not duration: + return "00:00" + + hours = duration // 60 // 60 + minutes = duration // 60 % 60 + seconds = duration % 60 + + # Looks like `h:mm:ss` + return "{}{}{:02d}:{:02d}".format( + hours if hours else "", + ":" if hours else "", + minutes, + seconds + ) + class Timer: def __init__(self, callback): self._callback = callback