From ce025fbb1f6aea9795e390a84269f65d5f45b8af Mon Sep 17 00:00:00 2001 From: kanewi11 Date: Sun, 16 Oct 2022 23:35:06 +0300 Subject: [PATCH] Small fixes --- .gitignore | 4 +--- README.md | 22 ++++++++++++++++++++++ config.py | 2 +- reactionbot.py | 10 +++++++--- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index d3c0cb4..f5b4169 100644 --- a/.gitignore +++ b/.gitignore @@ -13,9 +13,7 @@ .idea/**/dictionaries .idea/**/shelf -sessions/*.session -sessions/*.ini -sessions/*.json +sessions/* test.py *.log diff --git a/README.md b/README.md index e69de29..4a08bf0 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,22 @@ +# Bot for posting reactions to a Telegram post. +**Bot puts reactions only to new posts!** + +**Sessions must be for Pyrogram!** + +## Launch Instructions: +1. `git clone https://github.com/kanewi11/telegram-reaction-bot.git` +2. `python3 -m venv venv` +3. `source venv/bin/activate` +4. `pip install -r requirements.txt` +5. Add your channel name to `config.py`. +6. Add the session file and its configuration file to the `/sessions` directory. **These two files must have the same name!** Here is an example: +``` +/sessions +│ 8888888888.ini +│ 8888888888.session +│ 9999999999.ini +│ 9999999999.session +│ 98767242365.json +│ 98767242365.session +``` +7. `nohup python reactionbot.py &` \ No newline at end of file diff --git a/config.py b/config.py index 633a566..30e0a19 100644 --- a/config.py +++ b/config.py @@ -1 +1 @@ -channels = ['you_channel_name'] +channels = ['werqrewqrqwr'] diff --git a/reactionbot.py b/reactionbot.py index 9d80a06..02c4a0f 100644 --- a/reactionbot.py +++ b/reactionbot.py @@ -9,8 +9,9 @@ from pathlib import Path import uvloop -from pyrogram import Client, idle, filters, types +from pyrogram.errors import ReactionInvalid from pyrogram.handlers import MessageHandler +from pyrogram import Client, idle, filters, types from config import channels @@ -35,13 +36,16 @@ 'phone_number': ['phone_number', 'phone'] } -emojis = ['👍', '❤️', '🔥', '🥰', '👏', '😁', '🤔', '🤯', '🎉', '🤩', '⚡️', '💯', '❤️‍🔥', '🙏🏻'] +emojis = ['👍', '❤️', '🔥', '🥰', '👏', '😁', '🤔', '🤯', '🎉', '🤩', '⚡️', '💯', '❤️‍🔥'] async def send_reaction(client: Client, message: types.Message) -> None: """Хендлер для отправки реакций""" emoji = random.choice(emojis) - await client.send_reaction(chat_id=message.chat.id, message_id=message.id, emoji=emoji) + try: + await client.send_reaction(chat_id=message.chat.id, message_id=message.id, emoji=emoji) + except ReactionInvalid: + logging.warning(f'{emoji} - INVALID REACTION') async def make_work_dir() -> None: