2016-07-09 13:27:19 +12:00
|
|
|
from discord.ext import commands
|
|
|
|
from .utils import config
|
|
|
|
from .utils import checks
|
|
|
|
import re
|
|
|
|
import os
|
2016-07-17 03:56:20 +12:00
|
|
|
import glob
|
2016-07-09 13:27:19 +12:00
|
|
|
import sys
|
|
|
|
import discord
|
2016-07-13 16:30:22 +12:00
|
|
|
import inspect
|
2016-07-22 04:23:55 +12:00
|
|
|
import aiohttp
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
getter = re.compile(r'`(?!`)(.*?)`')
|
|
|
|
multi = re.compile(r'```(.*?)```', re.DOTALL)
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
@commands.command(pass_context=True)
|
2016-07-16 01:29:24 +12:00
|
|
|
@commands.check(checks.isOwner)
|
2016-07-09 13:27:19 +12:00
|
|
|
async def restart(self, ctx):
|
|
|
|
"""Forces the bot to restart"""
|
2016-07-29 11:08:06 +12:00
|
|
|
config.saveContent('restart_server', ctx.message.channel.id)
|
2016-07-28 23:45:27 +12:00
|
|
|
await self.bot.say("Restarting; see you in the next life {0}!".format(ctx.message.author.mention))
|
2016-07-10 01:29:17 +12:00
|
|
|
python = sys.executable
|
|
|
|
os.execl(python, python, *sys.argv)
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2016-07-18 09:10:12 +12:00
|
|
|
@commands.command()
|
2016-07-17 03:56:20 +12:00
|
|
|
@commands.check(checks.isOwner)
|
2016-07-18 09:10:12 +12:00
|
|
|
async def adddoggo(self, url: str):
|
2016-07-17 04:48:10 +12:00
|
|
|
"""Saves a URL as an image to add for the doggo command"""
|
2016-07-17 03:56:20 +12:00
|
|
|
os.chdir('/home/phxntx5/public_html/Bonfire/images')
|
|
|
|
local_path = 'doggo{}.jpg'.format(len(glob.glob('doggo*')))
|
2016-07-22 04:23:55 +12:00
|
|
|
with aiohttp.ClientSession() as s:
|
|
|
|
async with s.get(url) as r:
|
|
|
|
val = await r.read()
|
|
|
|
with open(local_path, "wb") as f:
|
|
|
|
f.write(val)
|
2016-07-18 09:10:12 +12:00
|
|
|
await self.bot.say(
|
2016-07-28 23:45:27 +12:00
|
|
|
"Just saved a new doggo image! I now have {} doggo images!".format(len(glob.glob('doggo*'))))
|
2016-07-18 09:10:12 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
@commands.command(pass_context=True)
|
2016-07-16 01:29:24 +12:00
|
|
|
@commands.check(checks.isOwner)
|
2016-07-24 02:36:54 +12:00
|
|
|
async def debug(self, ctx):
|
2016-07-09 13:27:19 +12:00
|
|
|
"""Executes code"""
|
2016-07-10 00:57:25 +12:00
|
|
|
match_single = getter.findall(ctx.message.content)
|
|
|
|
match_multi = multi.findall(ctx.message.content)
|
2016-07-28 23:45:27 +12:00
|
|
|
if not match_multi:
|
|
|
|
result = eval(match_single[0])
|
2016-07-14 02:27:23 +12:00
|
|
|
|
2016-07-28 23:45:27 +12:00
|
|
|
if inspect.isawaitable(result):
|
|
|
|
result = await result
|
|
|
|
await self.bot.say("```{0}```".format(result))
|
2016-07-30 00:54:36 +12:00
|
|
|
elif match_multi:
|
2016-07-28 23:45:27 +12:00
|
|
|
def r(v):
|
2016-07-30 00:52:50 +12:00
|
|
|
self.bot.loop.create_task(self.bot.say("```{}```".format(v)))
|
2016-07-28 23:45:27 +12:00
|
|
|
exec(match_multi[0])
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
@commands.command(pass_context=True)
|
2016-07-16 01:29:24 +12:00
|
|
|
@commands.check(checks.isOwner)
|
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}'
|
|
|
|
await self.bot.say(fmt.format(ctx.message))
|
|
|
|
await self.bot.logout()
|
|
|
|
await self.bot.close()
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
@commands.command()
|
2016-07-16 01:29:24 +12:00
|
|
|
@commands.check(checks.isOwner)
|
2016-07-09 13:42:33 +12:00
|
|
|
async def avatar(self, content: str):
|
2016-07-09 13:27:19 +12:00
|
|
|
"""Changes the avatar for the bot to the filename following the command"""
|
2016-07-10 00:57:25 +12:00
|
|
|
file = '/home/phxntx5/public_html/bot/images/' + content
|
|
|
|
with open(file, 'rb') as fp:
|
|
|
|
await self.bot.edit_profile(avatar=fp.read())
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
@commands.command()
|
2016-07-16 01:29:24 +12:00
|
|
|
@commands.check(checks.isOwner)
|
2016-07-09 13:42:33 +12:00
|
|
|
async def name(self, newNick: str):
|
2016-07-09 13:27:19 +12:00
|
|
|
"""Changes the bot's name"""
|
2016-07-10 00:57:25 +12:00
|
|
|
await self.bot.edit_profile(username=newNick)
|
|
|
|
await self.bot.say('Changed username to ' + newNick)
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
@commands.command()
|
2016-07-16 01:29:24 +12:00
|
|
|
@commands.check(checks.isOwner)
|
2016-07-09 13:27:19 +12:00
|
|
|
async def status(self, *stat: str):
|
|
|
|
"""Changes the bot's 'playing' status"""
|
2016-07-10 00:57:25 +12:00
|
|
|
newStatus = ' '.join(stat)
|
|
|
|
game = discord.Game(name=newStatus, type=0)
|
|
|
|
await self.bot.change_status(game)
|
|
|
|
await self.bot.say("Just changed my status to '{0}'!".format(newStatus))
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2016-07-13 02:17:47 +12:00
|
|
|
@commands.command()
|
2016-07-16 01:29:24 +12:00
|
|
|
@commands.check(checks.isOwner)
|
2016-07-13 02:17:47 +12:00
|
|
|
async def load(self, *, module: str):
|
|
|
|
"""Loads a module"""
|
2016-07-28 23:45:27 +12:00
|
|
|
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))
|
2016-07-13 02:17:47 +12:00
|
|
|
|
|
|
|
@commands.command()
|
2016-07-16 01:29:24 +12:00
|
|
|
@commands.check(checks.isOwner)
|
2016-07-13 02:17:47 +12:00
|
|
|
async def unload(self, *, module: str):
|
|
|
|
"""Unloads a 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)
|
|
|
|
await self.bot.say("I have just unloaded the {} module".format(module))
|
2016-07-13 02:17:47 +12:00
|
|
|
|
|
|
|
@commands.command()
|
2016-07-16 01:29:24 +12:00
|
|
|
@commands.check(checks.isOwner)
|
2016-07-13 02:17:47 +12:00
|
|
|
async def reload(self, *, module: str):
|
|
|
|
"""Reloads a 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)
|
|
|
|
self.bot.load_extension(module)
|
|
|
|
await self.bot.say("I have just reloaded the {} module".format(module))
|
2016-07-13 02:17:47 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
def setup(bot):
|
|
|
|
bot.add_cog(Owner(bot))
|