aboutsummaryrefslogtreecommitdiff
path: root/modules/admin.py
diff options
context:
space:
mode:
authorNoirPi <34034616+NoirPi@users.noreply.github.com>2019-04-27 13:49:23 +0200
committerNoirPi <34034616+NoirPi@users.noreply.github.com>2019-04-27 13:49:23 +0200
commit9fad5eaa97d20479c1a4a105fe47277968f67469 (patch)
tree5366c0371e179c199351c69b6083b3f0b767a91f /modules/admin.py
parent55c6967967c91a3259e9af67ba61dcfdaaff5f9e (diff)
downloadevalbot-9fad5eaa97d20479c1a4a105fe47277968f67469.tar.gz
evalbot-9fad5eaa97d20479c1a4a105fe47277968f67469.tar.bz2
evalbot-9fad5eaa97d20479c1a4a105fe47277968f67469.zip
Updated Bot to latest github.com Version of discord.py
Version Number: 1.1.0a1886+ga7f3300 Added guild variable Added print if reload throws Exceptions Signed-off-by: NoirPi <34034616+NoirPi@users.noreply.github.com>
Diffstat (limited to 'modules/admin.py')
-rw-r--r--modules/admin.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/modules/admin.py b/modules/admin.py
index e1d2921..c07b594 100644
--- a/modules/admin.py
+++ b/modules/admin.py
@@ -1,15 +1,16 @@
import re
-from typing import List, Dict, Pattern
+from typing import Dict, List, Pattern
import discord
-from discord import Embed, Color
+from discord import Color, Embed
from discord.ext import commands
-from discord.ext.commands import Context as CommandContext, Bot, is_owner, command
+from discord.ext.commands import Bot, command, Context as CommandContext, is_owner
from util import load_all_modules
REPLACEMENTS: Dict[Pattern, str] = {
- re.compile(r'<@!?(?P<id>[0-9]+)>'): '(guild.get_member({id}) if guild is not None else client.get_user({id}))',
+ re.compile(r'<@!?(?P<id>[0-9]+)>'): '(guild.get_member({id}) if guild is not None '
+ 'else client.get_user({id}))',
re.compile(r'<#(?P<id>[0-9]+)>'): '(discord.utils.get(all_channels, id={id}))',
re.compile(r'<@&(?P<id>[0-9]+)>'): '(discord.utils.get(all_roles, id={id}))',
# Maybe later emoji support
@@ -35,7 +36,8 @@ async def handle_eval(message: discord.Message, client: discord.Client, to_eval:
'all_roles': all_roles,
'client': client,
'discord': discord,
- 'print': (lambda *text: client.loop.create_task(channel.send(' '.join(text))))
+ 'print': (lambda *text: client.loop.create_task(channel.send(' '.join(text)))),
+ 'guild': channel.guild if hasattr(channel, 'guild') else None,
}
if channel.guild is not None:
variables['guild'] = channel.guild
@@ -53,14 +55,16 @@ async def handle_eval(message: discord.Message, client: discord.Client, to_eval:
exec(code, _globals, _locals)
except Exception as e:
await message.channel.send(
- embed=discord.Embed(color=discord.Color.red(), description="Compiler Error: `%s`" % (str(e))))
+ embed=discord.Embed(color=discord.Color.red(),
+ description="Compiler Error: `%s`" % (str(e))))
return
result = {**_globals, **_locals}
try:
result = await result["code"](**variables)
except Exception as e:
await message.channel.send(
- embed=discord.Embed(color=discord.Color.red(), description="Runtime Error: `%s`" % (str(e))))
+ embed=discord.Embed(color=discord.Color.red(),
+ description="Runtime Error: `%s`" % (str(e))))
return
return await channel.send(
@@ -69,7 +73,7 @@ async def handle_eval(message: discord.Message, client: discord.Client, to_eval:
description="📥 Evaluation success: ```py\n%r\n```" % result))
-class AdminCog(object):
+class AdminCog(commands.Cog, object):
def __init__(self, bot: commands.Bot):
self.bot: commands.Bot = bot
@@ -104,7 +108,8 @@ class AdminCog(object):
for extension in extensions:
try:
self.bot.load_extension(extension)
- except:
+ except Exception as e:
+ print(e)
await ctx.send(
embed=Embed(
title=f"Failed to load module `{extension}`",