-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathshift.py
137 lines (114 loc) · 3.89 KB
/
shift.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import asyncio
import logging
from pyrogram import Client, enums, filters
from pyrogram.errors import RPCError
from utils.misc import modules_help, prefix
from utils.scripts import text, edit_or_reply, format_exc
# Helper function to get text from a message
def text(message):
return message.reply_to_message.text if message.reply_to_message else ""
# Helper function to convert limit to an integer or None
def parse_limit(limit):
return int(limit) if limit and limit.isdigit() else None
fromchat = None
tochat = None
@Client.on_message(filters.command("shift", prefix) & filters.me)
async def shift(client, message):
lol = await edit_or_reply(message, "Processing please wait")
x = message.text.split(None, 1)[1]
x = x.replace(" ", "")
try:
fromchat, tochat, limit = x.split("|")
except:
try:
fromchat, tochat, limit = x.split("|")
except:
await lol.edit("Check command syntax", parse_mode=enums.ParseMode.HTML)
try:
fromchat = int(fromchat)
except:
if not (fromchat.startswith("@")):
await lol.edit("Enter a vailed username or id")
return
try:
tochat = int(tochat)
except:
if not (tochat.startswith("@")):
await lol.edit("Enter a vailed username or id")
return
a = 0
if limit == "None" or limit == "none":
try:
async for message in client.get_chat_history(fromchat):
try:
await message.copy(tochat)
a = a + 1
except Exception as e:
await lol.edit(e)
pass
except RPCError as i:
await lol.edit(i)
pass
await asyncio.sleep(1)
await lol.edit(
f"Successfully shifted {a} messages from {fromchat} to {tochat}"
)
except RPCError as i:
await lol.edit(i)
return
else:
try:
limit = int(limit)
except:
lol.edit("Enter a vailed limit")
return
try:
async for message in client.get_chat_history(fromchat, limit=limit):
try:
await message.copy(tochat)
a = a + 1
except Exception as e:
await lol.edit(e)
pass
except RPCError as i:
await lol.edit(i)
pass
await asyncio.sleep(1)
await lol.edit(
f"Successfully shifted {a} messages from {fromchat} to {tochat}"
)
except RPCError as i:
await lol.edit(i)
return
@Client.on_message(filters.command("dmshift", prefix) & filters.me)
async def dmshift(client, message):
await message.edit("Processing, please wait...")
command_parts = message.text.split()
if len(command_parts) != 2:
await message.edit(
"Invalid command format. Use: !dmshift @username_or_id",
parse_mode=enums.ParseMode.HTML,
)
return
x = command_parts[1]
if not message.reply_to_message:
await message.edit("Reply to any message to deliver.")
return
reply = message.reply_to_message
try:
x = int(x)
except ValueError:
if not x.startswith("@"):
await message.edit("Enter a valid username or ID.")
return
try:
await reply.copy(chat_id=x)
except Exception as e:
await message.edit(format_exc(e))
return
await message.edit(f"Message Delivered to {x}")
modules_help["shift"] = {
"shift": "Steal all from one chat to other chat \n .shift fromchat | to chat | limit none for no limits\nNote: | is essential",
"dmshift": "forward a message to someone without forward tag",
"Special Thanks": "FridayUB",
}