Skip to content

Commit

Permalink
Clonebot v2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
m4mallu committed Jul 24, 2022
1 parent 67158e4 commit 5129142
Show file tree
Hide file tree
Showing 14 changed files with 670 additions and 435 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@
</a>
</p>
</details>
<details>
<summary><b>Releases</b></summary>
<p align="left">
<a href="https://github.com/m4mallu/clonebot/releases/tag/1.1">
<img src="https://img.shields.io/badge/RELEASE-1.1-orange?style=for-the-badge&logo=gplv3">
</a>
<a href="https://github.com/m4mallu/clonebot/releases/tag/1.2">
<img src="https://img.shields.io/badge/RELEASE-1.2-orange?style=for-the-badge&logo=gplv3">
</a>
<a href="https://github.com/m4mallu/clonebot/releases/tag/1.3">
<img src="https://img.shields.io/badge/RELEASE-1.3-orange?style=for-the-badge&logo=gplv3">
</a>
<a href="https://github.com/m4mallu/clonebot/releases/tag/1.4">
<img src="https://img.shields.io/badge/RELEASE-1.4-orange?style=for-the-badge&logo=gplv3">
</a>
<a href="https://github.com/m4mallu/clonebot/releases/tag/1.5">
<img src="https://img.shields.io/badge/RELEASE-1.5-orange?style=for-the-badge&logo=gplv3">
</a>
</p>
</details>
<details>
<summary><b>License</b></summary>
<p align="left">
Expand Down
5 changes: 3 additions & 2 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from user import User
from pyrogram import Client
from presets import Presets as Msg
from pyrogram.enums import ParseMode


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

