2016-07-09 13:27:19 +12:00
|
|
|
from discord.ext import commands
|
|
|
|
from .utils import checks
|
2016-07-10 03:17:54 +12:00
|
|
|
from .utils import config
|
2016-09-29 12:39:34 +13:00
|
|
|
|
2016-07-16 02:58:10 +12:00
|
|
|
import discord
|
2016-07-17 00:27:10 +12:00
|
|
|
import re
|
2016-08-26 17:12:54 +12:00
|
|
|
import asyncio
|
2016-09-29 12:39:34 +13:00
|
|
|
import rethinkdb as r
|
2016-07-16 02:58:10 +12:00
|
|
|
|
2016-08-13 05:37:29 +12:00
|
|
|
valid_perms = [p for p in dir(discord.Permissions) if isinstance(getattr(discord.Permissions, p), property)]
|
2016-07-16 09:39:26 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
class Mod:
|
2016-07-09 13:59:10 +12:00
|
|
|
"""Commands that can be used by a or an admin, depending on the command"""
|
2016-07-16 09:39:26 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
2016-08-13 05:37:29 +12:00
|
|
|
|
2016-09-29 12:39:34 +13:00
|
|
|
def find_command(self, command):
|
|
|
|
# This method ensures the command given is valid. We need to loop through commands
|
|
|
|
# As self.bot.commands only includes parent commands
|
|
|
|
# So we are splitting the command in parts, looping through the commands
|
|
|
|
# And getting the subcommand based on the next part
|
|
|
|
# If we try to access commands of a command that isn't a group
|
|
|
|
# We'll hit an AttributeError, meaning an invalid command was given
|
|
|
|
# If we loop through and don't find anything, cmd will still be None
|
|
|
|
# And we'll report an invalid was given as well
|
|
|
|
cmd = None
|
|
|
|
|
|
|
|
for part in command.split():
|
|
|
|
try:
|
|
|
|
if cmd is None:
|
|
|
|
cmd = self.bot.commands.get(part)
|
|
|
|
else:
|
|
|
|
cmd = cmd.commands.get(part)
|
|
|
|
except AttributeError:
|
|
|
|
cmd = None
|
|
|
|
break
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
|
2016-08-12 07:00:24 +12:00
|
|
|
@commands.command(pass_context=True, no_pm=True)
|
2016-08-15 14:10:12 +12:00
|
|
|
@checks.custom_perms(kick_members=True)
|
2016-08-12 07:04:25 +12:00
|
|
|
async def alerts(self, ctx, channel: discord.Channel):
|
2016-08-12 07:00:24 +12:00
|
|
|
"""This command is used to set a channel as the server's 'notifications' channel
|
|
|
|
Any notifications (like someone going live on Twitch, or Picarto) will go to that channel"""
|
2016-09-29 12:39:34 +13:00
|
|
|
r_filter = {'server_id': ctx.message.server.id}
|
|
|
|
entry = {'server_id': ctx.message.server.id,
|
2016-09-29 15:20:15 +13:00
|
|
|
'channel_id': channel.id}
|
2016-09-29 12:39:34 +13:00
|
|
|
if not await config.add_content('server_alerts', entry, r_filter):
|
|
|
|
await config.update_content('server_alerts', entry, r_filter)
|
2016-08-12 07:02:47 +12:00
|
|
|
await self.bot.say("I have just changed this server's 'notifications' channel"
|
2016-08-12 07:33:19 +12:00
|
|
|
"\nAll notifications will now go to `{}`".format(channel))
|
2016-08-13 05:37:29 +12:00
|
|
|
|
2016-08-02 04:10:20 +12:00
|
|
|
@commands.command(pass_context=True, no_pm=True)
|
2016-08-15 14:10:12 +12:00
|
|
|
@checks.custom_perms(kick_members=True)
|
2016-08-13 05:37:29 +12:00
|
|
|
async def usernotify(self, ctx, on_off: str):
|
2016-08-02 04:10:20 +12:00
|
|
|
"""This command can be used to set whether or not you want user notificaitons to show
|
|
|
|
This will save what channel you run this command in, that will be the channel used to send the notification to
|
|
|
|
Provide on, yes, or true to set it on; otherwise it will be turned off"""
|
2016-08-18 08:46:20 +12:00
|
|
|
# Join/Leave notifications can be kept separate from normal alerts
|
|
|
|
# So we base this channel on it's own and not from alerts
|
2016-08-16 15:30:52 +12:00
|
|
|
# When mod logging becomes available, that will be kept to it's own channel if wanted as well
|
2016-08-13 05:37:29 +12:00
|
|
|
on_off = ctx.message.channel.id if re.search("(on|yes|true)", on_off.lower()) else None
|
2016-09-29 12:39:34 +13:00
|
|
|
r_filter = {'server_id': ctx.message.server.id}
|
|
|
|
entry = {'server_id': ctx.message.server.id,
|
|
|
|
'channel_id': on_off}
|
|
|
|
if not await config.add_content('user_notifications', entry, r_filter):
|
|
|
|
await config.update_content('user_notifications', entry, r_filter)
|
2016-08-12 07:33:19 +12:00
|
|
|
fmt = "notify" if on_off else "not notify"
|
2016-08-02 04:10:20 +12:00
|
|
|
await self.bot.say("This server will now {} if someone has joined or left".format(fmt))
|
2016-08-13 05:37:29 +12:00
|
|
|
|
2016-07-16 23:42:44 +12:00
|
|
|
@commands.group(pass_context=True, no_pm=True)
|
2016-07-10 07:39:32 +12:00
|
|
|
async def nsfw(self, ctx):
|
2016-07-10 07:40:51 +12:00
|
|
|
"""Handles adding or removing a channel as a nsfw channel"""
|
2016-08-16 15:30:52 +12:00
|
|
|
# This command isn't meant to do anything, so just send an error if an invalid subcommand is passed
|
2016-07-10 07:38:48 +12:00
|
|
|
if ctx.invoked_subcommand is None:
|
|
|
|
await self.bot.say('Invalid subcommand passed: {0.subcommand_passed}'.format(ctx))
|
2016-07-16 09:39:26 +12:00
|
|
|
|
2016-07-16 23:42:44 +12:00
|
|
|
@nsfw.command(name="add", pass_context=True, no_pm=True)
|
2016-08-15 14:10:12 +12:00
|
|
|
@checks.custom_perms(kick_members=True)
|
2016-07-10 07:38:48 +12:00
|
|
|
async def nsfw_add(self, ctx):
|
2016-07-10 06:27:14 +12:00
|
|
|
"""Registers this channel as a 'nsfw' channel"""
|
2016-09-29 12:39:34 +13:00
|
|
|
r_filter = {'channel_id': ctx.message.channel.id}
|
|
|
|
if await config.add_content('nsfw_channels', r_filter, r_filter):
|
2016-07-29 04:59:12 +12:00
|
|
|
await self.bot.say("This channel has just been registered as 'nsfw'! Have fun you naughties ;)")
|
2016-09-29 12:39:34 +13:00
|
|
|
else:
|
|
|
|
await self.bot.say("This channel is already registered as 'nsfw'!")
|
2016-07-16 09:39:26 +12:00
|
|
|
|
2016-07-18 09:10:12 +12:00
|
|
|
@nsfw.command(name="remove", aliases=["delete"], pass_context=True, no_pm=True)
|
2016-08-15 14:10:12 +12:00
|
|
|
@checks.custom_perms(kick_members=True)
|
2016-07-18 09:10:12 +12:00
|
|
|
async def nsfw_remove(self, ctx):
|
2016-07-10 04:28:18 +12:00
|
|
|
"""Removes this channel as a 'nsfw' channel"""
|
2016-09-29 12:39:34 +13:00
|
|
|
r_filter = {'channel_id': ctx.message.channel.id}
|
|
|
|
if await config.remove_content('nsfw_channels', r_filter):
|
2016-07-29 04:59:12 +12:00
|
|
|
await self.bot.say("This channel has just been unregistered as a nsfw channel")
|
2016-09-29 12:39:34 +13:00
|
|
|
else:
|
|
|
|
await self.bot.say("This channel is not registered as a ''nsfw' channel!")
|
2016-07-16 09:39:26 +12:00
|
|
|
|
2016-07-16 23:42:44 +12:00
|
|
|
@commands.command(pass_context=True, no_pm=True)
|
2016-08-15 14:10:12 +12:00
|
|
|
@checks.custom_perms(kick_members=True)
|
2016-07-29 04:59:12 +12:00
|
|
|
async def say(self, ctx, *, msg: str):
|
2016-07-10 07:14:38 +12:00
|
|
|
"""Tells the bot to repeat what you say"""
|
2016-08-21 11:54:51 +12:00
|
|
|
fmt = "\u200B{}".format(msg)
|
2016-08-26 16:50:09 +12:00
|
|
|
await self.bot.say(fmt)
|
2016-08-22 13:52:27 +12:00
|
|
|
try:
|
|
|
|
await self.bot.delete_message(ctx.message)
|
|
|
|
except:
|
|
|
|
pass
|
2016-07-16 09:39:26 +12:00
|
|
|
|
2016-07-16 23:42:44 +12:00
|
|
|
@commands.group(pass_context=True, invoke_without_command=True, no_pm=True)
|
2016-08-15 14:10:12 +12:00
|
|
|
@checks.custom_perms(send_messages=True)
|
2016-08-13 05:37:29 +12:00
|
|
|
async def perms(self, ctx, *, command: str = None):
|
2016-07-16 10:59:15 +12:00
|
|
|
"""This command can be used to print the current allowed permissions on a specific command
|
|
|
|
This supports groups as well as subcommands; pass no argument to print a list of available permissions"""
|
2016-07-31 14:20:38 +12:00
|
|
|
if command is None:
|
2016-08-13 05:37:29 +12:00
|
|
|
await self.bot.say(
|
|
|
|
"Valid permissions are: ```\n{}```".format("\n".join("{}".format(i) for i in valid_perms)))
|
2016-07-16 07:16:10 +12:00
|
|
|
return
|
2016-07-18 09:10:12 +12:00
|
|
|
|
2016-09-29 12:39:34 +13:00
|
|
|
r_filter = {'server_id': ctx.message.server.id}
|
|
|
|
server_perms = await config.get_content('custom_permissions', r_filter)
|
2016-09-29 15:31:53 +13:00
|
|
|
try:
|
|
|
|
server_perms = server_perms[0]
|
|
|
|
except TypeError:
|
|
|
|
server_perms = {}
|
2016-09-29 12:39:34 +13:00
|
|
|
cmd = self.find_command(command)
|
2016-08-31 10:33:46 +12:00
|
|
|
|
2016-08-29 07:39:28 +12:00
|
|
|
if cmd is None:
|
|
|
|
await self.bot.say("That is not a valid command!")
|
2016-07-16 01:56:13 +12:00
|
|
|
return
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2016-08-29 07:39:28 +12:00
|
|
|
perms_value = server_perms.get(cmd.qualified_name)
|
2016-07-31 00:55:26 +12:00
|
|
|
if perms_value is None:
|
2016-08-29 07:39:28 +12:00
|
|
|
# If we don't find custom permissions, get the required permission for a command
|
2016-08-29 07:40:34 +12:00
|
|
|
# based on what we set in checks.custom_perms, if custom_perms isn't found, we'll get an IndexError
|
2016-08-29 07:39:28 +12:00
|
|
|
try:
|
|
|
|
custom_perms = [func for func in cmd.checks if "custom_perms" in func.__qualname__][0]
|
2016-08-29 07:40:34 +12:00
|
|
|
except IndexError:
|
2016-08-31 10:33:46 +12:00
|
|
|
# Loop through and check if there is a check called is_owner
|
2016-09-29 12:39:34 +13:00
|
|
|
# If we loop through and don't find one, this means that the only other choice is to be
|
2016-08-31 10:33:46 +12:00
|
|
|
# Able to manage the server (for the checks on perm commands)
|
2016-08-29 07:39:28 +12:00
|
|
|
for func in cmd.checks:
|
|
|
|
if "is_owner" in func.__qualname__:
|
|
|
|
await self.bot.say("You need to own the bot to run this command")
|
|
|
|
return
|
2016-08-31 10:33:46 +12:00
|
|
|
await self.bot.say(
|
|
|
|
"You are required to have `manage_server` permissions to run `{}`".format(cmd.qualified_name))
|
2016-08-29 07:39:28 +12:00
|
|
|
return
|
2016-08-31 10:33:46 +12:00
|
|
|
|
2016-09-29 12:39:34 +13:00
|
|
|
# Perms will be an attribute if custom_perms is found no matter what, so no need to check this
|
2016-08-29 07:39:28 +12:00
|
|
|
perms = "\n".join(attribute for attribute, setting in custom_perms.perms.items() if setting)
|
2016-08-31 10:33:46 +12:00
|
|
|
await self.bot.say(
|
|
|
|
"You are required to have `{}` permissions to run `{}`".format(perms, cmd.qualified_name))
|
2016-07-18 03:17:47 +12:00
|
|
|
else:
|
2016-08-16 15:30:52 +12:00
|
|
|
# Permissions are saved as bit values, so create an object based on that value
|
|
|
|
# Then check which permission is true, that is our required permission
|
|
|
|
# There's no need to check for errors here, as we ensure a permission is valid when adding it
|
2016-07-31 00:55:26 +12:00
|
|
|
permissions = discord.Permissions(perms_value)
|
2016-07-31 12:20:55 +12:00
|
|
|
needed_perm = [perm[0] for perm in permissions if perm[1]][0]
|
2016-07-18 09:10:12 +12:00
|
|
|
await self.bot.say("You need to have the permission `{}` "
|
2016-07-31 00:55:26 +12:00
|
|
|
"to use the command `{}` in this server".format(needed_perm, command))
|
2016-07-16 09:39:26 +12:00
|
|
|
|
2016-07-16 23:42:44 +12:00
|
|
|
@perms.command(name="add", aliases=["setup,create"], pass_context=True, no_pm=True)
|
2016-07-17 00:01:32 +12:00
|
|
|
@commands.has_permissions(manage_server=True)
|
2016-07-16 10:18:04 +12:00
|
|
|
async def add_perms(self, ctx, *msg: str):
|
2016-07-16 11:30:46 +12:00
|
|
|
"""Sets up custom permissions on the provided command
|
2016-07-17 00:04:24 +12:00
|
|
|
Format must be 'perms add <command> <permission>'
|
|
|
|
If you want to open the command to everyone, provide 'none' as the permission"""
|
2016-08-18 08:46:20 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
# Since subcommands exist, base the last word in the list as the permission, and the rest of it as the command
|
2016-07-18 09:10:12 +12:00
|
|
|
command = " ".join(msg[0:len(msg) - 1])
|
|
|
|
permissions = msg[len(msg) - 1]
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
# If a user can run a command, they have to have send_messages permissions; so use this as the base
|
2016-07-18 08:24:13 +12:00
|
|
|
if permissions.lower() == "none":
|
2016-07-18 08:56:29 +12:00
|
|
|
permissions = "send_messages"
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2016-09-29 12:39:34 +13:00
|
|
|
# Convert the string to an int value of the permissions object, based on the required permission
|
|
|
|
# If we hit an attribute error, that means the permission given was not correct
|
|
|
|
perm_obj = discord.Permissions.none()
|
|
|
|
try:
|
|
|
|
setattr(perm_obj, permissions, True)
|
|
|
|
except AttributeError:
|
2016-09-18 13:30:20 +12:00
|
|
|
await self.bot.say("{} does not appear to be a valid permission! Valid permissions are: ```\n{}```"
|
|
|
|
.format(permissions, "\n".join(valid_perms)))
|
|
|
|
return
|
2016-07-30 23:58:01 +12:00
|
|
|
perm_value = perm_obj.value
|
2016-08-18 08:46:20 +12:00
|
|
|
|
2016-09-29 12:39:34 +13:00
|
|
|
cmd = self.find_command(command)
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2016-07-30 23:58:01 +12:00
|
|
|
if cmd is None:
|
2016-07-31 12:20:55 +12:00
|
|
|
await self.bot.say(
|
|
|
|
"That command does not exist! You can't have custom permissions on a non-existant command....")
|
2016-07-30 23:58:01 +12:00
|
|
|
return
|
2016-08-18 08:46:20 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
# Two cases I use should never have custom permissions setup on them, is_owner for obvious reasons
|
2016-08-18 08:46:20 +12:00
|
|
|
# The other case is if I'm using the default has_permissions case
|
|
|
|
# Which means I do not want to check custom permissions at all
|
2016-08-16 15:30:52 +12:00
|
|
|
# Currently the second case is only on adding and removing permissions, to avoid abuse on these
|
2016-07-16 10:18:04 +12:00
|
|
|
for check in cmd.checks:
|
2016-08-15 14:10:12 +12:00
|
|
|
if "is_owner" == check.__name__ or re.search("has_permissions", str(check)) is not None:
|
2016-07-16 07:16:10 +12:00
|
|
|
await self.bot.say("This command cannot have custom permissions setup!")
|
|
|
|
return
|
2016-07-16 09:39:26 +12:00
|
|
|
|
2016-09-29 12:39:34 +13:00
|
|
|
r_filter = {'server_id': ctx.message.server.id}
|
|
|
|
entry = {'server_id': ctx.message.server.id,
|
|
|
|
cmd.qualified_name: perm_value}
|
|
|
|
|
|
|
|
# In all other cases, I've used add_content before update_content
|
|
|
|
# In this case, I'm going the other way around, to make the least queries
|
|
|
|
# As custom permissions are probably going to be ran multiple times per server
|
|
|
|
# Whereas in most other cases, the command is probably going to be ran once/few times per server
|
|
|
|
if not await config.update_content('custom_permissions', entry, r_filter):
|
|
|
|
await config.add_content('custom_permissions', entry, r_filter)
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2016-09-29 12:39:34 +13:00
|
|
|
# Same case as prefixes, for now, trigger a manual update
|
|
|
|
self.bot.loop.create_task(config.cache['custom_permissions'].update())
|
2016-07-30 23:58:01 +12:00
|
|
|
await self.bot.say("I have just added your custom permissions; "
|
|
|
|
"you now need to have `{}` permissions to use the command `{}`".format(permissions, command))
|
2016-07-18 09:10:12 +12:00
|
|
|
|
2016-07-16 23:59:28 +12:00
|
|
|
@perms.command(name="remove", aliases=["delete"], pass_context=True, no_pm=True)
|
2016-07-17 00:01:32 +12:00
|
|
|
@commands.has_permissions(manage_server=True)
|
2016-09-29 15:31:53 +13:00
|
|
|
async def remove_perms(self, ctx, *, command: str):
|
2016-08-18 08:46:20 +12:00
|
|
|
"""Removes the custom permissions setup on the command specified"""
|
|
|
|
|
2016-09-29 12:39:34 +13:00
|
|
|
cmd = self.find_command(command)
|
2016-08-16 15:30:52 +12:00
|
|
|
|
|
|
|
if cmd is None:
|
|
|
|
await self.bot.say(
|
|
|
|
"That command does not exist! You can't have custom permissions on a non-existant command....")
|
|
|
|
return
|
2016-08-18 08:46:20 +12:00
|
|
|
|
2016-09-29 12:39:34 +13:00
|
|
|
r_filter = {'server_id': ctx.message.server.id}
|
|
|
|
await config.replace_content('custom_permissions', r.row.without(cmd.qualified_name), r_filter)
|
2016-07-30 23:58:01 +12:00
|
|
|
await self.bot.say("I have just removed the custom permissions for {}!".format(cmd))
|
2016-08-13 05:37:29 +12:00
|
|
|
|
2016-09-29 12:39:34 +13:00
|
|
|
# Same case as prefixes, for now, trigger a manual update
|
|
|
|
self.bot.loop.create_task(config.cache['custom_permissions'].update())
|
|
|
|
|
2016-09-01 07:10:33 +12:00
|
|
|
@commands.command(pass_context=True, no_pm=True)
|
|
|
|
@checks.custom_perms(manage_server=True)
|
|
|
|
async def prefix(self, ctx, *, prefix: str):
|
|
|
|
"""This command can be used to set a custom prefix per server"""
|
2016-09-29 12:39:34 +13:00
|
|
|
r_filter = {'server_id': ctx.message.server.id}
|
|
|
|
if prefix.lower == "none":
|
|
|
|
prefix = None
|
|
|
|
|
|
|
|
entry = {'server_id': ctx.message.server.id,
|
|
|
|
'prefix': prefix}
|
|
|
|
|
|
|
|
if not await config.add_content('prefixes', entry, r_filter):
|
|
|
|
await config.update_content('prefixes', entry, r_filter)
|
|
|
|
# For now, cache is not fully implemented, however is needed for prefixes
|
|
|
|
# So we're going to manually trigger an update when this is ran
|
|
|
|
self.bot.loop.create_task(config.cache['prefixes'].update())
|
|
|
|
|
2016-09-01 07:10:33 +12:00
|
|
|
await self.bot.say(
|
2016-09-29 12:39:34 +13:00
|
|
|
"I have just updated the prefix for this server; you now need to call commands with `{0}`."
|
|
|
|
"For example, you can call this command again with {0}prefix".format(
|
|
|
|
prefix))
|
2016-09-01 07:10:33 +12:00
|
|
|
|
2016-08-08 07:26:44 +12:00
|
|
|
@commands.command(pass_context=True, no_pm=True)
|
2016-08-15 14:10:12 +12:00
|
|
|
@checks.custom_perms(manage_messages=True)
|
2016-08-13 05:37:29 +12:00
|
|
|
async def purge(self, ctx, limit: int = 100):
|
2016-08-08 07:26:44 +12:00
|
|
|
"""This command is used to a purge a number of messages from the channel"""
|
2016-08-28 07:36:07 +12:00
|
|
|
if not ctx.message.channel.permissions_for(ctx.message.server.me).manage_messages:
|
|
|
|
await self.bot.say("I do not have permission to delete messages...")
|
|
|
|
return
|
2016-08-13 05:37:29 +12:00
|
|
|
await self.bot.purge_from(ctx.message.channel, limit=limit)
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2016-08-26 16:50:09 +12:00
|
|
|
@commands.command(pass_context=True, no_pm=True)
|
|
|
|
@checks.custom_perms(manage_messages=True)
|
|
|
|
async def prune(self, ctx, limit: int = 100):
|
|
|
|
"""This command can be used to prune messages from certain members
|
|
|
|
Mention any user you want to prune messages from; if no members are mentioned, the messages removed will be mine
|
|
|
|
If no limit is provided, then 100 will be used. This is also the max limit we can use"""
|
|
|
|
# We can only get logs from 100 messages at a time, so make sure we are not above that threshold
|
|
|
|
if limit > 100:
|
|
|
|
limit = 100
|
|
|
|
|
|
|
|
# If no members are provided, assume we're trying to prune our own messages
|
|
|
|
members = ctx.message.mentions
|
|
|
|
if len(members) == 0:
|
|
|
|
members = [ctx.message.server.me]
|
2016-08-28 07:36:07 +12:00
|
|
|
# If we're not setting the user to the bot, then we're deleting someone elses messages
|
|
|
|
# To do so, we need manage_messages permission, so check if we have that
|
|
|
|
elif not ctx.message.channel.permissions_for(ctx.message.server.me).manage_messages:
|
|
|
|
await self.bot.say("I do not have permission to delete messages...")
|
|
|
|
return
|
2016-08-26 16:50:09 +12:00
|
|
|
|
|
|
|
# Since logs_from will give us any message, not just the user's we need
|
|
|
|
# We'll increment count, and stop deleting messages if we hit the limit.
|
|
|
|
count = 0
|
|
|
|
async for msg in self.bot.logs_from(ctx.message.channel):
|
|
|
|
if msg.author in members:
|
2016-09-18 13:30:20 +12:00
|
|
|
try:
|
|
|
|
await self.bot.delete_message(msg)
|
|
|
|
count += 1
|
|
|
|
except discord.NotFound:
|
|
|
|
pass
|
2016-08-26 16:50:09 +12:00
|
|
|
if count >= limit:
|
|
|
|
break
|
2016-08-26 17:12:54 +12:00
|
|
|
msg = await self.bot.say("{} messages succesfully deleted".format(count))
|
|
|
|
await asyncio.sleep(60)
|
2016-09-19 09:13:41 +12:00
|
|
|
try:
|
|
|
|
await self.bot.delete_message(msg)
|
|
|
|
except discord.NotFound:
|
|
|
|
pass
|
2016-08-26 16:50:09 +12:00
|
|
|
|
2016-07-31 07:11:56 +12:00
|
|
|
@commands.group(aliases=['rule'], pass_context=True, no_pm=True, invoke_without_command=True)
|
2016-08-15 14:10:12 +12:00
|
|
|
@checks.custom_perms(send_messages=True)
|
2016-09-29 12:39:34 +13:00
|
|
|
async def rules(self, ctx, rule: int = None):
|
2016-07-31 07:11:56 +12:00
|
|
|
"""This command can be used to view the current rules on the server"""
|
2016-09-29 12:39:34 +13:00
|
|
|
r_filter = {'server_id': ctx.message.server.id}
|
|
|
|
rules = await config.get_content('rules', r_filter)
|
2016-09-29 15:20:15 +13:00
|
|
|
try:
|
|
|
|
rules = rules[0]['rules']
|
|
|
|
except TypeError:
|
2016-07-31 07:11:56 +12:00
|
|
|
await self.bot.say("This server currently has no rules on it! I see you like to live dangerously...")
|
|
|
|
return
|
2016-09-29 15:31:53 +13:00
|
|
|
if len(rules) == 0:
|
|
|
|
await self.bot.say("This server currently has no rules on it! I see you like to live dangerously...")
|
|
|
|
return
|
|
|
|
|
2016-09-29 12:39:34 +13:00
|
|
|
if rule is None:
|
|
|
|
# Enumerate the list, so that we can print the number and the rule for each rule
|
|
|
|
fmt = "\n".join("{}) {}".format(num + 1, rule) for num, rule in enumerate(rules))
|
|
|
|
await self.bot.say('```\n{}```'.format(fmt))
|
|
|
|
else:
|
2016-09-29 15:31:53 +13:00
|
|
|
try:
|
|
|
|
fmt = rules[rule - 1]
|
|
|
|
except IndexError:
|
|
|
|
await self.bot.say("That rules does not exist.")
|
|
|
|
return
|
2016-09-29 12:39:34 +13:00
|
|
|
await self.bot.say("Rule {}: \"{}\"".format(rule, fmt))
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2016-07-31 07:11:56 +12:00
|
|
|
@rules.command(name='add', aliases=['create'], pass_context=True, no_pm=True)
|
2016-08-15 14:10:12 +12:00
|
|
|
@checks.custom_perms(manage_server=True)
|
2016-07-31 07:12:35 +12:00
|
|
|
async def rules_add(self, ctx, *, rule: str):
|
2016-07-31 07:11:56 +12:00
|
|
|
"""Adds a rule to this server's rules"""
|
2016-09-29 12:39:34 +13:00
|
|
|
r_filter = {'server_id': ctx.message.server.id}
|
|
|
|
entry = {'server_id': ctx.message.server.id,
|
|
|
|
'rules': [rule]}
|
|
|
|
update = lambda row: row['rules'].append(rule)
|
|
|
|
if not await config.update_content('rules', update, r_filter):
|
|
|
|
await config.add_content('rules', entry, r_filter)
|
|
|
|
|
2016-07-31 07:11:56 +12:00
|
|
|
await self.bot.say("I have just saved your new rule, use the rules command to view this server's current rules")
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2016-07-31 07:11:56 +12:00
|
|
|
@rules.command(name='remove', aliases=['delete'], pass_context=True, no_pm=True)
|
2016-08-15 14:10:12 +12:00
|
|
|
@checks.custom_perms(manage_server=True)
|
2016-09-29 12:39:34 +13:00
|
|
|
async def rules_delete(self, ctx, rule: int):
|
2016-07-31 07:20:31 +12:00
|
|
|
"""Removes one of the rules from the list of this server's rules
|
2016-09-29 12:39:34 +13:00
|
|
|
Provide a number to delete that rule"""
|
|
|
|
r_filter = {'server_id': ctx.message.server.id}
|
|
|
|
update = {'rules': r.row['rules'].delete_at(rule - 1)}
|
|
|
|
if not await config.update_content('rules', update, r_filter):
|
|
|
|
await self.bot.say("That is not a valid rule number, try running the command again.")
|
|
|
|
else:
|
2016-07-31 07:16:58 +12:00
|
|
|
await self.bot.say("I have just removed that rule from your list of rules!")
|
2016-07-31 12:20:55 +12:00
|
|
|
|
|
|
|
|
2016-07-09 13:31:18 +12:00
|
|
|
def setup(bot):
|
|
|
|
bot.add_cog(Mod(bot))
|