Exemplo n.º 1
0
    def converter(self, in_q, out_q):
        while True:
            telegram_msg = in_q.get(block=True)

            if 'message' in telegram_msg:  # New message
                if 'text' not in telegram_msg['message']:
                    continue

                vk_id = DB.convert_ids('Telegram', 'VK', telegram_msg['message']['chat']['id'])

                if vk_id is None:
                    continue

                vk_msg = {'api_method': 'messages.send', 'params': {}}
                vk_msg['params']['peer_id'] = vk_id
                vk_msg['params']['message'] = telegram_msg['message']['text']

                out_q.put(vk_msg)
Exemplo n.º 2
0
    def converter(self, in_q, out_q):
        while True:
            vk_msg = in_q.get(block=True)

            if vk_msg[0] == 4:  # New message
                if vk_msg[2] & 2:  # Flag 'OUTBOX' set
                    continue

                telegram_info = DB.convert_ids('VK', 'Telegram', vk_msg[3], need_group_info=True)

                if telegram_info is None:
                    continue

                telegram_msg = {'parse_mode': "HTML"}
                telegram_msg['chat_id'] = telegram_info[0]

                if telegram_info[1]:
                    telegram_msg['text'] = "<b>Name Placeholder</b>:\n"
                else:
                    telegram_msg['text'] = ""

                telegram_msg['text'] += vk_msg[6].replace('<br>', '\n')
                out_q.put(telegram_msg)