Merge pull request #28 from H3rnand3zzz/patch-2

Refactor emoticons.py plugin, add new emoticons, and remove dependency
This commit is contained in:
Michael Vetter
2023-11-10 22:16:06 +01:00
committed by GitHub

View File

@@ -1,30 +1,33 @@
"""
Convert smileys ( :) :( etc) to the Unicode character representation
Dependencies:
pip install future
Converts smileys in a text to their Unicode character representations.
"""
import prof
from builtins import chr
EMOTICON_UNICODE_DICT = {':)': '😃', ':(': '☹️', ':D': '😃', ':O': '😲', ';)': '😉', ':-)': '😊', ':-D': '😁', ':-(': '😞',
';-)': '😜', '<3': '❤️', ':P': '😛', ':|': '😐', ':/': '😕', ':*': '😘', ':]': '😃', ':[': '😢',
':-|': '😐', ':\\': '😕', ':3': '😺', 'O:)': '😇', '>:(': '😠', ':poop:': '💩', ':fire:': '🔥',
':heart:': '❤️', ':thumbsup:': '👍', ':star:': '', ':beer:': '🍺', ':pizza:': '🍕', ':sunglasses:': '😎',
':ok_hand:': '👌', ':heart_eyes:': '😍'}
def _emote(input_str):
result = input_str
result = result.replace(":-)", chr(9786))
result = result.replace(":)", chr(9786))
result = result.replace(":-(", chr(9785))
result = result.replace(":(", chr(9785))
return result
def replace_emoticons(text, emoticon_dict):
for emoticon, unicode_char in emoticon_dict.items():
text = text.replace(emoticon, unicode_char)
return text
def convert_emoticons(input_str):
return replace_emoticons(input_str, EMOTICON_UNICODE_DICT)
def prof_pre_chat_message_display(barejid, resource, message):
return _emote(message)
return convert_emoticons(message)
def prof_pre_room_message_display(barejid, nick, message):
return _emote(message)
return convert_emoticons(message)
def prof_pre_priv_message_display(barejid, nick, message):
return _emote(message)
return convert_emoticons(message)