-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfwdall.py
45 lines (39 loc) · 1.71 KB
/
fwdall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import asyncio
from pyrogram import Client, filters, enums
from pyrogram.errors import FloodWait, RPCError
from pyrogram.types import Message
from utils.misc import modules_help, prefix
@Client.on_message(filters.command(["fwdall"], prefix) & filters.me)
async def forward(client: Client, message: Message):
sta = None if len(message.text.split(" ")) < 2 else message.text.split(" ")[1]
if sta is not None:
await message.edit("<b>Working...</b>", parse_mode=enums.ParseMode.HTML)
try:
target = await client.get_chat(sta)
except RPCError:
await message.edit(
"<b>Unknown target.</b>", parse_mode=enums.ParseMode.HTML
)
return
msgs = []
async for msg in client.get_chat_history(message.chat.id):
msgs.append(msg.id)
if len(msgs) >= 100:
try:
await client.forward_messages(target.id, message.chat.id, msgs)
except FloodWait as e:
await asyncio.sleep(e.x)
await client.forward_messages(target.id, message.chat.id, msgs)
msgs = []
if msgs:
try:
await client.forward_messages(target.id, message.chat.id, msgs)
except FloodWait as e:
await asyncio.sleep(e.x)
await client.forward_messages(target.id, message.chat.id, msgs)
await message.edit("<b>Done successfully.</b>", parse_mode=enums.ParseMode.HTML)
else:
await message.edit("<b>No target passed.</b>", parse_mode=enums.ParseMode.HTML)
modules_help["fwdall"] = {
"fwdall [target]*": "forward all messages to defined target [username/chat_id/chat_link]"
}