2016-07-09 13:27:19 +12:00
|
|
|
from discord.ext import commands
|
2016-10-06 07:44:37 +13:00
|
|
|
|
2017-02-13 12:45:19 +13:00
|
|
|
from . import utils
|
2016-10-06 07:44:37 +13:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
import re
|
2016-07-17 03:56:20 +12:00
|
|
|
import glob
|
2017-03-08 11:35:30 +13:00
|
|
|
import asyncio
|
|
|
|
import aiohttp
|
2016-07-09 13:27:19 +12:00
|
|
|
import discord
|
2016-07-13 16:30:22 +12:00
|
|
|
import inspect
|
2016-10-08 09:39:41 +13:00
|
|
|
import pendulum
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
|
|
|
|
class Owner:
|
2016-07-09 13:59:10 +12:00
|
|
|
"""Commands that can only be used by Phantom, bot management commands"""
|
2016-07-18 09:10:12 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
2016-08-31 10:33:46 +12:00
|
|
|
|
2016-10-08 09:39:41 +13:00
|
|
|
@commands.command()
|
2017-02-13 12:45:19 +13:00
|
|
|
@commands.check(utils.is_owner)
|
2017-03-08 11:35:30 +13:00
|
|
|
async def motd_push(self, ctx, *, message):
|
2016-10-08 09:39:41 +13:00
|
|
|
"""Used to push a new message to the message of the day"""
|
|
|
|
date = pendulum.utcnow().to_date_string()
|
2017-03-08 17:28:30 +13:00
|
|
|
key = date
|
2016-10-08 09:39:41 +13:00
|
|
|
entry = {'motd': message, 'date': date}
|
|
|
|
# Try to add this, if there's an entry for that date, lets update it to make sure only one motd is sent a day
|
|
|
|
# I should be managing this myself, more than one should not be sent in a day
|
2017-03-08 17:28:30 +13:00
|
|
|
if await utils.add_content('motd', entry):
|
|
|
|
await utils.update_content('motd', entry, key)
|
2017-03-08 11:35:30 +13:00
|
|
|
await ctx.send("New motd update for {}!".format(date))
|
2016-10-08 09:39:41 +13:00
|
|
|
|
2017-03-08 11:35:30 +13:00
|
|
|
@commands.command()
|
2017-02-13 12:45:19 +13:00
|
|
|
@commands.check(utils.is_owner)
|
2017-03-08 11:35:30 +13:00
|
|
|
async def debug(self, ctx, *, code: str):
|
2017-02-18 08:52:25 +13:00
|
|
|
"""Evaluates code."""
|
|
|
|
code = code.strip('` ')
|
|
|
|
python = '```py\n{}\n```'
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2017-02-18 08:52:25 +13:00
|
|
|
env = {
|
|
|
|
'bot': self.bot,
|
|
|
|
'ctx': ctx,
|
|
|
|
'message': ctx.message,
|
2017-03-08 12:56:24 +13:00
|
|
|
'server': ctx.message.guild,
|
2017-02-18 08:52:25 +13:00
|
|
|
'channel': ctx.message.channel,
|
|
|
|
'author': ctx.message.author
|
|
|
|
}
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2017-02-18 08:52:25 +13:00
|
|
|
env.update(globals())
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2017-02-18 08:52:25 +13:00
|
|
|
try:
|
|
|
|
result = eval(code, env)
|
|
|
|
if inspect.isawaitable(result):
|
|
|
|
result = await result
|
|
|
|
except Exception as e:
|
2017-03-08 11:35:30 +13:00
|
|
|
await ctx.send(python.format(type(e).__name__ + ': ' + str(e)))
|
2017-02-18 08:52:25 +13:00
|
|
|
return
|
2017-03-04 20:51:30 +13:00
|
|
|
try:
|
2017-03-08 11:35:30 +13:00
|
|
|
await ctx.send(python.format(result))
|
2017-03-04 20:51:30 +13:00
|
|
|
except discord.HTTPException:
|
2017-03-08 11:35:30 +13:00
|
|
|
await ctx.send("Result is too long for me to send")
|
2017-03-04 20:51:30 +13:00
|
|
|
except:
|
|
|
|
pass
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2017-03-08 11:35:30 +13:00
|
|
|
@commands.command()
|
2017-02-13 12:45:19 +13:00
|
|
|
@commands.check(utils.is_owner)
|
2016-07-09 13:27:19 +12:00
|
|
|
async def shutdown(self, ctx):
|
|
|
|
"""Shuts the bot down"""
|
2016-07-10 00:57:25 +12:00
|
|
|
fmt = 'Shutting down, I will miss you {0.author.name}'
|
2017-03-08 11:35:30 +13:00
|
|
|
await ctx.send(fmt.format(ctx.message))
|
2016-07-10 00:57:25 +12:00
|
|
|
await self.bot.logout()
|
|
|
|
await self.bot.close()
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
@commands.command()
|
2017-02-13 12:45:19 +13:00
|
|
|
@commands.check(utils.is_owner)
|
2017-03-09 08:25:52 +13:00
|
|
|
async def name(self, ctx, new_nick: str):
|
2016-07-09 13:27:19 +12:00
|
|
|
"""Changes the bot's name"""
|
2017-03-09 08:25:52 +13:00
|
|
|
await self.bot.user.edit(username=new_nick)
|
|
|
|
await ctx.send('Changed username to ' + new_nick)
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
@commands.command()
|
2017-02-13 12:45:19 +13:00
|
|
|
@commands.check(utils.is_owner)
|
2017-03-08 11:35:30 +13:00
|
|
|
async def status(self, ctx, *, status: str):
|
2016-07-09 13:27:19 +12:00
|
|
|
"""Changes the bot's 'playing' status"""
|
2017-03-09 08:25:52 +13:00
|
|
|
await self.bot.change_presence(game=discord.Game(name=status, type=0))
|
|
|
|
await ctx.send("Just changed my status to '{}'!".format(status))
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2016-07-13 02:17:47 +12:00
|
|
|
@commands.command()
|
2017-02-13 12:45:19 +13:00
|
|
|
@commands.check(utils.is_owner)
|
2017-03-08 11:35:30 +13:00
|
|
|
async def load(self, ctx, *, module: str):
|
2016-07-13 02:17:47 +12:00
|
|
|
"""Loads a module"""
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
# Do this because I'm too lazy to type cogs.module
|
2016-07-28 23:45:27 +12:00
|
|
|
module = module.lower()
|
|
|
|
if not module.startswith("cogs"):
|
|
|
|
module = "cogs.{}".format(module)
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
# This try catch will catch errors such as syntax errors in the module we are loading
|
2016-08-05 06:29:45 +12:00
|
|
|
try:
|
|
|
|
self.bot.load_extension(module)
|
2017-03-08 11:35:30 +13:00
|
|
|
await ctx.send("I have just loaded the {} module".format(module))
|
2016-08-05 06:29:45 +12:00
|
|
|
except Exception as error:
|
|
|
|
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
|
2017-03-08 11:35:30 +13:00
|
|
|
await ctx.send(fmt.format(type(error).__name__, error))
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2016-07-13 02:17:47 +12:00
|
|
|
@commands.command()
|
2017-02-13 12:45:19 +13:00
|
|
|
@commands.check(utils.is_owner)
|
2017-03-08 11:35:30 +13:00
|
|
|
async def unload(self, ctx, *, module: str):
|
2016-07-13 02:17:47 +12:00
|
|
|
"""Unloads a module"""
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
# Do this because I'm too lazy to type cogs.module
|
2016-07-28 23:45:27 +12:00
|
|
|
module = module.lower()
|
|
|
|
if not module.startswith("cogs"):
|
|
|
|
module = "cogs.{}".format(module)
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
self.bot.unload_extension(module)
|
2017-03-08 11:35:30 +13:00
|
|
|
await ctx.send("I have just unloaded the {} module".format(module))
|
2016-07-13 02:17:47 +12:00
|
|
|
|
|
|
|
@commands.command()
|
2017-02-13 12:45:19 +13:00
|
|
|
@commands.check(utils.is_owner)
|
2017-03-08 11:35:30 +13:00
|
|
|
async def reload(self, ctx, *, module: str):
|
2016-07-13 02:17:47 +12:00
|
|
|
"""Reloads a module"""
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
# Do this because I'm too lazy to type cogs.module
|
2016-07-28 23:45:27 +12:00
|
|
|
module = module.lower()
|
|
|
|
if not module.startswith("cogs"):
|
|
|
|
module = "cogs.{}".format(module)
|
|
|
|
self.bot.unload_extension(module)
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
# This try block will catch errors such as syntax errors in the module we are loading
|
2016-08-05 06:29:45 +12:00
|
|
|
try:
|
|
|
|
self.bot.load_extension(module)
|
2017-03-08 11:35:30 +13:00
|
|
|
await ctx.send("I have just reloaded the {} module".format(module))
|
2016-08-05 06:29:45 +12:00
|
|
|
except Exception as error:
|
|
|
|
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
|
2017-03-08 11:35:30 +13:00
|
|
|
await ctx.send(fmt.format(type(error).__name__, error))
|
2016-07-13 02:17:47 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
def setup(bot):
|
|
|
|
bot.add_cog(Owner(bot))
|