aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.py2
-rw-r--r--main.py12
-rw-r--r--telegrambot.py23
-rw-r--r--userbot.py (renamed from mentioned.py)24
4 files changed, 44 insertions, 17 deletions
diff --git a/config.py b/config.py
index 19ea090..8466aa3 100644
--- a/config.py
+++ b/config.py
@@ -5,3 +5,5 @@ 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")
+BOT_ID = environ.get("TELEGRAM_BOT_ID")
+USER_ID = environ.get("TELEGRAM_USER_ID")
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..82fb745
--- /dev/null
+++ b/main.py
@@ -0,0 +1,12 @@
+from telegrambot import updater
+from userbot import client
+
+
+def main():
+ client.start()
+ updater.start_polling()
+ client.run_until_disconnected()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/telegrambot.py b/telegrambot.py
new file mode 100644
index 0000000..008e38d
--- /dev/null
+++ b/telegrambot.py
@@ -0,0 +1,23 @@
+import logging
+
+from telegram.ext import Updater, Dispatcher, CallbackContext, MessageHandler
+from telegram.ext.filters import Filters
+from telegram import Bot, Update
+
+from config import BOT_TOKEN, USER_ID, GROUP_ID
+
+
+LOG = logging.getLogger(__name__)
+updater = Updater(token=BOT_TOKEN)
+disp: Dispatcher = updater.dispatcher
+bot: Bot = updater.bot
+
+
+def handle_msg_rec(update: Update, context: CallbackContext) -> None:
+ if update.message.from_user.id != int(USER_ID):
+ return
+ update.message.forward(int(GROUP_ID))
+ LOG.info(f"Message from {update.message.from_user.id} was forwarded to {GROUP_ID}")
+
+
+disp.add_handler(MessageHandler(Filters.update, callback=handle_msg_rec))
diff --git a/mentioned.py b/userbot.py
index 118d7e2..bd390d6 100644
--- a/mentioned.py
+++ b/userbot.py
@@ -1,17 +1,15 @@
import re
+import logging
from telethon import TelegramClient, events
from telethon.tl.types import PeerUser
-from telegram.ext import Updater
-from telegram import Chat, Bot
-from config import API_ID, API_HASH, WORDLIST, GROUP_ID, BOT_TOKEN
+from config import API_ID, API_HASH, WORDLIST, BOT_ID
+LOG = logging.getLogger(__name__)
client = TelegramClient("notify me on untagged", API_ID, API_HASH)
-updater = Updater(token=BOT_TOKEN)
-bot: Bot = updater.bot
-chat: Chat = bot.get_chat(GROUP_ID)
+client.parse_mode = "markdown"
@client.on(events.NewMessage())
@@ -23,7 +21,7 @@ async def handler(event: events.NewMessage.Event):
if isinstance(event.message.peer_id, PeerUser):
return
- if bot.get_me().id == from_.user_id:
+ if int(BOT_ID) == from_.user_id:
return
if from_.user_id == me.id:
return
@@ -44,14 +42,6 @@ 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():]}"
- chat.send_message(msg, parse_mode="markdown")
+ 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
-
-
-def main():
- client.start()
- client.run_until_disconnected()
-
-
-if __name__ == "__main__":
- main()
XMR address: 854DmXNrxULU3ZFJVs4Wc8PFhbq29RhqHhY8W6cdWrtFN3qmooKyyeYPcDzZTNRxphhJ5UzASQfAdEMwSteVqymk28aLhqj