Skip to content

Commit

Permalink
Added public chat support
Browse files Browse the repository at this point in the history
Session user doesn't need to join the public chat . Input - username (like @python) when cloning from a public chat as source chat.
  • Loading branch information
m4mallu committed Jun 5, 2021
1 parent 2db09e8 commit ce466a0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 37 deletions.
12 changes: 6 additions & 6 deletions plugins/cb_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# --------------------------- Source Button Action ------------------------------ #
@Client.on_callback_query(filters.regex(r'^source_btn$'))
async def source_chat_config(client: Bot, cb: CallbackQuery):
usr = int(cb.message.chat.id)
usr = int(cb.from_user.id)
await cb.message.delete()
source = await client.send_message(
chat_id=cb.message.chat.id,
Expand All @@ -29,7 +29,7 @@ async def source_chat_config(client: Bot, cb: CallbackQuery):
# --------------------------- Destination Button Action ------------------------- #
@Client.on_callback_query(filters.regex(r'^dest_btn$'))
async def dest_chat_config(client: Bot, cb: CallbackQuery):
usr = int(cb.message.chat.id)
usr = int(cb.from_user.id)
await cb.message.delete()
dest = await client.send_message(
chat_id=cb.message.chat.id,
Expand All @@ -46,7 +46,7 @@ async def dest_chat_config(client: Bot, cb: CallbackQuery):
# ---------------------------- Chat View Button Action -------------------------- #
@Client.on_callback_query(filters.regex(r'^view_btn$'))
async def view_config(client: Bot, cb: CallbackQuery):
usr = int(cb.message.chat.id)
usr = int(cb.from_user.id)
if usr in source_chat and destination_chat:
await cb.message.delete()
await client.send_message(
Expand All @@ -63,7 +63,7 @@ async def view_config(client: Bot, cb: CallbackQuery):
# --------------------------- Delete configuration Button Action --------------- #
@Client.on_callback_query(filters.regex(r'^del_cfg_btn$'))
async def del_config(client: Bot, cb: CallbackQuery):
usr = int(cb.message.chat.id)
usr = int(cb.from_user.id)
if usr in source_chat and destination_chat:
source_chat.pop(usr)
destination_chat.pop(usr)
Expand All @@ -75,7 +75,7 @@ async def del_config(client: Bot, cb: CallbackQuery):
# --------------------------- Clone Button Action ----------------------------- #
@Client.on_callback_query(filters.regex(r'^clone_btn$'))
async def clone_button(client: Bot, cb: CallbackQuery):
usr = int(cb.message.chat.id)
usr = int(cb.from_user.id)
if usr in source_chat and destination_chat:
await cb.message.delete()
await clone_medias(client, cb.message)
Expand All @@ -93,7 +93,7 @@ async def help_txt(client: Bot, cb: CallbackQuery):
# --------------------------- Stop Button Action ----------------------------- #
@Client.on_callback_query(filters.regex(r'^stop_clone$'))
async def stop_process(client: Bot, cb: CallbackQuery):
usr = int(cb.message.chat.id)
usr = int(cb.from_user.id)
await cb.message.delete()
clone_status.pop(usr)

Expand Down
80 changes: 50 additions & 30 deletions plugins/chat_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from presets import Presets
from pyrogram import filters, Client
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.errors import FloodWait
from init import source_chat, destination_chat, source_message_id, dest_message_id, help_message_id


Expand Down Expand Up @@ -59,22 +60,41 @@ async def start_bot(client: Bot, message: Message):
async def chat_reply(client: Bot, message: Message):
usr = int(message.from_user.id)
user_bot_me = await client.USER.get_me()
chat_status = []
try:
if message.reply_to_message.message_id == source_message_id[usr]:
if str(message.text).startswith('-100') and message.text[1:].isdigit():
bot_msg = await message.reply_text(text=Presets.WAIT_MSG)
await asyncio.sleep(1)
try:
if destination_chat[usr] == message.text:
await message.delete()
await client.delete_messages(message.chat.id, source_message_id[usr])
await bot_msg.edit(Presets.CHAT_DUPLICATED_MSG)
await asyncio.sleep(5)
await bot_msg.delete()
await start_bot(client, message)
return
except Exception:
pass
chat_id = int(message.text)
elif str(message.text).startswith('@') and bool(str(message.text).isdigit()) == bool(0):
chat_id = str(message.text)
else:
return
bot_msg = await message.reply_text(text=Presets.WAIT_MSG)
await asyncio.sleep(1)
try:
chat_status = await client.USER.get_chat(chat_id)
except FloodWait as e:
await asyncio.sleep(e.x)
except Exception:
await client.delete_messages(message.chat.id, source_message_id[usr])
await bot_msg.edit(Presets.INVALID_CHAT_ID)
await message.delete()
await asyncio.sleep(3)
await bot_msg.delete()
await start_bot(client, message)
return
try:
if destination_chat[usr] == message.text:
await message.delete()
await client.delete_messages(message.chat.id, source_message_id[usr])
await bot_msg.edit(Presets.CHAT_DUPLICATED_MSG)
await asyncio.sleep(5)
await bot_msg.delete()
await start_bot(client, message)
return
except Exception:
pass
if bool(chat_status.username) == bool(0):
try:
await client.USER.get_chat_member(chat_id=int(message.text), user_id=int(user_bot_me.id))
except Exception:
Expand All @@ -86,23 +106,23 @@ async def chat_reply(client: Bot, message: Message):
await bot_msg.delete()
await start_bot(client, message)
return
await client.delete_messages(message.chat.id, source_message_id[usr])
source_chat[usr] = message.text
await message.delete()
source_message_id.pop(usr)
await bot_msg.edit(Presets.SOURCE_CONFIRM.format(source_chat[usr]))
await asyncio.sleep(2)
await start_bot(client, message)
return
else:
await client.delete_messages(message.chat.id, source_message_id[usr])
warn = await message.reply_text(Presets.INVALID_CHAT_ID)
await message.delete()
source_message_id.pop(usr)
await asyncio.sleep(3)
await warn.delete()
await start_bot(client, message)
return
await client.delete_messages(message.chat.id, source_message_id[usr])
source_chat[usr] = message.text
await message.delete()
source_message_id.pop(usr)
await bot_msg.edit(Presets.SOURCE_CONFIRM.format(source_chat[usr]))
await asyncio.sleep(2)
await start_bot(client, message)
return
else:
await client.delete_messages(message.chat.id, source_message_id[usr])
warn = await message.reply_text(Presets.INVALID_CHAT_ID)
await message.delete()
source_message_id.pop(usr)
await asyncio.sleep(3)
await warn.delete()
await start_bot(client, message)
return
except Exception:
if message.reply_to_message.message_id == dest_message_id[usr]:
if str(message.text).startswith('-100') and message.text[1:].isdigit():
Expand Down
2 changes: 1 addition & 1 deletion presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Presets(object):
➡️ 𝐉𝐨𝐢𝐧 𝐭𝐡𝐞 𝐝𝐞𝐬𝐭𝐢𝐧𝐚𝐭𝐢𝐨𝐧 𝐜𝐡𝐚𝐭 𝐚𝐬 𝐚𝐝𝐦𝐢𝐧
➡️ 𝐁𝐨𝐭 𝐝𝐨𝐞𝐬𝐧'𝐭 𝐧𝐞𝐞𝐝 𝐭𝐨 𝐛𝐞 𝐢𝐧 𝐛𝐨𝐭𝐡 𝐜𝐡𝐚𝐭𝐬.
➡️ 𝐒𝐭𝐚𝐫𝐭 𝐭𝐡𝐞 𝐛𝐨𝐭
➡️ 𝐈𝐧𝐩𝐮𝐭 𝐒𝐨𝐮𝐫𝐜𝐞 & 𝐃𝐞𝐬𝐭𝐢𝐧𝐚𝐭𝐢𝐨𝐧 𝐜𝐡𝐚𝐭𝐬
➡️ 𝐈𝐧𝐩𝐮𝐭 𝐒𝐨𝐮𝐫𝐜𝐞 & 𝐃𝐞𝐬𝐭𝐢𝐧𝐚𝐭𝐢𝐨𝐧 𝐜𝐡𝐚𝐭𝐬 : 𝑢𝑠𝑒 '@𝑝𝑦𝑡ℎ𝑜𝑛' 𝑙𝑖𝑘𝑒 𝑢𝑠𝑒𝑟 𝑛𝑎𝑚𝑒 𝑓𝑜𝑟 𝑝𝑢𝑏𝑙𝑖𝑐 𝑐ℎ𝑎𝑡𝑠
➡️ 𝐑𝐮𝐧 𝐂𝐥𝐨𝐧𝐞
𝑀𝓎 𝓇𝑒𝓅𝑜 𝒸𝒶𝓃 𝒷𝑒 𝓈𝑒𝑒 (⦿‿⦿) <a href='https://github.com/m4mallu/clonebot'>𝙃𝙚𝙧𝙚</a>
Expand Down

2 comments on commit ce466a0

@demogorgonaj
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add the feature to skip certain no of files,that us to start from a point

@m4mallu
Copy link
Owner Author

@m4mallu m4mallu commented on ce466a0 Jun 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new update with lots of features including your suggestion will be pushed within one week!

Please sign in to comment.