From 6ff65935c878a9dc83eb7d81f1c9e745e543595b Mon Sep 17 00:00:00 2001 From: mroik Date: Thu, 25 Nov 2021 14:45:23 +0100 Subject: Messages are now sent by a bot in a group This way when someone mentions you without tagging you, there will be a notification from that group, because the message will be sent by the bot. --- config.py | 1 + mentioned.py | 9 +++++---- requirements.txt | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index 2a8ec0d..19ea090 100644 --- a/config.py +++ b/config.py @@ -4,3 +4,4 @@ API_ID = environ.get("TELEGRAM_API_ID") API_HASH = environ.get("TELEGRAM_API_HASH") GROUP_ID = environ.get("TELEGRAM_GROUP_ID") WORDLIST = [] # List of words to be notified about +BOT_TOKEN = environ.get("TELEGRAM_BOT_TOKEN") diff --git a/mentioned.py b/mentioned.py index b199c60..b3cd7ff 100644 --- a/mentioned.py +++ b/mentioned.py @@ -1,13 +1,14 @@ import re from telethon import TelegramClient, events -from telethon.tl.types import PeerUser, PeerChannel +from telethon.tl.types import PeerUser +from telegram import Bot -from config import API_ID, API_HASH, WORDLIST, GROUP_ID +from config import API_ID, API_HASH, WORDLIST, GROUP_ID, BOT_TOKEN client = TelegramClient("notify me on untagged", API_ID, API_HASH) -client.parse_mode = "markdown" +bot = Bot(BOT_TOKEN) @client.on(events.NewMessage()) @@ -38,7 +39,7 @@ async def handler(event: events.NewMessage.Event): msg += f"{message.message[:found.start()]}__"\ f"{message.message[found.start():found.end()]}__"\ f"{message.message[found.end():]}" - await client.send_message(await client.get_input_entity((int(GROUP_ID))), msg) + bot.send_message(GROUP_ID, msg, parse_mode="markdown") return diff --git a/requirements.txt b/requirements.txt index a879a03..3b58a5c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ Telethon==1.23.0 +python-telegram-bot==13.8.1 -- cgit v1.3