From 9fad5eaa97d20479c1a4a105fe47277968f67469 Mon Sep 17 00:00:00 2001 From: NoirPi <34034616+NoirPi@users.noreply.github.com> Date: Sat, 27 Apr 2019 13:49:23 +0200 Subject: 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> --- modules/admin.py | 23 ++++++++++++++--------- modules/execute.py | 10 ++++++---- 2 files changed, 20 insertions(+), 13 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[0-9]+)>'): '(guild.get_member({id}) if guild is not None else client.get_user({id}))', + re.compile(r'<@!?(?P[0-9]+)>'): '(guild.get_member({id}) if guild is not None ' + 'else client.get_user({id}))', re.compile(r'<#(?P[0-9]+)>'): '(discord.utils.get(all_channels, id={id}))', re.compile(r'<@&(?P[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}`", diff --git a/modules/execute.py b/modules/execute.py index 21e8fa3..2f7b293 100644 --- a/modules/execute.py +++ b/modules/execute.py @@ -3,13 +3,15 @@ from collections import defaultdict from datetime import datetime, timedelta from typing import Pattern -from discord import Embed, Message, Guild, TextChannel, Member +from discord import Embed, Guild, Member, Message, TextChannel +from discord.ext import commands from discord.ext.commands import Bot from compile_api import execute CODE_BLOCK_REGEX: Pattern = re.compile("```(?P.*)\n(?P[\\s\\S]*?)```") -INPUT_BLOCK_REGEX: Pattern = re.compile("input[: \t\n]*```(?P.*)?\n(?P[\\s\\S]*?)```", re.IGNORECASE) +INPUT_BLOCK_REGEX: Pattern = \ + re.compile("input[: \t\n]*```(?P.*)?\n(?P[\\s\\S]*?)```", re.IGNORECASE) PYTHON_3 = 24 NODEJS = 17 @@ -56,7 +58,7 @@ languages = { } -class ExecuteCog(object): +class ExecuteCog(commands.Cog, object): def __init__(self, bot: Bot): self.bot: Bot = bot self.last_messaged = defaultdict(lambda: datetime.fromtimestamp(0)) @@ -89,7 +91,7 @@ class ExecuteCog(object): embed=Embed( description=f"You are not allowed to eval code again. Check again in " f"{(timedelta(seconds=30)-delta).seconds}secs")) - if not author.guild_permissions.manage_messages and not author.id == 310702108997320705: + if not author.guild_permissions.manage_messages and not author.id == 280766063472541697: self.last_messaged[author.id] = datetime.now() language = languages[lang] print(language) -- cgit From f0939b99d71088c95e2b69616e1fee96b44ce167 Mon Sep 17 00:00:00 2001 From: NoirPi <34034616+NoirPi@users.noreply.github.com> Date: Sat, 27 Apr 2019 13:49:23 +0200 Subject: 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> --- modules/admin.py | 23 ++++++++++++++--------- modules/execute.py | 11 +++++++---- 2 files changed, 21 insertions(+), 13 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[0-9]+)>'): '(guild.get_member({id}) if guild is not None else client.get_user({id}))', + re.compile(r'<@!?(?P[0-9]+)>'): '(guild.get_member({id}) if guild is not None ' + 'else client.get_user({id}))', re.compile(r'<#(?P[0-9]+)>'): '(discord.utils.get(all_channels, id={id}))', re.compile(r'<@&(?P[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}`", diff --git a/modules/execute.py b/modules/execute.py index 21e8fa3..024c1ec 100644 --- a/modules/execute.py +++ b/modules/execute.py @@ -3,13 +3,15 @@ from collections import defaultdict from datetime import datetime, timedelta from typing import Pattern -from discord import Embed, Message, Guild, TextChannel, Member +from discord import Embed, Guild, Member, Message, TextChannel +from discord.ext import commands from discord.ext.commands import Bot from compile_api import execute CODE_BLOCK_REGEX: Pattern = re.compile("```(?P.*)\n(?P[\\s\\S]*?)```") -INPUT_BLOCK_REGEX: Pattern = re.compile("input[: \t\n]*```(?P.*)?\n(?P[\\s\\S]*?)```", re.IGNORECASE) +INPUT_BLOCK_REGEX: Pattern = \ + re.compile("input[: \t\n]*```(?P.*)?\n(?P[\\s\\S]*?)```", re.IGNORECASE) PYTHON_3 = 24 NODEJS = 17 @@ -56,12 +58,13 @@ languages = { } -class ExecuteCog(object): +class ExecuteCog(commands.Cog, object): def __init__(self, bot: Bot): self.bot: Bot = bot self.last_messaged = defaultdict(lambda: datetime.fromtimestamp(0)) # noinspection PyMethodMayBeStatic + @commands.Cog.listener() async def on_message(self, message: Message): if message.guild is None: return @@ -89,7 +92,7 @@ class ExecuteCog(object): embed=Embed( description=f"You are not allowed to eval code again. Check again in " f"{(timedelta(seconds=30)-delta).seconds}secs")) - if not author.guild_permissions.manage_messages and not author.id == 310702108997320705: + if not author.guild_permissions.manage_messages and not author.id == 280766063472541697: self.last_messaged[author.id] = datetime.now() language = languages[lang] print(language) -- cgit From df26076b99388dabd36ee32a0182a1078a567661 Mon Sep 17 00:00:00 2001 From: Roman Gräf Date: Sun, 28 Apr 2019 14:20:16 +0200 Subject: Update execute.py No need to inherit from object, reverted back to myself as global admin --- modules/execute.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/execute.py b/modules/execute.py index 024c1ec..bdc4d3f 100644 --- a/modules/execute.py +++ b/modules/execute.py @@ -58,7 +58,7 @@ languages = { } -class ExecuteCog(commands.Cog, object): +class ExecuteCog(commands.Cog): def __init__(self, bot: Bot): self.bot: Bot = bot self.last_messaged = defaultdict(lambda: datetime.fromtimestamp(0)) @@ -92,7 +92,7 @@ class ExecuteCog(commands.Cog, object): embed=Embed( description=f"You are not allowed to eval code again. Check again in " f"{(timedelta(seconds=30)-delta).seconds}secs")) - if not author.guild_permissions.manage_messages and not author.id == 280766063472541697: + if not author.guild_permissions.manage_messages and not author.id == 310702108997320705: self.last_messaged[author.id] = datetime.now() language = languages[lang] print(language) -- cgit From 044142eb95301b70bc1fb2dab158b952f2badb09 Mon Sep 17 00:00:00 2001 From: Roman Gräf Date: Sun, 28 Apr 2019 14:21:05 +0200 Subject: Update admin.py You dont need to explictely extend from object. --- modules/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/admin.py b/modules/admin.py index c07b594..ee67aa7 100644 --- a/modules/admin.py +++ b/modules/admin.py @@ -73,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(commands.Cog, object): +class AdminCog(commands.Cog): def __init__(self, bot: commands.Bot): self.bot: commands.Bot = bot -- cgit