From 1d9888a4567190427b3a3bc6855dae11757207b3 Mon Sep 17 00:00:00 2001 From: Will Tekulve Date: Sun, 28 Feb 2016 16:20:47 -0500 Subject: [PATCH] fix PR-found issues with red"s settings and audio --- cogs/audio.py | 27 +++++++++++++++------------ cogs/utils/settings.py | 19 +++++++++++++++++++ red.py | 7 ++++--- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/cogs/audio.py b/cogs/audio.py index 4502406fc..0ed425271 100644 --- a/cogs/audio.py +++ b/cogs/audio.py @@ -8,6 +8,7 @@ from random import shuffle from .utils.dataIO import fileIO from .utils import checks from __main__ import send_cmd_help +from __main__ import settings as bot_settings import glob import re import aiohttp @@ -69,7 +70,7 @@ class Audio: msg = ctx.message if await self.check_voice(msg.author, msg): if self.is_playlist_valid([link]): # reusing a function - if await self.is_alone_or_admin(msg.author): + if await self.is_alone_or_admin(msg): self.queue = [] self.current = -1 self.playlist = [] @@ -128,7 +129,7 @@ class Audio: """ msg = ctx.message if self.music_player.is_playing(): - if await self.is_alone_or_admin(msg.author): + if await self.is_alone_or_admin(msg): self.music_player.paused = False self.music_player.stop() else: @@ -177,7 +178,7 @@ class Audio: files.extend(glob.glob("data/audio/localtracks/" + name + "/*.mp3")) if glob.glob("data/audio/localtracks/" + name + "/*.flac"): files.extend(glob.glob("data/audio/localtracks/" + name + "/*.flac")) - if await self.is_alone_or_admin(msg.author): + if await self.is_alone_or_admin(msg): if await self.check_voice(msg.author, ctx.message): self.queue = [] self.current = -1 @@ -197,7 +198,7 @@ class Audio: """ msg = ctx.message if self.music_player.is_playing(): - if await self.is_alone_or_admin(msg.author): + if await self.is_alone_or_admin(msg): self.current = -1 self.playlist = [self.downloader["URL"]] await self.bot.say("I will play this song on repeat.") @@ -210,7 +211,7 @@ class Audio: """ msg = ctx.message if self.music_player.is_playing(): - if await self.is_alone_or_admin(msg.author): + if await self.is_alone_or_admin(msg): if self.playlist: shuffle(self.playlist) await self.bot.say("The order of this playlist has been mixed") @@ -223,7 +224,7 @@ class Audio: """ msg = ctx.message if self.music_player.is_playing() and self.playlist: - if await self.is_alone_or_admin(msg.author): + if await self.is_alone_or_admin(msg): self.current -= 2 if self.current == -1: self.current = len(self.playlist) -3 @@ -240,7 +241,7 @@ class Audio: """ msg = ctx.message if self.music_player.is_playing(): - if await self.is_alone_or_admin(msg.author): + if await self.is_alone_or_admin(msg): await self.close_audio() else: await self.bot.say("You can't stop music when there are other people in the channel! Vote to skip instead.") @@ -282,14 +283,16 @@ class Audio: else: await self.bot.say("That link is now allowed.") - async def is_alone_or_admin(self, author): #Direct control. fix everything + async def is_alone_or_admin(self, message): #Direct control. fix everything + author = message.author + server = message.server if not self.settings["QUEUE_MODE"]: return True - elif author.id == checks.settings["OWNER"]: + elif author.id == bot_settings.owner: return True - elif discord.utils.get(author.roles, name=checks.settings["ADMIN_ROLE"]) is not None: + elif discord.utils.get(author.roles, name=bot_settings.get_server_admin(server)) is not None: return True - elif discord.utils.get(author.roles, name=checks.settings["MOD_ROLE"]) is not None: + elif discord.utils.get(author.roles, name=bot_settings.get_server_mod(server)) is not None: return True elif len(author.voice_channel.voice_members) in (1, 2): return True @@ -308,7 +311,7 @@ class Audio: self.queue = [] await self.play_video(rndchoice(self.sing)) else: - if await self.is_alone_or_admin(msg.author): + if await self.is_alone_or_admin(msg): self.queue = [] await self.play_video(rndchoice(self.sing)) else: diff --git a/cogs/utils/settings.py b/cogs/utils/settings.py index ecd4d8dfb..06cbdbfed 100644 --- a/cogs/utils/settings.py +++ b/cogs/utils/settings.py @@ -1,11 +1,13 @@ from .dataIO import fileIO import discord +import os default_path = "data/red/settings.json" class Settings: def __init__(self,path=default_path): self.path = path + self.check_folders() self.default_settings = {"EMAIL" : "EmailHere", "PASSWORD" : "PasswordHere", "OWNER" : "id_here", "PREFIXES" : [], "default":{"ADMIN_ROLE" : "Transistor", "MOD_ROLE" : "Process"}} if not fileIO(self.path,"check"): self.bot_settings = self.default_settings @@ -15,6 +17,13 @@ class Settings: if "default" not in self.bot_settings: self.update_old_settings() + def check_folders(self): + folders = ("data", os.path.dirname(self.path), "cogs", "cogs/utils") + for folder in folders: + if not os.path.exists(folder): + print("Creating " + folder + " folder...") + os.makedirs(folder) + def save_settings(self): fileIO(self.path,"save",self.bot_settings) @@ -39,10 +48,20 @@ class Settings: def email(self): return self.bot_settings["EMAIL"] + @email.setter + def email(self,value): + self.bot_settings["EMAIL"] = value + self.save_settings() + @property def password(self): return self.bot_settings["PASSWORD"] + @password.setter + def password(self,value): + self.bot_settings["PASSWORD"] = value + self.save_settings() + @property def prefixes(self): return self.bot_settings["PREFIXES"] diff --git a/red.py b/red.py index 12c64eb5d..2b50dc209 100644 --- a/red.py +++ b/red.py @@ -348,13 +348,14 @@ def check_configs(): exit(1) print("\nChoose a prefix (or multiple ones, one at once) for the commands. Type exit when you're done. Example prefix: !") - settings.prefixes = [] + prefixes = [] new_prefix = "" - while new_prefix.lower() != "exit" or settings.prefixes == []: + while new_prefix.lower() != "exit" or prefixes == []: new_prefix = input("Prefix> ") if new_prefix.lower() != "exit" and new_prefix != "": - settings.prefixes = settings.prefixes.append(new_prefix) + prefixes.append(new_prefix) #Remember we're using property's here, oh well... + settings.prefixes = prefixes print("\nInput *your own* ID. You can type \@Yourname in chat to see it (copy only the numbers).") print("If you want, you can also do it later with [prefix]set owner. Leave empty in that case.")