proxy.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from asyncio import get_event_loop, sleep
  2. from pyrogram import filters
  3. from pyrogram.types import CallbackQuery, Message
  4. from wbb import app, arq
  5. from wbb.core.keyboard import ikb
  6. proxies = []
  7. async def get_proxies():
  8. global proxies
  9. proxies = (await arq.proxy()).result
  10. loop = get_event_loop()
  11. loop.create_task(get_proxies())
  12. def url_from_proxy(proxy: str) -> str:
  13. creds, proxy = proxy.split("//")[1:][0].split("@")
  14. user, passwd = creds.split(":")
  15. host, port = proxy.split(":")
  16. return (
  17. f"https://t.me/socks?server={host}&port="
  18. + f"{port}&user={user}&pass={passwd}"
  19. )
  20. @app.on_message(filters.command("proxy") & ~filters.edited)
  21. async def proxy_func(_, message: Message):
  22. if len(proxies) == 0:
  23. await asyncio.sleep(0.5)
  24. location = proxies[0].location
  25. proxy = proxies[0].proxy
  26. url = url_from_proxy(proxy)
  27. keyb = ikb(
  28. [
  29. [("Connect", url)],
  30. [
  31. ("←", f"proxy_arq_-1"),
  32. ("→", f"proxy_arq_1"),
  33. ],
  34. ]
  35. )
  36. await message.reply_text(
  37. f"""
  38. **Proxy:** {proxy}
  39. **Location**: {location}
  40. **POWERED BY [ARQ](http://t.me/ARQUpdates)**""",
  41. reply_markup=keyb,
  42. disable_web_page_preview=True,
  43. )
  44. @app.on_callback_query(filters.regex(r"proxy_arq_"))
  45. async def proxy_callback_func(_, cq: CallbackQuery):
  46. data = cq.data
  47. index = int(data.split("_")[-1])
  48. location = proxies[index].location
  49. proxy = proxies[index].proxy
  50. url = url_from_proxy(proxy)
  51. keyb = ikb(
  52. [
  53. [
  54. ("Connect", url),
  55. ],
  56. [
  57. ("←", f"proxy_arq_{index-1}"),
  58. ("→", f"proxy_arq_{index+1}"),
  59. ],
  60. ]
  61. )
  62. await cq.message.edit(
  63. f"""
  64. **Proxy:** {proxy}
  65. **Location**: {location}
  66. **POWERED BY [ARQ](http://t.me/ARQUpdates)**""",
  67. reply_markup=keyb,
  68. disable_web_page_preview=True,
  69. )