porting emoji to new bot. fixes #11
This commit is contained in:
parent
31611d9f1e
commit
5e79d3b0a7
@ -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
|
26
app/bot.py
26
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]
|
||||
|
58
app/emoji.py
58
app/emoji.py
@ -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)
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user