From 193663575867c20dec79a39a3d1233d22139f15b Mon Sep 17 00:00:00 2001 From: Twentysix Date: Sun, 21 Feb 2016 14:32:26 +0100 Subject: [PATCH] Added !set status and way to disable songs' titles as status --- cogs/audio.py | 41 ++++++++++++++++++++++++++--------------- red.py | 10 ++++++++++ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/cogs/audio.py b/cogs/audio.py index 9237bb243..bb6d757c9 100644 --- a/cogs/audio.py +++ b/cogs/audio.py @@ -8,6 +8,7 @@ from random import choice as rndchoice from random import shuffle from .utils.dataIO import fileIO from .utils import checks +from __main__ import send_cmd_help import glob import re import aiohttp @@ -44,6 +45,7 @@ class Audio: self.downloader = {"DONE" : False, "TITLE" : False, "ID" : False, "URL" : False, "DURATION" : False, "DOWNLOADING" : False} self.skip_votes = [] self.cleanup_timer = int(time.perf_counter()) + self.past_titles = [] # This is to prevent the audio module from setting the status to None if a status other than a track's title gets set self.sing = ["https://www.youtube.com/watch?v=zGTkAVsrfg8", "https://www.youtube.com/watch?v=cGMWL8cOeAU", "https://www.youtube.com/watch?v=vFrjMq4aL-g", "https://www.youtube.com/watch?v=WROI5WYBU_A", @@ -324,7 +326,7 @@ class Audio: async def _list(self, ctx): """Lists playlists""" if ctx.invoked_subcommand is None: - await self.bot.say("Type help list for info.") + await send_cmd_help(ctx) @_list.command(name="playlist", pass_context=True) async def list_playlist(self, ctx): @@ -387,25 +389,31 @@ class Audio: async def audioset(self, ctx): """Changes audio module settings""" if ctx.invoked_subcommand is None: + await send_cmd_help(ctx) msg = "```" for k, v in self.settings.items(): msg += str(k) + ": " + str(v) + "\n" - msg += "\nType help audioset to see the list of commands.```" + msg += "```" await self.bot.say(msg) @audioset.command(name="queue") - async def queueset(self, status : str): - """Enables/disables queue""" - status = status.lower() - if status == "on" or status == "true": - self.settings["QUEUE_MODE"] = True + async def queueset(self): + """Enables/disables forced queue""" + self.settings["QUEUE_MODE"] = not self.settings["QUEUE_MODE"] + if self.settings["QUEUE_MODE"]: await self.bot.say("Queue mode is now on.") - elif status == "off" or status == "false": - self.settings["QUEUE_MODE"] = False - await self.bot.say("Queue mode is now off.") else: - await self.bot.say("Queue status can be either on or off.") - return + await self.bot.say("Queue mode is now off.") + fileIO("data/audio/settings.json", "save", self.settings) + + @audioset.command(name="status") + async def songstatus(self): + """Enables/disables songs' titles as status""" + self.settings["TITLE_STATUS"] = not self.settings["TITLE_STATUS"] + if self.settings["TITLE_STATUS"]: + await self.bot.say("Songs' titles will show up as status.") + else: + await self.bot.say("Songs' titles will no longer show up as status.") fileIO("data/audio/settings.json", "save", self.settings) @audioset.command() @@ -495,7 +503,9 @@ class Audio: self.music_player = self.bot.voice.create_ffmpeg_player(path + self.downloader["ID"], options='''-filter:a "volume={}"'''.format(self.settings["VOLUME"])) self.music_player.paused = False self.music_player.start() - if path != "": await self.bot.change_status(discord.Game(name=self.downloader["TITLE"])) + if path != "" and self.settings["TITLE_STATUS"]: + self.past_titles.append(self.downloader["TITLE"]) + await self.bot.change_status(discord.Game(name=self.downloader["TITLE"])) except discord.errors.ClientException: print("Error: I can't play music without ffmpeg. Install it.") self.downloader = {"DONE" : False, "TITLE" : False, "ID" : False, "URL": False, "DURATION" : False, "DOWNLOADING" : False} @@ -587,7 +597,8 @@ class Audio: if msg.channel.is_private and msg.attachments != []: await self.transfer_playlist(msg) if not msg.channel.is_private: - if not self.playlist and not self.queue and not self.music_player.is_playing() and msg.server.me.game != None: + if not self.playlist and not self.queue and not self.music_player.is_playing() and str(msg.server.me.game) in self.past_titles: + self.past_titles = [] await self.bot.change_status(None) def get_local_playlists(self): @@ -744,7 +755,7 @@ def check_folders(): def check_files(): - default = {"VOLUME" : 0.5, "MAX_LENGTH" : 3700, "QUEUE_MODE" : True, "MAX_CACHE" : 0, "SOUNDCLOUD_CLIENT_ID": None} + default = {"VOLUME" : 0.5, "MAX_LENGTH" : 3700, "QUEUE_MODE" : True, "MAX_CACHE" : 0, "SOUNDCLOUD_CLIENT_ID": None, "TITLE_STATUS" : True} settings_path = "data/audio/settings.json" if not os.path.isfile(settings_path): diff --git a/red.py b/red.py index 5ee1f7310..bf110e9de 100644 --- a/red.py +++ b/red.py @@ -209,6 +209,16 @@ async def name(ctx, *name : str): await bot.edit_profile(settings["PASSWORD"], username=" ".join(name)) await bot.say("Done.") +@_set.command(pass_context=True) +@checks.is_owner() +async def status(ctx, *status : str): + """Sets Red's status""" + if status != (): + await bot.change_status(discord.Game(name=" ".join(status))) + else: + await self.bot.change_status(None) + await bot.say("Done.") + @bot.command() @checks.is_owner() async def shutdown():