diff --git a/cogs/interaction.py b/cogs/interaction.py index 976a6a9..15c33c6 100644 --- a/cogs/interaction.py +++ b/cogs/interaction.py @@ -1,5 +1,4 @@ from discord.ext import commands -from .utils import checks from .utils import config from threading import Timer import discord diff --git a/cogs/mod.py b/cogs/mod.py index a97c93c..ba5de29 100644 --- a/cogs/mod.py +++ b/cogs/mod.py @@ -16,7 +16,7 @@ class Mod: await self.bot.say('Invalid subcommand passed: {0.subcommand_passed}'.format(ctx)) @nsfw.command(name="add", pass_context=True) - @checks.isMod() + @commands.has_permissions(kick_members=True) async def nsfw_add(self, ctx): """Registers this channel as a 'nsfw' channel""" cursor = config.getCursor() @@ -31,7 +31,7 @@ class Mod: await self.bot.say("This channel has just been registered as 'nsfw'! Have fun you naughties ;)") @nsfw.command(name="remove", aliases=["delete"], pass_context=True) - @checks.isMod() + @commands.has_permissions(kick_members=True) async def nsfw_remove(self, ctx): """Removes this channel as a 'nsfw' channel""" cursor = config.getCursor() @@ -47,62 +47,19 @@ class Mod: await self.bot.say("This channel has just been unregistered as a nsfw channel") @commands.command(pass_context=True, no_pm=True) - @checks.isAdmin() + @commands.has_permissions(manage_server=True) async def leave(self, ctx): """Forces the bot to leave the server""" await self.bot.say('Why must I leave? Hopefully I can come back :c') await self.bot.leave_server(ctx.message.server) @commands.command(pass_context=True) - @checks.isMod() + @commands.has_permissions(kick_members=True) async def say(self, ctx, *msg: str): """Tells the bot to repeat what you say""" msg = ' '.join(msg) await self.bot.say(msg) await self.bot.delete_message(ctx.message) - - @commands.command() - @checks.isAdmin() - async def load(self, *, module : str): - """Loads a module""" - try: - module = module.lower() - if not module.startswith("cogs"): - module = "cogs.{}".format(module) - self.bot.load_extension(module) - await self.bot.say("I have just loaded the {} module".format(module)) - except Exception as e: - fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' - await self.bot.say(fmt.format(type(e).__name__, e)) - - @commands.command() - @checks.isAdmin() - async def unload(self, *, module : str): - """Unloads a module""" - try: - module = module.lower() - if not module.startswith("cogs"): - module = "cogs.{}".format(module) - self.bot.unload_extension(module) - await self.bot.say("I have just unloaded the {} module".format(module)) - except Exception as e: - fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' - await self.bot.say(fmt.format(type(e).__name__, e)) - - @commands.command() - @checks.isAdmin() - async def reload(self, *, module : str): - """Reloads a module""" - try: - module = module.lower() - if not module.startswith("cogs"): - module = "cogs.{}".format(module) - self.bot.unload_extension(module) - self.bot.load_extension(module) - await self.bot.say("I have just reloaded the {} module".format(module)) - except Exception as e: - fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' - await self.bot.say(fmt.format(type(e).__name__, e)) def setup(bot): diff --git a/cogs/owner.py b/cogs/owner.py index e83ca6e..8d453e2 100644 --- a/cogs/owner.py +++ b/cogs/owner.py @@ -82,6 +82,49 @@ class Owner: await self.bot.change_status(game) await self.bot.say("Just changed my status to '{0}'!".format(newStatus)) + @commands.command() + @checks.isOwner() + async def load(self, *, module: str): + """Loads a module""" + try: + module = module.lower() + if not module.startswith("cogs"): + module = "cogs.{}".format(module) + self.bot.load_extension(module) + await self.bot.say("I have just loaded the {} module".format(module)) + except Exception as e: + fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' + await self.bot.say(fmt.format(type(e).__name__, e)) + + @commands.command() + @checks.isOwner() + async def unload(self, *, module: str): + """Unloads a module""" + try: + module = module.lower() + if not module.startswith("cogs"): + module = "cogs.{}".format(module) + self.bot.unload_extension(module) + await self.bot.say("I have just unloaded the {} module".format(module)) + except Exception as e: + fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' + await self.bot.say(fmt.format(type(e).__name__, e)) + + @commands.command() + @checks.isOwner() + async def reload(self, *, module: str): + """Reloads a module""" + try: + module = module.lower() + if not module.startswith("cogs"): + module = "cogs.{}".format(module) + self.bot.unload_extension(module) + self.bot.load_extension(module) + await self.bot.say("I have just reloaded the {} module".format(module)) + except Exception as e: + fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' + await self.bot.say(fmt.format(type(e).__name__, e)) + def setup(bot): bot.add_cog(Owner(bot)) diff --git a/cogs/playlist.py b/cogs/playlist.py index f76ac55..706e344 100644 --- a/cogs/playlist.py +++ b/cogs/playlist.py @@ -1,12 +1,10 @@ import asyncio import discord -import traceback from discord.ext import commands -from .utils import checks if not discord.opus.is_loaded(): discord.opus.load_opus('/usr/lib64/libopus.so.0') - + class VoiceEntry: def __init__(self, message, player): @@ -147,7 +145,7 @@ class Music: await state.songs.put(entry) @commands.command(pass_context=True, no_pm=True) - @checks.isMod() + @commands.has_permissions(kick_members=True) async def volume(self, ctx, value: int): """Sets the volume of the currently playing song.""" @@ -158,7 +156,7 @@ class Music: await self.bot.say('Set the volume to {:.0%}'.format(player.volume)) @commands.command(pass_context=True, no_pm=True) - @checks.isMod() + @commands.has_permissions(kick_members=True) async def pause(self, ctx): """Pauses the currently played song.""" state = self.get_voice_state(ctx.message.server) @@ -167,7 +165,7 @@ class Music: player.pause() @commands.command(pass_context=True, no_pm=True) - @checks.isMod() + @commands.has_permissions(kick_members=True) async def resume(self, ctx): """Resumes the currently played song.""" state = self.get_voice_state(ctx.message.server) @@ -176,7 +174,7 @@ class Music: player.resume() @commands.command(pass_context=True, no_pm=True) - @checks.isMod() + @commands.has_permissions(kick_members=True) async def stop(self, ctx): """Stops playing audio and leaves the voice channel. This also clears the queue. @@ -228,7 +226,7 @@ class Music: await self.bot.say('You have already voted to skip this song.') @commands.command(pass_context=True, no_pm=True) - @checks.isMod() + @commands.has_permissions(kick_members=True) async def modskip(self, ctx): """Forces a song skip, can only be used by a moderator""" state = self.get_voice_state(ctx.message.server) diff --git a/cogs/stats.py b/cogs/stats.py index 58d1bb5..caa41a6 100644 --- a/cogs/stats.py +++ b/cogs/stats.py @@ -2,6 +2,7 @@ from discord.ext import commands from discord.utils import find from .utils import config import re +import pymysql class Stats: @@ -47,7 +48,7 @@ class Stats: member = find(lambda m: m.id == r['id'], self.bot.get_all_members()) amount = r['amount'] if member in members: - output += "\n{0.name}: {1} times".format(member,amount) + output += "\n{0.name}: {1} times".format(member, amount) config.closeConnection() await self.bot.say("```{}```".format(output)) except pymysql.ProgrammingError: diff --git a/cogs/twitch.py b/cogs/twitch.py index 75f8f37..06caa39 100644 --- a/cogs/twitch.py +++ b/cogs/twitch.py @@ -31,7 +31,8 @@ async def checkChannels(bot): user = re.search("(?<=twitch.tv/)(.*)", url).group(1) if not live and notify and channelOnline(user): cursor.execute('update twitch set live=1 where user_id="{}"'.format(r['user_id'])) - await bot.send_message(server, "{} has just gone live! View their stream at {}".format(member.name, url)) + await bot.send_message(server, "{} has just gone live! " + "View their stream at {}".format(member.name, url)) elif live and not channelOnline(user): cursor.execute('update twitch set live=0 where user_id="{}"'.format(r['user_id'])) await bot.send_message(server, "{} has just gone offline! Catch them next time they stream at {}" @@ -49,7 +50,7 @@ class Twitch: self.bot = bot @commands.group(pass_context=True, no_pm=True, invoke_without_command=True) - async def twitch(self, ctx, *, member: discord.Member=None): + async def twitch(self, *, member: discord.Member=None): """Use this command to check the twitch info of a user""" if member is not None: cursor = config.getCursor() diff --git a/cogs/utils/checks.py b/cogs/utils/checks.py index b866942..1286044 100644 --- a/cogs/utils/checks.py +++ b/cogs/utils/checks.py @@ -9,20 +9,6 @@ def isOwner(): return commands.check(predicate) -def isMod(): - def predicate(ctx): - return ctx.message.author.top_role.permissions.kick_members - - return commands.check(predicate) - - -def isAdmin(): - def predicate(ctx): - return ctx.message.author.top_role.permissions.manage_server - - return commands.check(predicate) - - def isPM(): def predicate(ctx): return ctx.message.channel.is_private