From 5df67e3241dd6bfc467ca89c4080724ef49202fa Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 4 Mar 2021 23:43:36 +0000 Subject: [PATCH] Support custom names and emojis --- teledynmap.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/teledynmap.py b/teledynmap.py index 796a403..6f0cc78 100644 --- a/teledynmap.py +++ b/teledynmap.py @@ -1,6 +1,6 @@ import aiohttp import asyncio -import emoji +import hashlib import logging import re import settings @@ -9,9 +9,11 @@ from telethon import TelegramClient, events bot = TelegramClient('bot', settings.API_ID, settings.API_HASH).start(bot_token=settings.API_TOKEN) web = None api = lambda route: settings.DYNMAP_ADDRESS + route -emojis = list(emoji.unicode_codes.UNICODE_EMOJI_ENGLISH.keys()) +md5 = lambda name: int(hashlib.md5(name.encode()).hexdigest(), 16) +emojis = list('๐ŸŒน๐Ÿต๐ŸŒป๐ŸŒผ๐Ÿ€๐Ÿž๐ŸŒŠโ›„๏ธโ„๏ธ๐Ÿ”๐ŸŒก๐Ÿ”ฅ๐Ÿœโ˜€๏ธ๐Ÿ’งโ˜”๏ธโšก๏ธ๐ŸŒˆโญ๏ธ๐ŸŒ๐ŸŒ™๐Ÿช๐Ÿต๐Ÿฆ๐Ÿฏ๐Ÿฑ๐Ÿถ๐Ÿบ๐Ÿป๐Ÿผ๐Ÿน๐Ÿฐ๐ŸฆŠ๐Ÿฆ๐Ÿฆ“๐Ÿฆ„๐Ÿธ๐Ÿข๐Ÿ•๐Ÿ†๐Ÿ๐Ÿฆฅ๐Ÿ˜๐Ÿฆ๐Ÿฆ’๐Ÿฆ๐Ÿช๐Ÿฆฆ๐Ÿ”๐Ÿค๐Ÿฆ‰๐Ÿฆœ๐Ÿฆข๐Ÿฆฉ๐Ÿง๐Ÿฌ๐Ÿ ๐Ÿก๐Ÿฆ๐Ÿ™๐Ÿ•ท๐ŸŒ๐Ÿž๐Ÿฆ‹๐Ÿ“๐Ÿ’๐ŸŽ๐Ÿ‰๐Ÿ๐ŸŒ๐Ÿ‹๐Ÿ๐Ÿฅ๐Ÿ‡๐Ÿฅฅ๐Ÿ…๐ŸŒถ๐Ÿ„๐Ÿฅ•๐Ÿง…๐ŸŒฝ๐Ÿฅฆ๐Ÿฅ‘๐Ÿž๐Ÿฅž๐Ÿง‡๐Ÿง€๐Ÿฅ“๐Ÿ”๐ŸŒญ๐Ÿฅช๐Ÿฅจ๐ŸŸ๐Ÿ•๐ŸŒฎ๐Ÿฅ™๐Ÿœ๐Ÿฃ๐Ÿญ๐Ÿฉ๐Ÿช๐Ÿฏ๐Ÿฟ๐Ÿบ๐Ÿท๐Ÿ›น๐Ÿš€๐Ÿ›ธ๐Ÿ›ฉ๐ŸŽ‰๐ŸŽˆ๐ŸŽ€๐ŸŽโšพ๏ธ๐Ÿ€๐Ÿ๐Ÿˆ๐ŸŽฏ๐ŸŽน๐ŸŽท๐ŸŽบ๐ŸŽธ๐Ÿ’ต๐Ÿ’ฐ๐Ÿ’ก๐Ÿ’Ž๐ŸŸฅ๐ŸŸง๐ŸŸจ๐ŸŸฉ๐ŸŸฆ๐ŸŸช') logging.basicConfig(level=logging.INFO) +logging.info('Loaded {} emojis'.format(len(emojis))) logging.info('Bridge initialized') @bot.on(events.NewMessage(incoming=True)) @@ -27,8 +29,8 @@ async def new_message(event): logging.info('No text found') return - name = re.sub(r'\W+', '', sender.first_name) + '(TG)' - name = name.replace('Somebody', 'Applezaus') + name = re.sub(r'\W+', '', sender.first_name) + name = '[TG] ' + settings.CUSTOM_NAMES.get(name, name) logging.info('[SEND] {}: {}'.format(name, text)) @@ -48,10 +50,11 @@ async def main(): last_time = j['timestamp'] for update in j['updates']: if update['type'] != 'chat': continue - if update['playerName'].endswith('(TG)'): continue + if update['playerName'].startswith('[TG] '): continue name = update['playerName'] - icon = emojis[hash(name) % len(emojis)] + icon = emojis[md5(name) % len(emojis)] + icon = settings.CUSTOM_EMOJIS.get(name, icon) message = '{} <{}> {}'.format(icon, name, update['message']) if message == last_msg: continue