From e3f64882e8045f190630936bc1de9c626db44404 Mon Sep 17 00:00:00 2001 From: Mroik Date: Wed, 24 Nov 2021 20:18:53 +0100 Subject: First commit --- LICENSE | 13 +++++++++++++ config.py | 5 +++++ mentioned.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 LICENSE create mode 100644 config.py create mode 100644 mentioned.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..58ec253 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + +Copyright (C) 2021 Mroik + +Everyone is permitted to copy and distribute verbatim or modified +copies of this license document, and changing it is allowed as long +as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..4fb3498 --- /dev/null +++ b/config.py @@ -0,0 +1,5 @@ +from os import environ + +API_ID = environ.get("TELEGRAM_API_ID") +API_HASH = environ.get("TELEGRAM_API_HASH") +WORDLIST = [] # List of words to be notified about diff --git a/mentioned.py b/mentioned.py new file mode 100644 index 0000000..327ab10 --- /dev/null +++ b/mentioned.py @@ -0,0 +1,40 @@ +from telethon import TelegramClient, events +from telethon.tl.types import PeerUser + +from config import API_ID, API_HASH, WORDLIST + + +client = TelegramClient("mi_chiamano", API_ID, API_HASH) +client.parse_mode = "markdown" + + +@client.on(events.NewMessage()) +async def handler(event: events.NewMessage.Event): + me = await client.get_me() + from_ = event.message.from_id + chan = event.message.peer_id + message = event.message + + if isinstance(event.message.peer_id, PeerUser): + return + if from_.user_id == me.id: + return + if message.message == "" or message.message is None: + return + if event.message.mentioned: + return + for word in WORDLIST: + if word.upper() in event.message.message.upper(): + msg = f"[{from_.user_id}](tg://user?id={from_.user_id}) tagged you in" + msg += f" [{chan.channel_id}](https://t.me/c/{chan.channel_id}/{str(message.id)})" + await client.send_message("me", msg) + return + + +def main(): + client.start() + client.run_until_disconnected() + + +if __name__ == "__main__": + main() -- cgit v1.3