Moving emoji into its own file, fixes #8
This commit is contained in:
parent
4b4d412727
commit
562c4f63d8
@ -15,6 +15,7 @@ import define_word
|
||||
import discord
|
||||
import docker
|
||||
import eight_ball
|
||||
import emoji
|
||||
import excuse
|
||||
import get_from_reddit
|
||||
import help_methods
|
||||
@ -187,54 +188,7 @@ async def on_message(message):
|
||||
"You dont have permission to manage emojis"
|
||||
)
|
||||
return
|
||||
|
||||
if message.content.split()[1] == 'del':
|
||||
name = message.content.split()[2]
|
||||
emotes = [x for x in client.get_all_emojis() if x.name == name]
|
||||
emote_length = len(emotes)
|
||||
if not 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"
|
||||
)
|
||||
|
||||
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
|
||||
await emoji.parse_message(client, message)
|
||||
|
||||
if message.content.startswith('!greentext'):
|
||||
await client.send_message(
|
||||
|
58
app/emoji.py
Normal file
58
app/emoji.py
Normal file
@ -0,0 +1,58 @@
|
||||
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)
|
Loading…
x
Reference in New Issue
Block a user