fix PR-found issues with red"s settings and audio

This commit is contained in:
Will Tekulve 2016-02-28 16:20:47 -05:00
parent 4eed137aaa
commit 1d9888a456
3 changed files with 38 additions and 15 deletions

View File

@ -8,6 +8,7 @@ from random import shuffle
from .utils.dataIO import fileIO from .utils.dataIO import fileIO
from .utils import checks from .utils import checks
from __main__ import send_cmd_help from __main__ import send_cmd_help
from __main__ import settings as bot_settings
import glob import glob
import re import re
import aiohttp import aiohttp
@ -69,7 +70,7 @@ class Audio:
msg = ctx.message msg = ctx.message
if await self.check_voice(msg.author, msg): if await self.check_voice(msg.author, msg):
if self.is_playlist_valid([link]): # reusing a function 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.queue = []
self.current = -1 self.current = -1
self.playlist = [] self.playlist = []
@ -128,7 +129,7 @@ class Audio:
""" """
msg = ctx.message msg = ctx.message
if self.music_player.is_playing(): 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.paused = False
self.music_player.stop() self.music_player.stop()
else: else:
@ -177,7 +178,7 @@ class Audio:
files.extend(glob.glob("data/audio/localtracks/" + name + "/*.mp3")) files.extend(glob.glob("data/audio/localtracks/" + name + "/*.mp3"))
if glob.glob("data/audio/localtracks/" + name + "/*.flac"): if glob.glob("data/audio/localtracks/" + name + "/*.flac"):
files.extend(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): if await self.check_voice(msg.author, ctx.message):
self.queue = [] self.queue = []
self.current = -1 self.current = -1
@ -197,7 +198,7 @@ class Audio:
""" """
msg = ctx.message msg = ctx.message
if self.music_player.is_playing(): 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.current = -1
self.playlist = [self.downloader["URL"]] self.playlist = [self.downloader["URL"]]
await self.bot.say("I will play this song on repeat.") await self.bot.say("I will play this song on repeat.")
@ -210,7 +211,7 @@ class Audio:
""" """
msg = ctx.message msg = ctx.message
if self.music_player.is_playing(): 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: if self.playlist:
shuffle(self.playlist) shuffle(self.playlist)
await self.bot.say("The order of this playlist has been mixed") await self.bot.say("The order of this playlist has been mixed")
@ -223,7 +224,7 @@ class Audio:
""" """
msg = ctx.message msg = ctx.message
if self.music_player.is_playing() and self.playlist: 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 self.current -= 2
if self.current == -1: if self.current == -1:
self.current = len(self.playlist) -3 self.current = len(self.playlist) -3
@ -240,7 +241,7 @@ class Audio:
""" """
msg = ctx.message msg = ctx.message
if self.music_player.is_playing(): 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() await self.close_audio()
else: else:
await self.bot.say("You can't stop music when there are other people in the channel! Vote to skip instead.") 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: else:
await self.bot.say("That link is now allowed.") 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"]: if not self.settings["QUEUE_MODE"]:
return True return True
elif author.id == checks.settings["OWNER"]: elif author.id == bot_settings.owner:
return True 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 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 return True
elif len(author.voice_channel.voice_members) in (1, 2): elif len(author.voice_channel.voice_members) in (1, 2):
return True return True
@ -308,7 +311,7 @@ class Audio:
self.queue = [] self.queue = []
await self.play_video(rndchoice(self.sing)) await self.play_video(rndchoice(self.sing))
else: else:
if await self.is_alone_or_admin(msg.author): if await self.is_alone_or_admin(msg):
self.queue = [] self.queue = []
await self.play_video(rndchoice(self.sing)) await self.play_video(rndchoice(self.sing))
else: else:

View File

@ -1,11 +1,13 @@
from .dataIO import fileIO from .dataIO import fileIO
import discord import discord
import os
default_path = "data/red/settings.json" default_path = "data/red/settings.json"
class Settings: class Settings:
def __init__(self,path=default_path): def __init__(self,path=default_path):
self.path = 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"}} self.default_settings = {"EMAIL" : "EmailHere", "PASSWORD" : "PasswordHere", "OWNER" : "id_here", "PREFIXES" : [], "default":{"ADMIN_ROLE" : "Transistor", "MOD_ROLE" : "Process"}}
if not fileIO(self.path,"check"): if not fileIO(self.path,"check"):
self.bot_settings = self.default_settings self.bot_settings = self.default_settings
@ -15,6 +17,13 @@ class Settings:
if "default" not in self.bot_settings: if "default" not in self.bot_settings:
self.update_old_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): def save_settings(self):
fileIO(self.path,"save",self.bot_settings) fileIO(self.path,"save",self.bot_settings)
@ -39,10 +48,20 @@ class Settings:
def email(self): def email(self):
return self.bot_settings["EMAIL"] return self.bot_settings["EMAIL"]
@email.setter
def email(self,value):
self.bot_settings["EMAIL"] = value
self.save_settings()
@property @property
def password(self): def password(self):
return self.bot_settings["PASSWORD"] return self.bot_settings["PASSWORD"]
@password.setter
def password(self,value):
self.bot_settings["PASSWORD"] = value
self.save_settings()
@property @property
def prefixes(self): def prefixes(self):
return self.bot_settings["PREFIXES"] return self.bot_settings["PREFIXES"]

7
red.py
View File

@ -348,13 +348,14 @@ def check_configs():
exit(1) exit(1)
print("\nChoose a prefix (or multiple ones, one at once) for the commands. Type exit when you're done. Example prefix: !") 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 = "" new_prefix = ""
while new_prefix.lower() != "exit" or settings.prefixes == []: while new_prefix.lower() != "exit" or prefixes == []:
new_prefix = input("Prefix> ") new_prefix = input("Prefix> ")
if new_prefix.lower() != "exit" and new_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... #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("\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.") print("If you want, you can also do it later with [prefix]set owner. Leave empty in that case.")