diff options
author | romangraef <romangraef@loves.dicksinhisan.us> | 2018-07-09 21:27:06 +0200 |
---|---|---|
committer | romangraef <romangraef@loves.dicksinhisan.us> | 2018-07-09 21:27:06 +0200 |
commit | 2f759c65d89b796ee7136b0d3e2cb5757a5fcf95 (patch) | |
tree | 349e067f42201101fd953bd68f7f1e5d1ad82dc4 | |
parent | 0e1e4393c0d672cbf5f6ad3aa3d1e1026802ea5d (diff) | |
download | evalbot-2f759c65d89b796ee7136b0d3e2cb5757a5fcf95.tar.gz evalbot-2f759c65d89b796ee7136b0d3e2cb5757a5fcf95.tar.bz2 evalbot-2f759c65d89b796ee7136b0d3e2cb5757a5fcf95.zip |
added language channel filter
-rw-r--r-- | filter.py | 33 | ||||
-rw-r--r-- | modules/execute.py | 6 |
2 files changed, 38 insertions, 1 deletions
diff --git a/filter.py b/filter.py new file mode 100644 index 0000000..2675b10 --- /dev/null +++ b/filter.py @@ -0,0 +1,33 @@ +from discord import Message, Member, TextChannel + +allowed_languages = { + 365161457995743252: ['python3', 'python2'], + 365161096199536662: ['java'], + 365162262400598016: ['nodejs'], + 365162403526082561: ['php'], + 411245017764462593: ['java'], + 440476654767177728: ['java'], + 395547238165643265: ['csharp'], + 365161847529275393: ['cpp14'], + 440476086300573696: ['go'], + 440476142881996810: ['ruby'], +} + +everything = [365162674033524746, 365236060252536833] + + +def verify(message: Message, language: str): + if not message.guild: + return False + author: Member = message.author + channel: TextChannel = message.channel + if author.guild_permissions.manage_messages: + return True + + if channel.id in everything: + return True + + if language in allowed_languages.get(channel.id, []): + return True + + return False diff --git a/modules/execute.py b/modules/execute.py index 4d3f426..1d9102e 100644 --- a/modules/execute.py +++ b/modules/execute.py @@ -7,6 +7,7 @@ from discord import Embed, Color, Message, Guild, TextChannel, Member from discord.ext.commands import Bot from compile_api import execute +from filter import verify CODE_BLOCK_REGEX: Pattern = re.compile("```(?P<lang>.*)\n(?P<code>[\\s\\S]*?)```") INPUT_BLOCK_REGEX: Pattern = re.compile("input[: \t\n]*```(?P<lang>.*)?\n(?P<text>[\\s\\S]*?)```", re.IGNORECASE) @@ -90,7 +91,10 @@ class ExecuteCog(object): f"{(timedelta(seconds=30)-delta).seconds}secs")) if not author.guild_permissions.manage_messages: self.last_messaged[author.id] = datetime.now() - response = await execute(code, *languages[lang]) + language, version = languages[lang] + if not verify(message, language): + return + response = await execute(code, language, version) if response.status_code == 429: return await channel.send( embed=Embed( |