Skip to content

Commit 5129142

Browse files
committed
Clonebot v2
Upgraded to Pyrogram 2.x 'Text' file type included. Working UI optimized. Button layout optimization. clone from older messages retained. Clone report facility. Get chat id and message id by forwarding message to the bot chat. Bot restart method included. Set a custom caption by sending a formatted text to the bot chat. Code optimization and performance improvements.
1 parent 67158e4 commit 5129142

File tree

14 files changed

+670
-435
lines changed

14 files changed

+670
-435
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@
6363
</a>
6464
</p>
6565
</details>
66+
<details>
67+
<summary><b>Releases</b></summary>
68+
<p align="left">
69+
<a href="https://github.com/m4mallu/clonebot/releases/tag/1.1">
70+
<img src="https://img.shields.io/badge/RELEASE-1.1-orange?style=for-the-badge&logo=gplv3">
71+
</a>
72+
<a href="https://github.com/m4mallu/clonebot/releases/tag/1.2">
73+
<img src="https://img.shields.io/badge/RELEASE-1.2-orange?style=for-the-badge&logo=gplv3">
74+
</a>
75+
<a href="https://github.com/m4mallu/clonebot/releases/tag/1.3">
76+
<img src="https://img.shields.io/badge/RELEASE-1.3-orange?style=for-the-badge&logo=gplv3">
77+
</a>
78+
<a href="https://github.com/m4mallu/clonebot/releases/tag/1.4">
79+
<img src="https://img.shields.io/badge/RELEASE-1.4-orange?style=for-the-badge&logo=gplv3">
80+
</a>
81+
<a href="https://github.com/m4mallu/clonebot/releases/tag/1.5">
82+
<img src="https://img.shields.io/badge/RELEASE-1.5-orange?style=for-the-badge&logo=gplv3">
83+
</a>
84+
</p>
85+
</details>
6686
<details>
6787
<summary><b>License</b></summary>
6888
<p align="left">

bot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from user import User
55
from pyrogram import Client
66
from presets import Presets as Msg
7+
from pyrogram.enums import ParseMode
78

89

910
if bool(os.environ.get("ENV", False)):
@@ -20,7 +21,7 @@ class Bot(Client):
2021

