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-07-10 03:40:46 +12:00
|
|
|
import pymysql
|
2016-07-16 03:59:30 +12:00
|
|
|
import traceback
|
2016-07-16 02:58:10 +12:00
|
|
|
import discord
|
|
|
|
|
|
|
|
valid_perms = ['kick_members','ban_members','administrator','manage_channels','manage_server','read_messages',
|
|
|
|
'send_messages','send_tts_messages','manage_messages','embed_links','attach_files','read_message_history',
|
|
|
|
'mention_everyone','connect','speak','mute_members','deafen_members','move_members','use_voice_activation',
|
|
|
|
'change_nicknames','manage_nicknames','manage_roles']
|
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-09 13:27:19 +12:00
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
2016-07-10 03:17:54 +12:00
|
|
|
|
2016-07-10 07:38:48 +12:00
|
|
|
@commands.group(pass_context=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-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))
|
|
|
|
|
|
|
|
@nsfw.command(name="add", pass_context=True)
|
2016-07-13 02:17:47 +12:00
|
|
|
@commands.has_permissions(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-07-10 04:02:33 +12:00
|
|
|
cursor = config.getCursor()
|
2016-07-10 03:17:54 +12:00
|
|
|
cursor.execute('use {}'.format(config.db_default))
|
2016-07-10 03:26:13 +12:00
|
|
|
try:
|
|
|
|
cursor.execute('insert into nsfw_channels (channel_id) values ("{}")'.format(ctx.message.channel.id))
|
|
|
|
except pymysql.IntegrityError:
|
|
|
|
await self.bot.say("This channel is already registered as 'nsfw'!")
|
2016-07-10 04:54:24 +12:00
|
|
|
config.closeConnection()
|
2016-07-10 03:41:44 +12:00
|
|
|
return
|
2016-07-10 04:33:48 +12:00
|
|
|
config.closeConnection()
|
2016-07-10 03:26:13 +12:00
|
|
|
await self.bot.say("This channel has just been registered as 'nsfw'! Have fun you naughties ;)")
|
2016-07-10 04:25:28 +12:00
|
|
|
|
2016-07-10 07:38:48 +12:00
|
|
|
@nsfw.command(name="remove", aliases=["delete"], pass_context=True)
|
2016-07-13 02:17:47 +12:00
|
|
|
@commands.has_permissions(kick_members=True)
|
2016-07-10 07:38:48 +12:00
|
|
|
async def nsfw_remove(self, ctx):
|
2016-07-10 04:28:18 +12:00
|
|
|
"""Removes this channel as a 'nsfw' channel"""
|
2016-07-10 04:25:28 +12:00
|
|
|
cursor = config.getCursor()
|
|
|
|
cursor.execute('use {}'.format(config.db_default))
|
2016-07-10 04:54:24 +12:00
|
|
|
cursor.execute('select * from nsfw_channels where channel_id="{}"'.format(ctx.message.channel.id))
|
|
|
|
if cursor.fetchone() is None:
|
2016-07-10 04:25:28 +12:00
|
|
|
await self.bot.say("This channel is not registered as a ''nsfw' channel!")
|
2016-07-10 04:54:24 +12:00
|
|
|
config.closeConnection()
|
2016-07-10 04:25:28 +12:00
|
|
|
return
|
2016-07-10 04:54:24 +12:00
|
|
|
|
|
|
|
cursor.execute('delete from nsfw_channels where channel_id="{}"'.format(ctx.message.channel.id))
|
2016-07-10 04:33:48 +12:00
|
|
|
config.closeConnection()
|
2016-07-10 04:25:28 +12:00
|
|
|
await self.bot.say("This channel has just been unregistered as a nsfw channel")
|
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
@commands.command(pass_context=True, no_pm=True)
|
2016-07-13 02:17:47 +12:00
|
|
|
@commands.has_permissions(manage_server=True)
|
2016-07-09 13:27:19 +12:00
|
|
|
async def leave(self, ctx):
|
|
|
|
"""Forces the bot to leave the server"""
|
2016-07-10 00:57:25 +12:00
|
|
|
await self.bot.say('Why must I leave? Hopefully I can come back :c')
|
|
|
|
await self.bot.leave_server(ctx.message.server)
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2016-07-10 07:14:38 +12:00
|
|
|
@commands.command(pass_context=True)
|
2016-07-13 02:17:47 +12:00
|
|
|
@commands.has_permissions(kick_members=True)
|
2016-07-10 07:14:38 +12:00
|
|
|
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)
|
2016-07-16 01:27:00 +12:00
|
|
|
|
|
|
|
@commands.group(pass_context=True, invoke_without_command=True)
|
2016-07-16 01:27:55 +12:00
|
|
|
async def perms(self, ctx, command: str):
|
2016-07-16 01:27:00 +12:00
|
|
|
if command not in self.bot.commands:
|
2016-07-16 01:58:28 +12:00
|
|
|
await self.bot.say("{} does not appear to be a valid command!".format(command))
|
2016-07-16 01:27:00 +12:00
|
|
|
return
|
2016-07-16 01:56:13 +12:00
|
|
|
|
|
|
|
cursor = config.getCursor()
|
|
|
|
cursor.execute('use {}'.format(config.db_default))
|
|
|
|
cursor.execute("show tables like '{}'".format(ctx.message.server.id))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result is None:
|
|
|
|
await self.bot.say("There are no custom permissions setup on this server yet!")
|
|
|
|
return
|
|
|
|
|
|
|
|
cursor.execute('select perms from custom_permissions where server_id=%s and command=%s', (ctx.message.server.id,command))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result is None:
|
|
|
|
await self.bot.say("That command has no custom permissions setup on it!")
|
|
|
|
return
|
|
|
|
|
|
|
|
await self.bot.say("You need to have the permission `{}` to use the command `{}` in this server".format(result['perm'],command))
|
|
|
|
|
|
|
|
@perms.command(name="add", aliases=["setup,create"], pass_context=True)
|
2016-07-16 02:58:10 +12:00
|
|
|
@commands.has_permissions(manage_server=True)
|
|
|
|
async def add_perms(self, ctx, command: str, permissions: str):
|
2016-07-16 03:59:06 +12:00
|
|
|
try:
|
|
|
|
for checks in self.bot.commands.get(command).checks:
|
|
|
|
if "isOwner" == checks.__name__:
|
|
|
|
await self.bot.say("This command cannot have custom permissions setup!")
|
|
|
|
return
|
|
|
|
|
|
|
|
if getattr(discord.Permissions, permissions, None) is None and not permissions.lower() == "none":
|
|
|
|
await self.bot.say("{} does not appear to be a valid permission! Valid permissions are: ```{}```"
|
|
|
|
.format(permissions, "\n".join(valid_perms)))
|
2016-07-16 02:58:10 +12:00
|
|
|
else:
|
2016-07-16 03:59:06 +12:00
|
|
|
cursor = config.getCursor()
|
|
|
|
cursor.execute('use {}'.format(config.db_default))
|
|
|
|
cursor.execute("show tables like %s", (ctx.message.server.id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result is None:
|
|
|
|
#Server's data doesn't exist yet, need to create it
|
|
|
|
sql = "create table `{}` (`command` varchar(32) not null,`perms` varchar(32) not null,"
|
|
|
|
"primary key (`command`)) engine=InnoDB default charset=utf8 collate=utf8_bin"
|
|
|
|
cursor.execute(sql.format(ctx.message.server.id))
|
2016-07-16 03:18:55 +12:00
|
|
|
cursor.execute("insert into {} (command, perms) values({}, {})",(ctx.message.server.id,command,perms))
|
2016-07-16 02:58:10 +12:00
|
|
|
else:
|
2016-07-16 03:59:06 +12:00
|
|
|
cursor.execute("select perms from %s where command=%s",(ctx.message.server.id,command))
|
|
|
|
if cursor.fetchone() is None:
|
|
|
|
cursor.execute("insert into {} (command, perms) values({}, {})",(ctx.message.server.id,command,perms))
|
|
|
|
else:
|
|
|
|
cursor.execute("update %s set perms=%s where command=%s",(ctx.message.server.id,perms,command))
|
|
|
|
|
|
|
|
config.closeConnection()
|
|
|
|
except:
|
|
|
|
traceback.print_exc(file=open("/home/phxntx5/public_html/Bonfire/bot_error","a"))
|
2016-07-09 13:31:18 +12:00
|
|
|
|
|
|
|
|
|
|
|
def setup(bot):
|
|
|
|
bot.add_cog(Mod(bot))
|