From 04f235ec198eba78dbb1679d56471dc54a70bc68 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Tue, 1 Sep 2020 18:13:04 -0700 Subject: [PATCH] porting emoji to new bot. fixes #11 --- CONTRIBUTING.md | 3 +-- app/bot.py | 26 ++++++++++++++++++++ app/emoji.py | 58 --------------------------------------------- app/help_methods.py | 2 +- 4 files changed, 28 insertions(+), 61 deletions(-) delete mode 100644 app/emoji.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bdc0de99..823a450c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,5 @@ ### Contribution guidelines ### * Make your changes -* Test the bot by running `test-dragon-bot.sh` and interacting with the bot in the `#dragon-bot-test` channel - * This will lint your python as well +* Test the bot by running `./test-dragon-bot.sh` and interacting with the bot in the `#dragon-bot-test` channel * Create your pull request * bonus points if you include screenshots, terminal output, or even videos of the features on the PR \ No newline at end of file diff --git a/app/bot.py b/app/bot.py index 0fb87352..431b6aba 100755 --- a/app/bot.py +++ b/app/bot.py @@ -120,6 +120,32 @@ async def excuse(ctx): import excuse await ctx.send(excuse.get_excuse()) +@bot.command(name='emoji') +async def emoji(ctx): + await ctx.message.delete() + try: + command, url, emoji_name = ctx.message.content.split() + except Exception: + import help_methods + await ctx.send(help_methods.get_help_message('emoji')) + return + + import core_utils + emoji_staging = '/tmp/emoji' + await ctx.send("emoji successfully uploaded! Heres how it looks in a sentence {}\nUse it with `:{}:`".format( + await ctx.message.guild.create_custom_emoji( + name=emoji_name, + image=open(core_utils.download_image(url, emoji_staging), "rb").read() + ), emoji_name + ) + ) + except Exception: + await ctx.send( + "I wasnt able to upload that image as an emoji. Sorry" + ) + os.remove(emoji_staging) + return + @bot.command(name='avatar') async def avatar(ctx): profile = [ctx.message.author] diff --git a/app/emoji.py b/app/emoji.py deleted file mode 100644 index 460476e7..00000000 --- a/app/emoji.py +++ /dev/null @@ -1,58 +0,0 @@ -import os -import help_methods -import discord -import core_utils - -async def create_emoji(client, message): - 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: - # Attempt to upload the emoji - await client.delete_message(message) - await client.send_message( - message.channel, - "emoji successfully uploaded! Heres how it looks in a sentence {}\nUse it with `:{}:`".format( - await client.create_custom_emoji( - server=message.server, - name=emoji_name, - image=open(core_utils.download_image(url, emoji_staging), "rb").read() - ), emoji_name - ) - ) - - except Exception: - await client.send_message( - message.channel, - "I wasnt able to upload that image as an emoji. Sorry" - ) - os.remove(emoji_staging) - return - -async def delete_emoji(client, message): - name = message.content.split()[2] - emotes = [x for x in client.get_all_emojis() if x.name == name] - if not len(emotes): - return await client.send_message( - message.channel, - "No emotes with that name could be found on this server." - ) - for emote in emotes: - await client.delete_custom_emoji(emote) - return await client.send_message( - message.channel, - "Successfully deleted" - ) - -async def parse_message(client, message): - if message.content.split()[1] == 'del': - return await delete_emoji(client, message) - - await create_emoji(client, message) \ No newline at end of file diff --git a/app/help_methods.py b/app/help_methods.py index 10620124..e3d10822 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -62,7 +62,7 @@ def get_help_message(method): ], '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.' + '\nDiscord does not support GIFS. It will throw an error if you try.' '\nCurrently only admins can do this', '\nUsage: !emoji http://pictures.com/some_image.png my_new_emoji\n', 'or `!emoji del some_emoji` to delete'