1
0
Fork 0
mirror of synced 2024-06-02 10:44:32 +12:00
Bonfire/cogs/mod.py

110 lines
4.3 KiB
Python
Raw Normal View History

2016-07-09 13:27:19 +12:00
from discord.ext import commands
from .utils import checks
from .utils import config
import pymysql
2016-07-09 13:27:19 +12:00
class Mod:
"""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 07:38:48 +12:00
@commands.group(pass_context=True)
async def nsfw(self, ctx)
"""Handles adding or removing a channel as a nsfw channel"""
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)
@checks.isMod()
2016-07-10 07:38:48 +12:00
async def nsfw_add(self, ctx):
"""Registers this channel as a 'nsfw' channel"""
cursor = config.getCursor()
cursor.execute('use {}'.format(config.db_default))
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()
return
2016-07-10 04:33:48 +12:00
config.closeConnection()
await self.bot.say("This channel has just been registered as 'nsfw'! Have fun you naughties ;)")
2016-07-10 07:38:48 +12:00
@nsfw.command(name="remove", aliases=["delete"], pass_context=True)
@checks.isMod()
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"""
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:
await self.bot.say("This channel is not registered as a ''nsfw' channel!")
2016-07-10 04:54:24 +12:00
config.closeConnection()
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()
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)
@checks.isAdmin()
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)
2016-07-09 13:27:19 +12:00
2016-07-10 07:14:38 +12:00
@commands.command(pass_context=True)
@checks.isMod()
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```'
2016-07-10 02:59:21 +12:00
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```'
2016-07-10 02:59:21 +12:00
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```'
2016-07-10 02:59:21 +12:00
await self.bot.say(fmt.format(type(e).__name__, e))
2016-07-09 13:31:18 +12:00
def setup(bot):
bot.add_cog(Mod(bot))