porting emoji to new bot. fixes #11

This commit is contained in:
Luke Robles 2020-09-01 18:13:04 -07:00
parent 858ccb6b2a
commit 04f235ec19
4 changed files with 28 additions and 61 deletions

View File

@ -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

View File

@ -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]

View File

@ -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)

View File

@ -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'