1
0
Fork 0
mirror of synced 2024-05-19 20:12:30 +12:00

Used commands.has_permissions for a couple of my old predicates

This commit is contained in:
phxntxm 2016-07-12 09:17:47 -05:00
parent 9a516b0628
commit d8ca2de783
7 changed files with 58 additions and 73 deletions

View file

@ -1,5 +1,4 @@
from discord.ext import commands
from .utils import checks
from .utils import config
from threading import Timer
import discord

View file

@ -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):

View file

@ -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))

View file

@ -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)

View file

@ -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:

View file

@ -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()

View file

@ -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