diff --git a/webapp/titanembeds/EmojiParser.py b/webapp/titanembeds/EmojiParser.py new file mode 100644 index 0000000..70d6ffb --- /dev/null +++ b/webapp/titanembeds/EmojiParser.py @@ -0,0 +1,17 @@ +from titanembeds.utils import discord_api +import re + +def parseEmoji(textToParse, guild_id): + _endpoint = "/guilds/{guild_id}".format(guild_id=guild_id) + _method = "GET" + response = discord_api.request(_method, _endpoint) + emojis = [] + emojis = re.findall(":(.*?):", textToParse) + newText = textToParse + for emoji in response['emojis']: + name = emoji['name'] + emojiId = emoji['id'] + for emoji2 in emojis: + if name.lower is emoji2.replace(":", "").lower(): + newText = newText.replace(":{}:".format(name), "".format(id)) + return newText \ No newline at end of file diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py index bc35f24..e95d00c 100644 --- a/webapp/titanembeds/blueprints/api/api.py +++ b/webapp/titanembeds/blueprints/api/api.py @@ -1,5 +1,6 @@ from titanembeds.database import db, Guilds, UnauthenticatedUsers, UnauthenticatedBans, AuthenticatedUsers, KeyValueProperties, GuildMembers, Messages, get_channel_messages, list_all_guild_members from titanembeds.decorators import valid_session_required, discord_users_only +from titamembeds.EmojiParser import parseEmoji from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key from titanembeds.oauth import user_has_permission, generate_avatar_url, check_user_can_administrate_guild from flask import Blueprint, abort, jsonify, session, request @@ -102,6 +103,7 @@ def check_user_in_guild(guild_id): def format_post_content(guild_id, message): illegal_post = False illegal_reasons = [] + message = parseEmoji(message, guild_id) message = message.replace("<", "\<") message = message.replace(">", "\>")