from pyrogram import Client
import shelve
import random
api_id = ************
api_hash = '***************'
phone_number = '+*************'
PUBLIC = 'angryzaycman'
TEXTS = ['Круто!', 'Nice!!!!', 'Oh my god']
processed_messages = shelve.open('processed_messages.db', writeback=True)
with Client('python_cyberpunk', api_id, api_hash, phone_number=phone_number) as app:
public = app.get_chat(PUBLIC)
print(public)
chat = public.linked_chat
for msg in app.get_chat_history(chat.id, limit=100):
if (msg.from_user is None and msg.sender_chat.id == public.id ):
if str(msg.forward_from_message_id) in processed_messages:
print(f'Пропускаем уже обработанное message_id={msg.id}')
processed_messages[str(msg.forward_from_message_id)] = True
print(f'Обработка message_id={msg.id}')
text = random.choice(TEXTS)
print(text)
app.send_message(chat.id, text, reply_to_message_id=msg.id)
import asyncio
from pyrogram import Client
import shelve
import random
from secret.config import Config
TEXTS = ['Круто!', 'Nice!!!!', 'Oh my god']
config = Config()
api_id = config.api_id
api_hash = config.api_hash
phone_number = config.phone
PUBLIC = config.title
chat_id = config.chat_id
name = config.name
processed_messages = shelve.open('processed_messages.db', writeback=True)
app = Client(name, api_id, api_hash, phone_number=phone_number)
async def main():
async with app:
public = await app.get_chat(PUBLIC)
async for msg in app.get_chat_history(chat_id, limit=100):
if msg.from_user: # если у нас есть параметр from_user
any_sender_id = msg.from_user.id # присваеваем ID юзера
else: # иначе
any_sender_id = msg.sender_chat.id # присваеваем ID канала или чата
if any_sender_id == public.id: # проверяем что это нужный паблик
if str(msg.id) in processed_messages:
print(f'Пропускаем уже обработанное message_id={msg.id}')
else:
processed_messages.update({str(msg.id): True})
print(f'Обработка message_id={msg.id}')
text = random.choice(TEXTS)
print(text)
result = await app.send_message(chat_id, text, reply_to_message_id=msg.id)
processed_messages.update({str(result.id): True})
await asyncio.sleep(1) # пауза, чтоб не банили за флуд
app.run(main())