From 339ad336e29aaaa3dda3300a7ff7f11c8d547f84 Mon Sep 17 00:00:00 2001 From: John Hernandez <129467592+H3rnand3zzz@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:02:33 +0100 Subject: [PATCH] Refactor emoticons.py plugin, add new emoticons, and remove dependency Enhance the emoticons.py plugin by using a dictionary for emoticon replacement. Add new emoticons to the dictionary and remove the dependency on the 'future' module. Update documentation accordingly. --- stable/emoticons.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/stable/emoticons.py b/stable/emoticons.py index 92c8fc1..f8ffcbd 100644 --- a/stable/emoticons.py +++ b/stable/emoticons.py @@ -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)