aboutsummaryrefslogtreecommitdiff
path: root/userbot.py
diff options
context:
space:
mode:
authorMroik <mroik@delayed.space>2024-04-12 17:02:57 +0200
committerMroik <mroik@delayed.space>2024-04-12 17:09:15 +0200
commitd45829b4af237b34e6a7590ee96ca08136870adc (patch)
treeff372ce857273403a93ffc973b8ec46f9ceed01e /userbot.py
parentef1aa7bfa5047b239a3748a4e92c8d8ae6ef8e8a (diff)
Rewrite project
Diffstat (limited to 'userbot.py')
-rw-r--r--userbot.py56
1 files changed, 14 insertions, 42 deletions
diff --git a/userbot.py b/userbot.py
index bd390d6..d9d0f79 100644
--- a/userbot.py
+++ b/userbot.py
@@ -1,47 +1,19 @@
-import re
-import logging
-
from telethon import TelegramClient, events
-from telethon.tl.types import PeerUser
-
-from config import API_ID, API_HASH, WORDLIST, BOT_ID
+from telethon.tl.patched import Message
+from telethon.tl.types import Chat
+from config import API_ID, API_HASH, WORDLIST, BOTNICK
-
-LOG = logging.getLogger(__name__)
-client = TelegramClient("notify me on untagged", API_ID, API_HASH)
+client = TelegramClient("notify-on-untagged", int(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 int(BOT_ID) == from_.user_id:
- return
- if from_.user_id == me.id:
- return
- if message.message == "" or message.message is None:
- return
- if message.mentioned:
- return
- for word in WORDLIST:
- if f" {word.upper()} " in message.message.upper()\
- or message.message.upper().startswith(f"{word.upper()} ")\
- or message.message.upper().endswith(f" {word.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)}):\n"
- found = re.search(f"{word.upper()}", message.message.upper())
- if found is None:
- msg += f"{message.message}"
- else:
- 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(BOT_ID)), msg)
- LOG.info(f"Message from {from_.user_id} was sent to BOT {BOT_ID}")
- return
+@client.on(events.NewMessage)
+async def check_message(event):
+ message: Message = event.message
+ c: Chat = await message.get_chat()
+ found = len(list(filter(lambda x: x in message.message, WORDLIST))) > 0
+ if found:
+ print(f"[{message.chat_id}](https://t.me/c/{message.chat_id}/{message.id})")
+ to_send = f"[{message.from_id.user_id}](tg://user?id={message.from_id.user_id}) "
+ to_send += f"tagged you in [{c.id}](https://t.me/c/{c.id}/{message.id})"
+ await client.send_message(BOTNICK, to_send)
XMR address: 854DmXNrxULU3ZFJVs4Wc8PFhbq29RhqHhY8W6cdWrtFN3qmooKyyeYPcDzZTNRxphhJ5UzASQfAdEMwSteVqymk28aLhqj