Spaces:
Sleeping
Sleeping
Fix deprecated forward_from_chat and add missing get_client import
Browse files- utils/bot_mode.py +31 -13
utils/bot_mode.py
CHANGED
|
@@ -11,6 +11,7 @@ from utils.mongo_indexer import (
|
|
| 11 |
index_channel_messages_with_iter,
|
| 12 |
MongoNotConfiguredError,
|
| 13 |
)
|
|
|
|
| 14 |
|
| 15 |
logger = Logger(__name__)
|
| 16 |
|
|
@@ -135,13 +136,21 @@ async def index_handler(client: Client, message: Message):
|
|
| 135 |
except Exception:
|
| 136 |
await message.reply_text("β Invalid message link!")
|
| 137 |
return
|
| 138 |
-
# Check if it's a forwarded message
|
| 139 |
-
elif msg_input.
|
| 140 |
-
|
| 141 |
-
if
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
return
|
| 144 |
-
last_msg_id = msg_input.forward_from_message_id
|
| 145 |
# Check if it's just a number (skip count)
|
| 146 |
elif msg_input.text and msg_input.text.strip().isdigit():
|
| 147 |
skip = int(msg_input.text.strip())
|
|
@@ -209,15 +218,24 @@ async def index_handler(client: Client, message: Message):
|
|
| 209 |
except Exception:
|
| 210 |
await message.reply_text("β Invalid message link!")
|
| 211 |
return
|
| 212 |
-
# Check if it's a forwarded message
|
| 213 |
-
elif msg.
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
await message.reply_text("β Please forward a message from a channel.")
|
| 218 |
return
|
| 219 |
-
last_msg_id = msg.forward_from_message_id
|
| 220 |
-
chat_id = msg.forward_from_chat.username or msg.forward_from_chat.id
|
| 221 |
else:
|
| 222 |
await message.reply_text("β Please forward a message from a channel or send a message link.")
|
| 223 |
return
|
|
|
|
| 11 |
index_channel_messages_with_iter,
|
| 12 |
MongoNotConfiguredError,
|
| 13 |
)
|
| 14 |
+
from utils.clients import get_client
|
| 15 |
|
| 16 |
logger = Logger(__name__)
|
| 17 |
|
|
|
|
| 136 |
except Exception:
|
| 137 |
await message.reply_text("β Invalid message link!")
|
| 138 |
return
|
| 139 |
+
# Check if it's a forwarded message (using new forward_origin API)
|
| 140 |
+
elif msg_input.forward_origin:
|
| 141 |
+
from pyrogram.types import MessageOriginChannel
|
| 142 |
+
if isinstance(msg_input.forward_origin, MessageOriginChannel):
|
| 143 |
+
forward_chat = msg_input.forward_origin.chat
|
| 144 |
+
forward_chat_id = forward_chat.username if forward_chat else None
|
| 145 |
+
if not forward_chat_id:
|
| 146 |
+
forward_chat_id = msg_input.forward_origin.chat.id if msg_input.forward_origin.chat else None
|
| 147 |
+
if forward_chat_id != chat_id:
|
| 148 |
+
await message.reply_text("β Forwarded message is from a different channel!")
|
| 149 |
+
return
|
| 150 |
+
last_msg_id = msg_input.forward_origin.message_id
|
| 151 |
+
else:
|
| 152 |
+
await message.reply_text("β Please forward a message from a channel.")
|
| 153 |
return
|
|
|
|
| 154 |
# Check if it's just a number (skip count)
|
| 155 |
elif msg_input.text and msg_input.text.strip().isdigit():
|
| 156 |
skip = int(msg_input.text.strip())
|
|
|
|
| 218 |
except Exception:
|
| 219 |
await message.reply_text("β Invalid message link!")
|
| 220 |
return
|
| 221 |
+
# Check if it's a forwarded message (using new forward_origin API)
|
| 222 |
+
elif msg.forward_origin:
|
| 223 |
+
from pyrogram.types import MessageOriginChannel
|
| 224 |
+
if isinstance(msg.forward_origin, MessageOriginChannel):
|
| 225 |
+
forward_chat = msg.forward_origin.chat
|
| 226 |
+
chat_type = getattr(forward_chat, 'type', None) if forward_chat else None
|
| 227 |
+
type_str = str(chat_type).lower() if chat_type else ""
|
| 228 |
+
if "channel" not in type_str and not getattr(forward_chat, 'is_channel', False) if forward_chat else False:
|
| 229 |
+
await message.reply_text("β Please forward a message from a channel.")
|
| 230 |
+
return
|
| 231 |
+
last_msg_id = msg.forward_origin.message_id
|
| 232 |
+
chat_id = forward_chat.username if forward_chat and forward_chat.username else (forward_chat.id if forward_chat else None)
|
| 233 |
+
if chat_id is None:
|
| 234 |
+
await message.reply_text("β Could not determine channel from forwarded message.")
|
| 235 |
+
return
|
| 236 |
+
else:
|
| 237 |
await message.reply_text("β Please forward a message from a channel.")
|
| 238 |
return
|
|
|
|
|
|
|
| 239 |
else:
|
| 240 |
await message.reply_text("β Please forward a message from a channel or send a message link.")
|
| 241 |
return
|