httpx man

This commit is contained in:
Nexus 2023-11-04 16:54:42 +00:00
parent db634f2a73
commit a6f2055b8c
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -855,30 +855,27 @@ class OtherCog(commands.Cog):
await ctx.respond("Removed domain from blacklist.") await ctx.respond("Removed domain from blacklist.")
@staticmethod @staticmethod
async def check_proxy(self, url: str = "socks5://localhost:1090"): async def check_proxy(url: str = "socks5://localhost:1090"):
async with httpx.AsyncClient( client = httpx.AsyncClient(http2=True)
http2=True my_ip64 = (await client.get("https://api64.ipify.org")).text
) as client: my_ip4 = (await client.get("https://api.ipify.org")).text
my_ip64 = (await client.get("https://api64.ipify.org")).text real_ips = [my_ip64, my_ip4]
my_ip4 = (await client.get("https://api.ipify.org")).text await client.aclose()
real_ips = [my_ip64, my_ip4]
# Check the proxy # Check the proxy
with httpx.AsyncClient( client = httpx.AsyncClient(http2=True, proxies=url)
proxies=url try:
) as client: response = await client.get(
try: "https://1.1.1.1/cdn-cgi/trace",
response = await client.get( )
"https://1.1.1.1/cdn-cgi/trace", response.raise_for_status()
) for line in response.text.splitlines():
response.raise_for_status() if line.startswith("ip"):
for line in response.text.splitlines(): if any(x in line for x in real_ips):
if line.startswith("ip"): return 1
if any(x in line for x in real_ips): except (httpx.TransportError, httpx.HTTPStatusError):
return 1 return 2
except (httpx.TransportError, httpx.HTTPStatusError): await client.aclose()
return 2
@commands.slash_command(name="yt-dl") @commands.slash_command(name="yt-dl")
@commands.max_concurrency(1, commands.BucketType.user) @commands.max_concurrency(1, commands.BucketType.user)