| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- from asyncio import get_event_loop, sleep
- from pyrogram import filters
- from pyrogram.types import CallbackQuery, Message
- from wbb import app, arq
- from wbb.core.keyboard import ikb
- __MODULE__ = "Proxy"
- __HELP__ = "/proxy - Get socks5 proxy which you can" \
- + " use with telegram or other things"
- proxies = []
- async def get_proxies():
- global proxies
- proxies = (await arq.proxy()).result
- loop = get_event_loop()
- loop.create_task(get_proxies())
- def url_from_proxy(proxy: str) -> str:
- creds, proxy = proxy.split("//")[1:][0].split("@")
- user, passwd = creds.split(":")
- host, port = proxy.split(":")
- return (
- f"https://t.me/socks?server={host}&port="
- + f"{port}&user={user}&pass={passwd}"
- )
- @app.on_message(filters.command("proxy") & ~filters.edited)
- async def proxy_func(_, message: Message):
- if len(proxies) == 0:
- await asyncio.sleep(0.5)
- location = proxies[0].location
- proxy = proxies[0].proxy
- url = url_from_proxy(proxy)
- keyb = ikb(
- [
- [("Connect", url)],
- [
- ("←", f"proxy_arq_-1"),
- ("→", f"proxy_arq_1"),
- ],
- ]
- )
- await message.reply_text(
- f"""
- **Proxy:** {proxy}
- **Location**: {location}
- **POWERED BY [ARQ](http://t.me/ARQUpdates)**""",
- reply_markup=keyb,
- disable_web_page_preview=True,
- )
- @app.on_callback_query(filters.regex(r"proxy_arq_"))
- async def proxy_callback_func(_, cq: CallbackQuery):
- data = cq.data
- index = int(data.split("_")[-1])
- location = proxies[index].location
- proxy = proxies[index].proxy
- url = url_from_proxy(proxy)
- keyb = ikb(
- [
- [
- ("Connect", url),
- ],
- [
- ("←", f"proxy_arq_{index-1}"),
- ("→", f"proxy_arq_{index+1}"),
- ],
- ]
- )
- await cq.message.edit(
- f"""
- **Proxy:** {proxy}
- **Location**: {location}
- **POWERED BY [ARQ](http://t.me/ARQUpdates)**""",
- reply_markup=keyb,
- disable_web_page_preview=True,
- )
|