def __init__(self):
super().__init__(
"bot_session",
name="bot_session",
api_hash=Config.API_HASH,
api_id=Config.APP_ID,
bot_token=Config.TG_BOT_TOKEN,
Expand All @@ -36,7 +37,7 @@ async def start(self):
await super().start()
usr_bot_me = await self.get_me()
bot_me = self.USER_ID
self.set_parse_mode("html")
self.set_parse_mode(ParseMode.HTML)
self.LOGGER(__name__).info(
f"@{usr_bot_me.username} started! "
)
Expand Down
113 changes: 82 additions & 31 deletions library/buttons.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,127 @@

from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton

# Buttons used

home_button = [
[InlineKeyboardButton("🌏 Source", "source_btn"),
InlineKeyboardButton("⬇️ Fr. Id", "from_btn"),
InlineKeyboardButton("❓ Help", url="https://telegra.ph/Clonebot-UI-Help-05-30")],
[InlineKeyboardButton("🎯 Target", "target_btn"),
InlineKeyboardButton("⬆️ To Id", "up_to_btn"),
InlineKeyboardButton("Types ➡", "types_btn")],
[InlineKeyboardButton("Delayed", "delay_btn"),
InlineKeyboardButton("Caption", "caption_btn"),
InlineKeyboardButton("FNAC", "f_caption_btn")],
[InlineKeyboardButton("🔎️ View", "view_btn"),
InlineKeyboardButton("🚮 Reset", "rst_btn"),
InlineKeyboardButton("❌ Close", "close_btn")],
[InlineKeyboardButton("🚦 Clone Medias 🚦", "clone_btn")]
[
InlineKeyboardButton("🌏 Source", "source_btn"),
InlineKeyboardButton("⬇️ Fr. Id", "from_btn"),
InlineKeyboardButton("❓ Help", url="https://bit.ly/3z2jquF")
],
[
InlineKeyboardButton("🎯 Target", "target_btn"),
InlineKeyboardButton("⬆️ To Id", "up_to_btn"),
InlineKeyboardButton("Types ➡", "types_btn")
],
[
InlineKeyboardButton("Delayed", "delay_btn"),
InlineKeyboardButton("Caption", "caption_btn"),
InlineKeyboardButton("FNAC", "f_caption_btn")
],
[
InlineKeyboardButton("🔎️ View", "view_btn"),
InlineKeyboardButton("✍️ CC", "cust_captn_btn"),
InlineKeyboardButton("❌ Close", "close_btn")
],
[
InlineKeyboardButton("🗑 Reset", "rst_btn"),
InlineKeyboardButton("🔄 Restart", "restart_btn")
],
[
InlineKeyboardButton("🚦 Clone Messages 🚦", "clone_btn")
]
]


start_button = [
[InlineKeyboardButton("🏅 GitHub 🏅", url="github.com/m4mallu/clonebot"),
InlineKeyboardButton("⚙️Settings ⚙", "start_btn")]
[
InlineKeyboardButton("🏅 GitHub 🏅", url="github.com/m4mallu/clonebot"),
InlineKeyboardButton("⚙️Settings ⚙", "start_btn")
]
]


types_button = [
[InlineKeyboardButton(" ⏺ Docs", "docs_btn"),
InlineKeyboardButton(" ⏺ Video", "video_btn"),
InlineKeyboardButton(" ⏺ Audio", "audio_btn")],
[InlineKeyboardButton(" ⏺ Photo", "photo_btn"),
InlineKeyboardButton(" ⏺ Voice", "voice_btn"),
InlineKeyboardButton("⚙️ View", "view_types")],
[InlineKeyboardButton("⬅️ Back", "start_btn")]
[
InlineKeyboardButton("Docs ✅", "docs_yes_btn"),
InlineKeyboardButton("Video ✅", "video_yes_btn"),
InlineKeyboardButton("Audio ✅", "audio_yes_btn")
],
[
InlineKeyboardButton("Photo ✅", "photo_yes_btn"),
InlineKeyboardButton("Voice ✅", "voice_yes_btn"),
InlineKeyboardButton("Text ✅", "text_yes_btn")
],
[
InlineKeyboardButton("⚙️ View", "view_types"),
InlineKeyboardButton("⬅️ Back", "start_btn")
]
]


stop_button = [
[InlineKeyboardButton("🚫 STOP 🚫", "stop_clone")]
[
InlineKeyboardButton("🚫 STOP 🚫", "stop_clone")
]
]


finished_button = [
[InlineKeyboardButton("🏠 HOME", "start_btn"),
InlineKeyboardButton("❌ CLOSE", "close_btn")]
[
InlineKeyboardButton("Home", "start_btn"),
InlineKeyboardButton("Close", "close_btn")
]
]


close_button = [
[
InlineKeyboardButton("Delete", "close_btn"),
InlineKeyboardButton("Close", "clear_btn")
]
]


terminate_btn = [
[InlineKeyboardButton("🧸 Updates", url="https://github.com/m4mallu/clonebot-ui"),
InlineKeyboardButton("❓ Usage", url="https://telegra.ph/Clonebot-UI-Help-05-30")],
[InlineKeyboardButton("🚫 Terminate", "terminate_btn"),
InlineKeyboardButton("🏠 Home", "start_btn")]
[
InlineKeyboardButton("🧸 Updates", url="https://github.com/m4mallu/clonebot"),
InlineKeyboardButton("❓ Usage", url="https://bit.ly/3z2jquF")
],
[
InlineKeyboardButton("🚫 Terminate", "terminate_btn"),
InlineKeyboardButton("🏠 Home", "start_btn")
]
]


indexing_skip_button = [
[
InlineKeyboardButton("🕹 Skip", "index_skip_btn")
]
]


purging_skip_button = [
[
InlineKeyboardButton("🕹 Skip", "purge_skip_btn")
]
]


purge_button = [
[
InlineKeyboardButton("Nop", "purge_no_btn"),
InlineKeyboardButton("Purge it 👍", "purge_yes_btn")
]
]

# markups used
caption_cnf_button = [
[
InlineKeyboardButton("YES ✅", "capt_cnf_yes_btn"),
InlineKeyboardButton("NO ❌", "capt_cnf_no_btn")
]
]


reply_markup_purge = InlineKeyboardMarkup(purge_button)

Expand All @@ -93,3 +140,7 @@
reply_markup_finished = InlineKeyboardMarkup(finished_button)

reply_markup_types_button = InlineKeyboardMarkup(types_button)

reply_markup_close = InlineKeyboardMarkup(close_button)

reply_markup_cap_cnf = InlineKeyboardMarkup(caption_cnf_button)
22 changes: 14 additions & 8 deletions library/chat_support.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#----------------------------------- https://github.com/m4mallu/clonebot-ui -----------------------------------------#
#----------------------------------- https://github.com/m4mallu/clonebot ----------------------------------------------#
import os
import csv
import time
import shutil
import asyncio
import itertools
Expand All @@ -13,28 +14,28 @@
async def find_msg_id(client, id, chat_id):
id_last_msg = int()
try:
async for user_message in client.USER.iter_history(chat_id):
messages = await client.USER.get_messages(chat_id, user_message.message_id, replies=0)
async for user_message in client.USER.get_chat_history(chat_id):
messages = await client.USER.get_messages(chat_id, user_message.id, replies=0)
for file_type in file_types:
media = getattr(messages, file_type, None)
if media is not None:
id_last_msg = str(messages.message_id).split(" ")[0]
id_last_msg = str(messages.id).split(" ")[0]
await msg_id_limit(id, id_last_msg)
await to_msg_id_cnf_db(id, id_last_msg)
file_types.clear()
file_types.extend(Presets.FILE_TYPES)
return
except FloodWait as e:
await asyncio.sleep(e.x)
await asyncio.sleep(e.value)
except Exception:
pass


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


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


# Function to find DC Id:
# Function to find DC ID:
async def find_dc(chat_status):
dc = chat_status.dc_id
dc_id = {dc == 1: "𝙼𝚒𝚊𝚖𝚒 𝙵𝙻, 𝚄𝚂𝙰 [𝐃𝐂 𝟏]", dc == 2: "𝙰𝚖𝚜𝚝𝚎𝚛𝚍𝚊𝚖, 𝙽𝙻 [𝐃𝐂 𝟐]", dc == 3: "𝙼𝚒𝚊𝚖𝚒 𝙵𝙻, 𝚄𝚂𝙰 [𝐃𝐂 𝟑]",
Expand Down Expand Up @@ -88,3 +89,8 @@ async def del_user_cfg(id):
shutil.rmtree(cfg_path)
except Exception:
pass


# Function to get the current time
async def get_time():
return time.strftime("%I:%M %p")
5 changes: 3 additions & 2 deletions library/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
index_skip_key = {} # Skip indexing function key
purge_skip_key = {} # Purge function key

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

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

0 comments on commit 5129142

Please sign in to comment.