2122
def __init__(self):
2223
super().__init__(
23-
"bot_session",
24+
name="bot_session",
2425
api_hash=Config.API_HASH,
2526
api_id=Config.APP_ID,
2627
bot_token=Config.TG_BOT_TOKEN,
@@ -36,7 +37,7 @@ async def start(self):
3637
await super().start()
3738
usr_bot_me = await self.get_me()
3839
bot_me = self.USER_ID
39-
self.set_parse_mode("html")
40+
self.set_parse_mode(ParseMode.HTML)
4041
self.LOGGER(__name__).info(
4142
f"@{usr_bot_me.username} started! "
4243
)

library/buttons.py

Lines changed: 82 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,127 @@
11

22
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
33

4-
# Buttons used
54

65
home_button = [
7-
[InlineKeyboardButton("🌏 Source", "source_btn"),
8-
InlineKeyboardButton("⬇️ Fr. Id", "from_btn"),
9-
InlineKeyboardButton("❓ Help", url="https://telegra.ph/Clonebot-UI-Help-05-30")],
10-
[InlineKeyboardButton("🎯 Target", "target_btn"),
11-
InlineKeyboardButton("⬆️ To Id", "up_to_btn"),
12-
InlineKeyboardButton("Types ➡", "types_btn")],
13-
[InlineKeyboardButton("Delayed", "delay_btn"),
14-
InlineKeyboardButton("Caption", "caption_btn"),
15-
InlineKeyboardButton("FNAC", "f_caption_btn")],
16-
[InlineKeyboardButton("🔎️ View", "view_btn"),
17-
InlineKeyboardButton("🚮 Reset", "rst_btn"),
18-
InlineKeyboardButton("❌ Close", "close_btn")],
19-
[InlineKeyboardButton("🚦 Clone Medias 🚦", "clone_btn")]
6+
[
7+
InlineKeyboardButton("🌏 Source", "source_btn"),
8+
InlineKeyboardButton("⬇️ Fr. Id", "from_btn"),
9+
InlineKeyboardButton("❓ Help", url="https://bit.ly/3z2jquF")
10+
],
11+
[
12+
InlineKeyboardButton("🎯 Target", "target_btn"),
13+
InlineKeyboardButton("⬆️ To Id", "up_to_btn"),
14+
InlineKeyboardButton("Types ➡", "types_btn")
15+
],
16+
[
17+
InlineKeyboardButton("Delayed", "delay_btn"),
18+
InlineKeyboardButton("Caption", "caption_btn"),
19+
InlineKeyboardButton("FNAC", "f_caption_btn")
20+
],
21+
[
22+
InlineKeyboardButton("🔎️ View", "view_btn"),
23+
InlineKeyboardButton("✍️ CC", "cust_captn_btn"),
24+
InlineKeyboardButton("❌ Close", "close_btn")
25+
],
26+
[
27+
InlineKeyboardButton("🗑 Reset", "rst_btn"),
28+
InlineKeyboardButton("🔄 Restart", "restart_btn")
29+
],
30+
[
31+
InlineKeyboardButton("🚦 Clone Messages 🚦", "clone_btn")
32+
]
2033
]
2134

2235

2336
start_button = [
24-
[InlineKeyboardButton("🏅 GitHub 🏅", url="github.com/m4mallu/clonebot"),
25-
InlineKeyboardButton("⚙️Settings ⚙", "start_btn")]
37+
[
38+
InlineKeyboardButton("🏅 GitHub 🏅", url="github.com/m4mallu/clonebot"),
39+
InlineKeyboardButton("⚙️Settings ⚙", "start_btn")
40+
]
2641
]
2742

2843

2944
types_button = [
30-
[InlineKeyboardButton(" ⏺ Docs", "docs_btn"),
31-
InlineKeyboardButton(" ⏺ Video", "video_btn"),
32-
InlineKeyboardButton(" ⏺ Audio", "audio_btn")],
33-
[InlineKeyboardButton(" ⏺ Photo", "photo_btn"),
34-
InlineKeyboardButton(" ⏺ Voice", "voice_btn"),
35-
InlineKeyboardButton("⚙️ View", "view_types")],
36-
[InlineKeyboardButton("⬅️ Back", "start_btn")]
45+
[
46+
InlineKeyboardButton("Docs ✅", "docs_yes_btn"),
47+
InlineKeyboardButton("Video ✅", "video_yes_btn"),
48+
InlineKeyboardButton("Audio ✅", "audio_yes_btn")
49+
],
50+
[
51+
InlineKeyboardButton("Photo ✅", "photo_yes_btn"),
52+
InlineKeyboardButton("Voice ✅", "voice_yes_btn"),
53+
InlineKeyboardButton("Text ✅", "text_yes_btn")
54+
],
55+
[
56+
InlineKeyboardButton("⚙️ View", "view_types"),
57+
InlineKeyboardButton("⬅️ Back", "start_btn")
58+
]
3759
]
3860

3961

4062
stop_button = [
41-
[InlineKeyboardButton("🚫 STOP 🚫", "stop_clone")]
63+
[
64+
InlineKeyboardButton("🚫 STOP 🚫", "stop_clone")
65+
]
4266
]
4367

4468

4569
finished_button = [
46-
[InlineKeyboardButton("🏠 HOME", "start_btn"),
47-
InlineKeyboardButton("❌ CLOSE", "close_btn")]
70+
[
71+
InlineKeyboardButton("Home", "start_btn"),
72+
InlineKeyboardButton("Close", "close_btn")
73+
]
74+
]
75+
76+
77+
close_button = [
78+
[
79+
InlineKeyboardButton("Delete", "close_btn"),
80+
InlineKeyboardButton("Close", "clear_btn")
81+
]
4882
]
4983

5084

5185
terminate_btn = [
52-
[InlineKeyboardButton("🧸 Updates", url="https://github.com/m4mallu/clonebot-ui"),
53-
InlineKeyboardButton("❓ Usage", url="https://telegra.ph/Clonebot-UI-Help-05-30")],
54-
[InlineKeyboardButton("🚫 Terminate", "terminate_btn"),
55-
InlineKeyboardButton("🏠 Home", "start_btn")]
86+
[
87+
InlineKeyboardButton("🧸 Updates", url="https://github.com/m4mallu/clonebot"),
88+
InlineKeyboardButton("❓ Usage", url="https://bit.ly/3z2jquF")
89+
],
90+
[
91+
InlineKeyboardButton("🚫 Terminate", "terminate_btn"),
92+
InlineKeyboardButton("🏠 Home", "start_btn")
93+
]
5694
]
5795

96+
5897
indexing_skip_button = [
5998
[
6099
InlineKeyboardButton("🕹 Skip", "index_skip_btn")
61100
]
62101
]
63102

103+
64104
purging_skip_button = [
65105
[
66106
InlineKeyboardButton("🕹 Skip", "purge_skip_btn")
67107
]
68108
]
69109

110+
70111
purge_button = [
71112
[
72113
InlineKeyboardButton("Nop", "purge_no_btn"),
73114
InlineKeyboardButton("Purge it 👍", "purge_yes_btn")
74115
]
75116
]
76117

77-
# markups used
118+
caption_cnf_button = [
119+
[
120+
InlineKeyboardButton("YES ✅", "capt_cnf_yes_btn"),
121+
InlineKeyboardButton("NO ❌", "capt_cnf_no_btn")
122+
]
123+
]
124+
78125

79126
reply_markup_purge = InlineKeyboardMarkup(purge_button)
80127

@@ -93,3 +140,7 @@
93140
reply_markup_finished = InlineKeyboardMarkup(finished_button)
94141

95142
reply_markup_types_button = InlineKeyboardMarkup(types_button)
143+
144+
reply_markup_close = InlineKeyboardMarkup(close_button)
145+
146+
reply_markup_cap_cnf = InlineKeyboardMarkup(caption_cnf_button)

library/chat_support.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#----------------------------------- https://github.com/m4mallu/clonebot-ui -----------------------------------------#
1+
#----------------------------------- https://github.com/m4mallu/clonebot ----------------------------------------------#
22
import os
33
import csv
4+
import time
45
import shutil
56
import asyncio
67
import itertools
@@ -13,28 +14,28 @@
1314
async def find_msg_id(client, id, chat_id):
1415
id_last_msg = int()
1516
try:
16-
async for user_message in client.USER.iter_history(chat_id):
17-
messages = await client.USER.get_messages(chat_id, user_message.message_id, replies=0)
17+
async for user_message in client.USER.get_chat_history(chat_id):
18+
messages = await client.USER.get_messages(chat_id, user_message.id, replies=0)
1819
for file_type in file_types:
1920
media = getattr(messages, file_type, None)
2021
if media is not None:
21-
id_last_msg = str(messages.message_id).split(" ")[0]
22+
id_last_msg = str(messages.id).split(" ")[0]
2223
await msg_id_limit(id, id_last_msg)
2324
await to_msg_id_cnf_db(id, id_last_msg)
2425
file_types.clear()
2526
file_types.extend(Presets.FILE_TYPES)
2627
return
2728
except FloodWait as e:
28-
await asyncio.sleep(e.x)
29+
await asyncio.sleep(e.value)
2930
except Exception:
3031
pass
3132

3233

3334
# Function to find percentage of the total process
34-
async def calc_percentage(sp, ep, message_id):
35+
async def calc_percentage(sp, ep, msg_id):
3536
const = pct = int()
3637
const = (ep - sp) + 1
37-
pct = ((message_id + const) - ep) / const * 100 # Credits to ma wife to find a formula !
38+
pct = ((msg_id + const) - ep) / const * 100 # Credits to my wife to find a formula !
3839
return pct
3940

4041

@@ -45,7 +46,7 @@ async def calc_progress(pct):
4546
return progress
4647

4748

48-
# Function to find DC Id:
49+
# Function to find DC ID:
4950
async def find_dc(chat_status):
5051
dc = chat_status.dc_id
5152
dc_id = {dc == 1: "𝙼𝚒𝚊𝚖𝚒 𝙵𝙻, 𝚄𝚂𝙰 [𝐃𝐂 𝟏]", dc == 2: "𝙰𝚖𝚜𝚝𝚎𝚛𝚍𝚊𝚖, 𝙽𝙻 [𝐃𝐂 𝟐]", dc == 3: "𝙼𝚒𝚊𝚖𝚒 𝙵𝙻, 𝚄𝚂𝙰 [𝐃𝐂 𝟑]",
@@ -88,3 +89,8 @@ async def del_user_cfg(id):
8889
shutil.rmtree(cfg_path)
8990
except Exception:
9091
pass
92+
93+
94+
# Function to get the current time
95+
async def get_time():
96+
return time.strftime("%I:%M %p")

library/sql.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
index_skip_key = {} # Skip indexing function key
1212
purge_skip_key = {} # Purge function key
1313

14-
master_index = [] # Unique Id index of cloning medias (including target chat)
15-
file_types = ["document", "video", "audio", "voice", "photo"]
14+
custom_caption = {} # Custom caption key
15+
master_index = [] # Unique id index of cloning medias (including target chat)
16+
file_types = ["document", "video", "audio", "voice", "photo", "text"]
1617

1718
if bool(os.environ.get("ENV", False)):
1819
from sample_config import Config

0 commit comments

Comments
 (0)