From 714c9696971d1ecba5454c598546d37a3d8258f0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 19 Feb 2019 19:37:17 +0100 Subject: [PATCH] Add /emojify (thanks @Pandiscotto!) --- strings.py | 9 ++++++++ telegrambot.py | 17 +++++++++++--- utils/__init__.py | 3 ++- utils/emojify.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 utils/emojify.py diff --git a/strings.py b/strings.py index 9b624ef7..a0848235 100644 --- a/strings.py +++ b/strings.py @@ -32,6 +32,7 @@ class TELEGRAM: PONG = "๐Ÿ“ Pong!" +ESCAPE = "{text}" # Ah, non lo so io. @@ -105,6 +106,14 @@ class EAT: INVALID_SYNTAX = "โš  Non hai specificato cosa mangiare!\nSintassi: /eat (cibo)" +# Emojify a string +class EMOJIFY: + RESPONSE = "{emojified}" + + class ERRORS: + INVALID_SYNTAX = "โš  Non hai specificato una frase!\nSintassi: /emojify (testo)" + + # Royalnet linking class LINK: SUCCESS = "โœ… Collegamento riuscito!" diff --git a/telegrambot.py b/telegrambot.py index afe1a6c8..d7de53f3 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -2,7 +2,7 @@ import datetime import random import typing import db -from utils import smecds, cast, errors +from utils import smecds, cast, errors, emojify # python-telegram-bot has a different name # noinspection PyPackageRequirements import telegram @@ -772,14 +772,25 @@ def cmd_start(bot: telegram.Bot, update: telegram.Update): @command def cmd_spell(bot: telegram.Bot, update: telegram.Update): try: - input: str = update.message.text.split(" ", 1)[1] + spell_name: str = update.message.text.split(" ", 1)[1] except IndexError: reply(bot, update, strings.SPELL.ERRORS.INVALID_SYNTAX) return - spell = cast.Spell(input) + spell = cast.Spell(spell_name) reply(bot, update, spell.stringify()) +@command +def cmd_emojify(bot: telegram.Bot, update: telegram.Update): + try: + string: str = update.message.text.split(" ", 1)[1] + except IndexError: + reply(bot, update, strings.EMOJIFY.ERRORS.INVALID_SYNTAX) + return + msg = emojify(string) + reply(bot, update, strings.EMOJIFY.RESPONSE, emojified=msg) + + def process(arg_discord_connection): if arg_discord_connection is not None: global discord_connection diff --git a/utils/__init__.py b/utils/__init__.py index 01a4947b..741ccd25 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -2,5 +2,6 @@ from .dirty import Dirty, DirtyDelta from .mmstatus import MatchmakingStatus from .cast import Spell from .stagismo import smecds +from .emojify import emojify -__all__ = ["Dirty", "DirtyDelta", "MatchmakingStatus", "Spell", "smecds"] +__all__ = ["Dirty", "DirtyDelta", "MatchmakingStatus", "Spell", "smecds", "emojify"] diff --git a/utils/emojify.py b/utils/emojify.py new file mode 100644 index 00000000..69865b54 --- /dev/null +++ b/utils/emojify.py @@ -0,0 +1,56 @@ +import random + +emojis = { + "abcd": ["๐Ÿ”ก", "๐Ÿ” "], + "back": ["๐Ÿ”™"], + "cool": ["๐Ÿ†’"], + "free": ["๐Ÿ†“"], + "abc": ["๐Ÿ”ค"], + "atm": ["๐Ÿง"], + "new": ["๐Ÿ†•"], + "sos": ["๐Ÿ†˜"], + "top": ["๐Ÿ”"], + "zzz": ["๐Ÿ’ค"], + "end": ["๐Ÿ”š"], + "ab": ["๐Ÿ†Ž"], + "cl": ["๐Ÿ†‘"], + "id": ["๐Ÿ†”"], + "ng": ["๐Ÿ†–"], + "no": ["โ™‘๏ธ"], + "ok": ["๐Ÿ†—"], + "on": ["๐Ÿ”›"], + "sy": ["๐Ÿ’ฑ"], + "tm": ["โ„ข๏ธ"], + "wc": ["๐Ÿšพ"], + "up": ["๐Ÿ†™"], + "a": ["๐Ÿ…ฐ๏ธ", "๐ŸŽฃ"], + "b": ["๐Ÿ…ฑ๏ธ", "๐Ÿ‡ณ๐Ÿ‡ต"], + "c": ["โ˜ช๏ธ", "ยฉ", "๐Ÿฅ"], + "e": ["๐Ÿ“ง", "๐Ÿ’ถ"], + "f": ["๐ŸŽ"], + "h": ["๐Ÿจ", "๐Ÿฉ", "๐Ÿ‹โ€โ™€", "๐Ÿ‹โ€โ™‚"], + "i": ["โ„น๏ธ", "โ™Š๏ธ", "๐Ÿ•ด", "๐Ÿ••"], + "j": ["๐Ÿงœโ€โ™€", "๐Ÿงœโ€โ™‚", "๐Ÿคณ", "๐Ÿ’", "๐Ÿ‘", "โคด๏ธ"], + "k": ["๐ŸŽ‹", "๐Ÿฆ…", "๐Ÿ’ƒ"], + "l": ["๐Ÿ›ด", "๐Ÿ•’"], + "m": ["โ™๏ธ", "โ“‚๏ธ", "ใ€ฝ๏ธ"], + "n": ["๐Ÿ“ˆ"], + "o": ["โญ•๏ธ", "๐Ÿ…พ๏ธ", "๐Ÿ“ฏ", "๐ŸŒ", "๐ŸŒš", "๐ŸŒ•", "๐Ÿฅฏ", "๐Ÿ™†โ€โ™€", "๐Ÿ™†โ€โ™‚"], + "p": ["๐Ÿ…ฟ๏ธ"], + "q": ["๐Ÿ”", "๐Ÿ€"], + "r": ["ยฎ"], + "s": ["๐Ÿ’ฐ", "๐Ÿ’ต", "๐Ÿ’ธ", "๐Ÿ’ฒ", "๐Ÿงžโ€โ™€", "๐Ÿงžโ€โ™‚"], + "t": ["๐Ÿคธโ€โ™€", "๐Ÿคธโ€โ™‚", "โœ๏ธ", "โฌ†๏ธ", "๐Ÿ”จ", "โ˜ฆ๏ธ", "๐Ÿš"], + "u": ["โ›Ž", "โš“๏ธ", "๐Ÿ‰", "๐ŸŒ™", "๐Ÿ‹"], + "v": ["โœ…", "๐Ÿ”ฝ", "โ˜‘๏ธ", "โœ”๏ธ"], + "w": ["๐Ÿคทโ€โ™€","๐Ÿคทโ€โ™‚", "๐Ÿคพโ€โ™€", "๐Ÿคพโ€โ™‚", "๐Ÿคฝโ€โ™€", "๐Ÿคฝโ€โ™‚"], + "x": ["๐Ÿ™…โ€โ™€", "๐Ÿ™…โ€โ™‚", "๐Ÿ‡ฏ๐Ÿ‡ฒ", "๐Ÿ‡ฏ๐Ÿ‡ช", "โŒ", "โŽ"], + "z": ["โšก๏ธ", "๐Ÿ”‹"] +} + +def emojify(string: str): + new_string = string + for key in emojis: + selected_emoji = random.sample(emojis[key], 1)[0] + new_string = new_string.replace(key, selected_emoji) + return new_string \ No newline at end of file