1
0
Fork 0
mirror of synced 2024-06-27 02:31:04 +12:00
Bonfire/cogs/mod.py

95 lines
3.6 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
@commands.command(pass_context=True)
@checks.isMod()
async def nsfw(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'!")
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 ;)")
@commands.command(pass_context=True)
@checks.isMod()
2016-07-10 04:27:48 +12:00
async def unnsfw(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))
try:
cursor.execute('delete from nsfw_channels where channel_id="{}"'.format(ctx.message.channel.id))
except pymysql.IntegrityError:
await self.bot.say("This channel is not registered as a ''nsfw' channel!")
return
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
@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))