feat(collector): implement historical channel scraper command and ui guide
This commit is contained in:
+37
-4
@@ -17,7 +17,7 @@ def get_main_menu_keyboard():
|
||||
[Button.text("🔑 Request Login Code", resize=True), Button.text("📊 Fleet Statistics", resize=True)],
|
||||
[Button.text("📡 Monitored Sources", resize=True), Button.text("🎯 Target Channels", resize=True)],
|
||||
[Button.text("➕ Add Source Guide", resize=True), Button.text("➕ Add Target Guide", resize=True)],
|
||||
[Button.text("❓ Help & Documentation", resize=True)]
|
||||
[Button.text("📥 Scrape History Guide", resize=True), Button.text("❓ Help & Documentation", resize=True)]
|
||||
]
|
||||
|
||||
class AdminBotService:
|
||||
@@ -137,6 +137,38 @@ class AdminBotService:
|
||||
result = await self.collector.submit_password(pwd)
|
||||
await status_msg.edit(result, parse_mode="html", buttons=get_main_menu_keyboard())
|
||||
|
||||
# --- History Scraper Commands ---
|
||||
@self.client.on(events.NewMessage(pattern=r"(?i)^(📥 Scrape History Guide)$"))
|
||||
async def cmd_scrape_guide(event: events.NewMessage.Event):
|
||||
if not self.is_admin(event.sender_id):
|
||||
return
|
||||
guide = (
|
||||
"📥 <b>Historical Channel Scraper:</b>\n\n"
|
||||
"Import previous/past posts from any channel:\n"
|
||||
"<code>/scrape_history <channel_id> [number_of_posts]</code>\n\n"
|
||||
"<i>Example (Scrape last 30 posts):</i>\n"
|
||||
"<code>/scrape_history -1001234567890 30</code>\n\n"
|
||||
"<i>(Default is 20 posts if count is omitted).</i>"
|
||||
)
|
||||
await event.reply(guide, parse_mode="html")
|
||||
|
||||
@self.client.on(events.NewMessage(pattern=r"^/scrape_history\s+(-?\d+)(?:\s+(\d+))?"))
|
||||
async def cmd_scrape_history(event: events.NewMessage.Event):
|
||||
if not self.is_admin(event.sender_id):
|
||||
return
|
||||
if not self.collector:
|
||||
await event.reply("Collector service not linked.")
|
||||
return
|
||||
ch_id = int(event.pattern_match.group(1))
|
||||
limit = int(event.pattern_match.group(2)) if event.pattern_match.group(2) else 20
|
||||
|
||||
status_msg = await event.reply(f"⏳ Scraping the last <b>{limit}</b> posts from <code>{ch_id}</code> in the background...", parse_mode="html")
|
||||
|
||||
async def progress_notify(txt: str):
|
||||
await status_msg.edit(txt, parse_mode="html", buttons=get_main_menu_keyboard())
|
||||
|
||||
await self.collector.scrape_channel_history(channel_id=ch_id, limit=limit, progress_callback=progress_notify)
|
||||
|
||||
# --- Statistics ---
|
||||
@self.client.on(events.NewMessage(pattern=r"(?i)^(/stats|📊 Fleet Statistics)$"))
|
||||
async def cmd_stats(event: events.NewMessage.Event):
|
||||
@@ -259,9 +291,10 @@ class AdminBotService:
|
||||
help_text = (
|
||||
"📖 <b>Copykar Bot Quick Help</b>\n\n"
|
||||
"1. <b>Authentication:</b> Click <code>🔑 Request Login Code</code> and submit via <code>/code <12345></code>.\n"
|
||||
"2. <b>Monitored Sources:</b> Add channels the userbot should listen to via <code>/add_source</code>.\n"
|
||||
"3. <b>Review Flow:</b> AI scans posts, checks duplicates, and sends drafts to the review channel with inline approval buttons.\n"
|
||||
"4. <b>Publishing:</b> Approved posts are published to your target channels strictly according to their interval minutes."
|
||||
"2. <b>Monitored Sources:</b> Add channels via <code>/add_source</code>.\n"
|
||||
"3. <b>Historical Posts:</b> Backfill existing posts using <code>/scrape_history <channel_id> [limit]</code>.\n"
|
||||
"4. <b>Review Flow:</b> AI scans posts, checks duplicates, and sends drafts to the review channel with inline approval buttons.\n"
|
||||
"5. <b>Publishing:</b> Approved posts are published to your target channels strictly according to their interval minutes."
|
||||
)
|
||||
await event.reply(help_text, parse_mode="html", buttons=get_main_menu_keyboard())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user