Yous135774 commited on
Commit
3fee5e8
·
verified ·
1 Parent(s): 304cb4d

Update bot.py

Browse files
Files changed (1) hide show
  1. bot.py +36 -0
bot.py CHANGED
@@ -1686,6 +1686,42 @@ async def help_cmd(interaction: discord.Interaction):
1686
  # ================================
1687
  # 🚀 22. Bot Startup & Hugging Face Keep-Alive
1688
  # ================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1689
  @bot.event
1690
  async def on_ready():
1691
  print("⏳ جاري البحث عن نسخ احتياطية للبيانات في ديسكورد...")
 
1686
  # ================================
1687
  # 🚀 22. Bot Startup & Hugging Face Keep-Alive
1688
  # ================================
1689
+ @tasks.loop(minutes=15)
1690
+ async def advanced_tracker_loop():
1691
+ tracker_data = load_tracker()
1692
+ scraper = cloudscraper.create_scraper()
1693
+
1694
+ for channel_id_str, sites in tracker_data.get("channels", {}).items():
1695
+ channel = bot.get_channel(int(channel_id_str))
1696
+ if not channel: continue
1697
+
1698
+ for site in sites:
1699
+ try:
1700
+ res = await asyncio.to_thread(scraper.get, site["url"], timeout=10)
1701
+ soup = BeautifulSoup(res.text, 'html.parser')
1702
+
1703
+ links = soup.find_all('a', href=True)
1704
+ chapter_links = [a['href'] for a in links if re.search(r'chapter|ch|فصل|episode', a['href'].lower())]
1705
+ current_hash = chapter_links[0] if chapter_links else str(len(res.text))
1706
+
1707
+ if current_hash != site.get("latest_hash"):
1708
+ site["latest_hash"] = current_hash
1709
+ save_tracker(tracker_data)
1710
+
1711
+ new_url = current_hash if current_hash.startswith("http") else urllib.parse.urljoin(site["url"], current_hash)
1712
+
1713
+ embed = discord.Embed(
1714
+ title=f"🚀 تحديث جديد: {site['title_ar']}",
1715
+ description=f"تم صدور فصل جديد من المانهوا!\n\n🔗 **[اضغط هنا لقراءة الفصل]({new_url})**",
1716
+ color=0xe74c3c
1717
+ )
1718
+ embed.set_thumbnail(url=site["img_url"])
1719
+ embed.set_footer(text=f"العمل الأصلي: {site['title_en']}")
1720
+
1721
+ await channel.send(embed=embed)
1722
+ await asyncio.sleep(2)
1723
+ except Exception as e:
1724
+ pass
1725
  @bot.event
1726
  async def on_ready():
1727
  print("⏳ جاري البحث عن نسخ احتياطية للبيانات في ديسكورد...")