From d0d8c50f14da46237f0f1b94020c7db22fbb4562 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 18 Apr 2021 16:29:59 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20/emojify?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- royalpack/__main__.py | 7 +-- royalpack/commands/__init__.py | 3 +- royalpack/commands/cat.py | 2 +- royalpack/commands/ciao.py | 27 ---------- royalpack/commands/debug.py | 57 --------------------- royalpack/commands/emojify.py | 94 ++++++++++++++++++++++++++++++++++ royalpack/commands/ping.py | 2 +- royalpack/commands/ship.py | 2 +- 8 files changed, 100 insertions(+), 94 deletions(-) delete mode 100644 royalpack/commands/ciao.py delete mode 100644 royalpack/commands/debug.py create mode 100644 royalpack/commands/emojify.py diff --git a/royalpack/__main__.py b/royalpack/__main__.py index 2d5d35c0..49a5ff17 100644 --- a/royalpack/__main__.py +++ b/royalpack/__main__.py @@ -49,11 +49,8 @@ register_telegram(commands.ciaoruozi, ["ciaoruozi"]) register_telegram(commands.color, ["color"]) register_telegram(commands.ping, ["ping"]) register_telegram(commands.ship, ["ship"], r"(?P[A-Za-z]+)[\s+&]+(?P[A-Za-z]+)") -register_telegram(commands.debug, ["debug"]) -register_telegram(commands.debug_impls, ["debug"], r"impls") -register_telegram(commands.debug_exts, ["debug"], r"exts (?P\S+)") -register_telegram(commands.debug_convs, ["debug"], r"convs (?P\S+)") -register_telegram(commands.ciao, ["ciao"]) +register_telegram(commands.emojify, ["emojify"], r"(?P.+)") + pda.implementations["telethon.1"].register_conversation(r) diff --git a/royalpack/commands/__init__.py b/royalpack/commands/__init__.py index eb37a43e..b6cd7de1 100644 --- a/royalpack/commands/__init__.py +++ b/royalpack/commands/__init__.py @@ -5,5 +5,4 @@ from .ciaoruozi import * from .color import * from .ping import * from .ship import * -from .debug import * -from .ciao import * +from .emojify import * diff --git a/royalpack/commands/cat.py b/royalpack/commands/cat.py index ab4fb44a..0688d1b3 100644 --- a/royalpack/commands/cat.py +++ b/royalpack/commands/cat.py @@ -10,7 +10,7 @@ log = logging.getLogger(__name__) @engi.TeleportingConversation async def cat(*, _sentry: engi.Sentry, _msg: engi.Message, **__): """ - Send a cat in the chat! ๐Ÿˆ + Invia un gatto in chat! ๐Ÿˆ """ log.debug("Creating a new HTTP session") diff --git a/royalpack/commands/ciao.py b/royalpack/commands/ciao.py deleted file mode 100644 index 411a0805..00000000 --- a/royalpack/commands/ciao.py +++ /dev/null @@ -1,27 +0,0 @@ -import royalnet.engineer as engi -import royalnet.engineer.conversation as c - - -@engi.TeleportingConversation -async def ciao(*, _sentry: engi.Sentry, _msg: engi.Message, **__): - await _msg.reply(text="๐Ÿ‘‹ Ciao, chi sei?") - - answer: engi.MessageReceived = await _sentry.filter(engi.Type(engi.MessageReceived)).get() - _msg: engi.Message = await answer.message - _text: str = await _msg.text - - await _msg.reply(text=f"๐Ÿ‘‹ Ciao {_text}! Come stai?") - - answer: engi.MessageReceived = await _sentry.filter(engi.Type(engi.MessageReceived)).get() - _msg: engi.Message = await answer.message - _text: str = await _msg.text - - if "mamma" in _text or "madre" in _text: - await _msg.reply(text=f"๐Ÿ˜ Ehi... Al massimo sono io quello che sta {_text}!") - elif "male" in _text: - await _msg.reply(text=f"โ˜น๏ธ Mi dispiace che tu stia {_text}... :(") - else: - await _msg.reply(text=f"๐Ÿ™‚ Anche io sto {_text} :)") - - -__all__ = ("ciao",) diff --git a/royalpack/commands/debug.py b/royalpack/commands/debug.py deleted file mode 100644 index ef5ddaed..00000000 --- a/royalpack/commands/debug.py +++ /dev/null @@ -1,57 +0,0 @@ -import royalnet.engineer as engi - - -newline = "\n" - - -@engi.TeleportingConversation -async def debug(*, _sentry: engi.Sentry, _msg: engi.Message, _pda: engi.PDA, **__): - """ - Check the implementations currently running on the PDA. - """ - await _msg.reply(text=f""" -๐Ÿ› Sottocomandi di debug disponibili: - -- impls -- commands -""") - - -@engi.TeleportingConversation -async def debug_impls(*, _sentry: engi.Sentry, _msg: engi.Message, _pda: engi.PDA, **__): - await _msg.reply(text=f""" -๐Ÿ› Implementazioni attive sul PDA: - -{newline.join([f'๐Ÿ”ต {implementation!r}' for implementation in _pda.implementations.values()])} -""") - - -@engi.TeleportingConversation -async def debug_exts(*, _sentry: engi.Sentry, _msg: engi.Message, _pda: engi.PDA, impl: str, **__): - await _msg.reply(text=f""" -๐Ÿ› Estensioni attive sull'implementazione {impl}: - -{newline.join([f'๐Ÿ”ต {extension!r}' for extension in _pda.implementations[impl].extensions])} -""") - - -@engi.TeleportingConversation -async def debug_convs(*, _sentry: engi.Sentry, _msg: engi.Message, _pda: engi.PDA, impl: str, **__): - implementation = _pda.implementations[impl] - - if not isinstance(implementation, engi.ConversationListImplementation): - await _msg.reply(text="โš ๏ธ Questa implementazione gestisce le conversazioni con un metodo sconosciuto.") - - await _msg.reply(text=f""" -๐Ÿ› Conversazioni registrate sull'implementazione {impl}: - -{newline.join([f'๐Ÿ”ต {command!r}' for command in implementation.conversations])} -""") - - -__all__ = ( - "debug", - "debug_impls", - "debug_exts", - "debug_convs", -) diff --git a/royalpack/commands/emojify.py b/royalpack/commands/emojify.py new file mode 100644 index 00000000..2d053507 --- /dev/null +++ b/royalpack/commands/emojify.py @@ -0,0 +1,94 @@ +import royalnet.engineer as engi +import random + + +_emojis = { + "abcd": ["๐Ÿ”ก", "๐Ÿ” "], + "back": ["๐Ÿ”™"], + "cool": ["๐Ÿ†’"], + "free": ["๐Ÿ†“"], + "1234": ["๐Ÿ”ข"], + "abc": ["๐Ÿ”ค"], + "atm": ["๐Ÿง"], + "new": ["๐Ÿ†•"], + "sos": ["๐Ÿ†˜"], + "top": ["๐Ÿ”"], + "zzz": ["๐Ÿ’ค"], + "end": ["๐Ÿ”š"], + "777": ["๐ŸŽฐ"], + "100": ["๐Ÿ’ฏ"], + "ab": ["๐Ÿ†Ž"], + "cl": ["๐Ÿ†‘"], + "id": ["๐Ÿ†”"], + "ng": ["๐Ÿ†–"], + "no": ["โ™‘๏ธ"], + "ok": ["๐Ÿ†—"], + "on": ["๐Ÿ”›"], + "sy": ["๐Ÿ’ฑ"], + "tm": ["โ„ข๏ธ"], + "wc": ["๐Ÿšพ"], + "up": ["๐Ÿ†™"], + "!!": ["โ€ผ๏ธ"], + "!?": ["โ‰๏ธ"], + "69": ["โ™‹๏ธ"], + "24": ["๐Ÿช"], + "18": ["๐Ÿ”ž"], + "10": ["๐Ÿ™Œ", "๐Ÿ”Ÿ", "๐Ÿคฒ"], + "a": ["๐Ÿ…ฐ๏ธ"], + "b": ["๐Ÿ…ฑ๏ธ"], + "c": ["โ˜ช๏ธ", "ยฉ", "๐Ÿฅ"], + "d": ["๐Ÿ‡ฉ"], + "e": ["๐Ÿ“ง", "๐Ÿ’ถ"], + "f": ["๐ŸŽ"], + "g": ["๐Ÿ‡ฌ"], + "h": ["๐Ÿจ", "๐Ÿฉ", "๐Ÿ‹โ€โ™€", "๐Ÿ‹โ€โ™‚"], + "i": ["โ„น๏ธ", "โ™Š๏ธ", "๐Ÿ••"], + "j": ["โคด๏ธ"], + "k": ["๐ŸŽ‹", "๐Ÿฆ…", "๐Ÿ’ƒ"], + "l": ["๐Ÿ›ด", "๐Ÿ•’"], + "m": ["โ™๏ธ", "โ“‚๏ธ", "ใ€ฝ๏ธ"], + "n": ["๐Ÿ“ˆ"], + "o": ["โญ•๏ธ", "๐Ÿ…พ๏ธ", "๐Ÿ“ฏ", "๐ŸŒ", "๐ŸŒš", "๐ŸŒ•", "๐Ÿฅฏ", "๐Ÿ™†โ€โ™€", "๐Ÿ™†โ€โ™‚"], + "p": ["๐Ÿ…ฟ๏ธ"], + "q": ["๐Ÿ”", "๐Ÿ€", "๐Ÿญ"], + "r": ["ยฎ"], + "s": ["๐Ÿ’ฐ", "๐Ÿ’ต", "๐Ÿ’ธ", "๐Ÿ’ฒ"], + "t": ["โœ๏ธ", "โฌ†๏ธ", "โ˜ฆ๏ธ"], + "u": ["โ›Ž", "โš“๏ธ", "๐Ÿ‰", "๐ŸŒ™", "๐Ÿ‹"], + "v": ["โœ…", "๐Ÿ”ฝ", "โ˜‘๏ธ", "โœ”๏ธ"], + "w": ["๐Ÿคทโ€โ™€", "๐Ÿคทโ€โ™‚", "๐Ÿคพโ€โ™€", "๐Ÿคพโ€โ™‚", "๐Ÿคฝโ€โ™€", "๐Ÿคฝโ€โ™‚"], + "x": ["๐Ÿ™…โ€โ™€", "๐Ÿ™…โ€โ™‚", "โŒ", "โŽ"], + "y": ["๐Ÿ’ด"], + "z": ["โšก๏ธ"], + "*": ["*๏ธโƒฃ"], + "!": ["โ—๏ธ", "โ•", "โš ๏ธ"], + "?": ["โ“", "โ”"], + "9": ["9๏ธโƒฃ"], + "8": ["๐ŸŽฑ", "8๏ธโƒฃ"], + "7": ["7๏ธโƒฃ"], + "6": ["6๏ธโƒฃ"], + "5": ["โœ‹", "๐Ÿคš", "๐Ÿ‘‹", "5๏ธโƒฃ"], + "4": ["4๏ธโƒฃ"], + "3": ["๐Ÿฅ‰", "3๏ธโƒฃ"], + "2": ["โœŒ๏ธ", "๐Ÿค˜", "๐Ÿฅˆ", "2๏ธโƒฃ"], + "1": ["๐Ÿ‘†", "โ˜๏ธ", "๐Ÿ–•", "๐Ÿฅ‡", "1๏ธโƒฃ"], + "0": ["โญ•๏ธ", "๐Ÿ…พ๏ธ", "๐Ÿ“ฏ", "๐ŸŒ", "๐ŸŒš", "๐ŸŒ•", "๐Ÿฅฏ", "๐Ÿ™†โ€โ™€", "๐Ÿ™†โ€โ™‚", "0๏ธโƒฃ"], + "+": ["๐Ÿฅ"], + "/": ["๐Ÿ’", "๐Ÿงช", "๐Ÿงน"], + "\\": ["๐Ÿข", "๐Ÿก", "๐Ÿฅ„", "๐ŸŒ‚"], +} + + +@engi.TeleportingConversation +async def emojify(*, _msg: engi.Message, message: str, **__): + """ + Converti un messaggio in emoji. + """ + message = message.lower() + for key in _emojis: + selected_emoji = random.sample(_emojis[key], 1)[0] + message = message.replace(key, selected_emoji) + await _msg.reply(text=message) + + +__all__ = ("emojify",) diff --git a/royalpack/commands/ping.py b/royalpack/commands/ping.py index 63723219..57dad3d0 100644 --- a/royalpack/commands/ping.py +++ b/royalpack/commands/ping.py @@ -4,7 +4,7 @@ import royalnet.engineer as engi @engi.TeleportingConversation async def ping(*, _sentry: engi.Sentry, _msg: engi.Message, **__): """ - A way to check if the bot is working: it will always reply to this command with "๐Ÿ“ Pong!". + Gioca a ping pong con il bot. ๐Ÿ“ """ await _msg.reply(text="๐Ÿ“ Pong!") diff --git a/royalpack/commands/ship.py b/royalpack/commands/ship.py index 5b3e3325..2954b488 100644 --- a/royalpack/commands/ship.py +++ b/royalpack/commands/ship.py @@ -8,7 +8,7 @@ log = logging.getLogger(__name__) @engi.TeleportingConversation async def ship(*, _sentry: engi.Sentry, _msg: engi.Message, first: str, second: str, **__): """ - Ship two names together! ๐Ÿ’ž + Shippa insieme due persone! ๐Ÿ’ž """ log.info(f"Shipping: {first!r} + {second!r}")