From bcb06f6545bbe186a838c591eab160f61b066996 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sun, 17 Dec 2017 18:23:48 +0000 Subject: [PATCH] Adding emoji functionality and updating the roles to match the new server --- app/dragon-bot.py | 46 +++++++++++++++++++++++++++++++++++++++++++-- app/help_methods.py | 6 ++++++ app/role_check.py | 8 ++++---- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index f738d86d..eaf61ca9 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -81,7 +81,7 @@ async def on_message(message): ) if message.content.startswith('!cleanup'): - if not role_check.cleanup_permissions(message.author.roles) or message.channel.id != '339510341459247106': + if not role_check.cleanup_permissions(message.author.roles): await client.send_message(message.channel, 'You cant do that') return @@ -113,6 +113,48 @@ async def on_message(message): if message.content.startswith('!excuse'): await client.send_message(message.channel, excuse.get_excuse()) + if message.content.startswith('!emoji'): + if not role_check.is_admin(message.author.roles): + await client.send_message( + message.channel, + "You dont have permission to create emojis" + ) + return + + emoji_staging = '/tmp/emoji' + + try: + command, url, emoji_name = message.content.split() + except Exception: + await client.send_message( + message.channel, + help_methods.get_help_message('emoji') + ) + return + try: + # Download the emoji with requests + with open(emoji_staging, 'wb') as f: + f.write(requests.get(url).content) + + # Attempt to upload the emoji + await client.create_custom_emoji( + server=client.get_server('152921472304676865'), + name=emoji_name, + image=open(emoji_staging, "rb").read() + ) + await client.send_message( + message.channel, + "emoji successfully uploaded!" + ) + + except Exception: + await client.send_message( + message.channel, + "I wasnt able to upload that image as an emoji. Sorry" + ) + os.remove(emoji_staging) + return + if message.content.startswith('!help'): await client.send_message(message.channel, "ok {}, check your private messages".format(message.author.mention)) await client.send_message( @@ -184,8 +226,8 @@ async def on_message(message): await client.send_message( message.channel, wallpaper.get_picture(message.content) - ) + if message.content.startswith('!docker'): # Check permissions if not role_check.docker_permissions(message.author.roles): diff --git a/app/help_methods.py b/app/help_methods.py index 70fbd8ed..21e52521 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -31,6 +31,12 @@ def get_help_message(method): 'Returns the URL to a G O O D B O Y E or G I R L', '\nUsage: !dog' ], + 'emoji': [ + 'Uploads the passed in URL to the server as an emoji.', + '\nDiscord does not support GIFS. It will throw and error if you try.' + '\nCurrently only admins can do this', + '\nUsage: !emoji http://pictures.com/some_image.png my_new_emoji' + ], 'excuse': [ 'Generates a random excuse you can give your boss', '\nUsage: !excuse' diff --git a/app/role_check.py b/app/role_check.py index bbb40dee..44505402 100644 --- a/app/role_check.py +++ b/app/role_check.py @@ -24,18 +24,18 @@ def is_admin(user): """ is_admin(user) - Returns true if the user contains the Adminimodistrator role + Returns true if the user contains the ADMIN role """ - return check_permissions(user, ['Adminimodistrator']) + return check_permissions(user, ['ADMIN']) def is_mod(user): """ is_admin(user) - Returns true if the user contains the MOD or Greasemonkey role + Returns true if the user contains the Moderator role """ - return check_permissions(user, ['MOD', 'Greasemonkey']) + return check_permissions(user, ['Moderator']) def docker_permissions(user):