iShotaBot/modules/repeater.py

55 lines
1.4 KiB
Python
Raw Permalink Normal View History

2021-11-28 14:55:10 +00:00
from pyrogram import Client, filters, ContinuePropagation
from pyrogram.types import Message
from init import bot
2021-11-28 14:55:10 +00:00
last_msg = {}
last_repeat_msg = {}
repeat_count = {}
@bot.on_message(filters.incoming & filters.group)
2021-11-28 14:55:10 +00:00
async def repeater_handler(client: Client, message: Message):
global last_msg, last_repeat_msg, repeat_count
group_id = message.chat.id
try:
last_msg[group_id]
except KeyError:
2024-06-19 12:47:36 +00:00
last_msg[group_id] = {}
2021-11-28 14:55:10 +00:00
try:
last_repeat_msg[group_id]
except KeyError:
last_repeat_msg[group_id] = ""
msg = t_msg = message.text
2021-11-29 05:11:21 +00:00
if not msg:
raise ContinuePropagation
2023-01-12 13:19:54 +00:00
if (
msg.startswith("/")
or msg.startswith("!")
or msg.startswith(",")
or msg.startswith("")
):
2021-11-29 05:11:21 +00:00
raise ContinuePropagation
2021-11-28 14:55:10 +00:00
2024-06-19 12:47:36 +00:00
last_msg_text = last_msg[group_id].get("text", "")
last_msg_id = last_msg[group_id].get("id", 0)
if message.id == last_msg_id:
raise ContinuePropagation
if msg != last_msg_text or msg == last_repeat_msg[group_id]:
last_msg[group_id] = {"text": msg, "id": message.id}
2021-11-28 14:55:10 +00:00
repeat_count[group_id] = 0
else:
repeat_count[group_id] += 1
last_repeat_msg[group_id] = ""
if repeat_count[group_id] >= 2:
await client.send_message(group_id, t_msg)
repeat_count[group_id] = 0
2024-06-19 12:47:36 +00:00
last_msg[group_id] = {}
2021-11-28 14:55:10 +00:00
last_repeat_msg[group_id] = msg
2021-11-29 05:11:21 +00:00
raise ContinuePropagation