proxy.py 2.1 KB

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