proxy.py 2.0 KB

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