Update proxying

This commit is contained in:
Nexus 2023-11-04 16:47:14 +00:00
parent 2f72a949d5
commit a4aa4725a6
Signed by: nex
GPG key ID: 0FA334385D0B689F
3 changed files with 63 additions and 13 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="dataSourceStorageLocal" created-in="PY-232.9921.36"> <component name="dataSourceStorageLocal" created-in="PY-232.10072.31">
<data-source name="main" uuid="28efee07-d306-4126-bf69-01008b4887e2"> <data-source name="main" uuid="28efee07-d306-4126-bf69-01008b4887e2">
<database-info product="SQLite" version="3.39.2" jdbc-version="2.1" driver-name="SQLite JDBC" driver-version="3.39.2.0" dbms="SQLITE" exact-version="3.39.2" exact-driver-version="3.39"> <database-info product="SQLite" version="3.39.2" jdbc-version="2.1" driver-name="SQLite JDBC" driver-version="3.39.2.0" dbms="SQLITE" exact-version="3.39.2" exact-driver-version="3.39">
<identifier-quote-string>&quot;</identifier-quote-string> <identifier-quote-string>&quot;</identifier-quote-string>

View file

@ -854,6 +854,32 @@ class OtherCog(commands.Cog):
await blacklist.write(line) await blacklist.write(line)
await ctx.respond("Removed domain from blacklist.") await ctx.respond("Removed domain from blacklist.")
@staticmethod
async def check_proxy(self, url: str = "socks5h://localhost:1090"):
async with httpx.AsyncClient(
http2=True
) as client:
my_ip64 = (await client.get("https://api64.ipify.org")).text
my_ip4 = (await client.get("https://api.ipify.org")).text
real_ips = [my_ip64, my_ip4]
# Check the proxy
with httpx.AsyncClient(
proxies=url
) as client:
try:
response = await client.get(
"https://1.1.1.1/cdn-cgi/trace",
)
response.raise_for_status()
for line in response.text.splitlines():
if line.startswith("ip"):
if any(x in line for x in real_ips):
return 1
except (httpx.TransportError, httpx.HTTPStatusError):
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)
async def yt_dl_2( async def yt_dl_2(
@ -872,19 +898,14 @@ class OtherCog(commands.Cog):
) = "", ) = "",
extract_audio: bool = False, extract_audio: bool = False,
cookies_txt: discord.Attachment = None, cookies_txt: discord.Attachment = None,
proxy_via_nexbox: discord.Option( disable_filesize_buffer: bool = False
name="proxy-via-nexbox",
description="Proxies via nexbox, circumventing some blocks. Very Slow.",
type=discord.SlashCommandOptionType.boolean,
default=False
) = False
): ):
"""Downloads a video using youtube-dl""" """Downloads a video using youtube-dl"""
cookies = io.StringIO() cookies = io.StringIO()
cookies.seek(0) cookies.seek(0)
await ctx.defer() await ctx.defer()
from urllib.parse import urlparse, parse_qs from urllib.parse import parse_qs
formats = await self.list_formats(url) formats = await self.list_formats(url)
if _format: if _format:
_fmt = _format _fmt = _format
@ -896,6 +917,9 @@ class OtherCog(commands.Cog):
MAX_SIZE_MB = ctx.guild.filesize_limit / 1024 / 1024 MAX_SIZE_MB = ctx.guild.filesize_limit / 1024 / 1024
if MAX_SIZE_MB == 8.0: if MAX_SIZE_MB == 8.0:
MAX_SIZE_MB = 25.0 MAX_SIZE_MB = 25.0
if disable_filesize_buffer is False:
MAX_SIZE_MB *= 0.9
BYTES_REMAINING = (MAX_SIZE_MB - 0.256) * 1024 * 1024 BYTES_REMAINING = (MAX_SIZE_MB - 0.256) * 1024 * 1024
import yt_dlp import yt_dlp
@ -973,8 +997,34 @@ class OtherCog(commands.Cog):
"source_address": "0.0.0.0", "source_address": "0.0.0.0",
"cookiefile": str(real_cookies_txt.resolve().absolute()) "cookiefile": str(real_cookies_txt.resolve().absolute())
} }
if proxy_via_nexbox: description = ""
args["proxy"] = "socks5h://localhost:1080" proxy_url = "socks5h://localhost:1090"
try:
proxy_down = await self.check_proxy("socks5h://localhost:1090")
if proxy_down > 0:
if proxy_down == 1:
description += ":warning: (SHRoNK) Proxy check leaked IP - trying backup proxy\n"
elif proxy_down == 2:
description += ":warning: (SHRoNK) Proxy connection failed - trying backup proxy\n"
else:
description += ":warning: (SHRoNK) Unknown proxy error - trying backup proxy\n"
proxy_down = await self.check_proxy("socks5h://localhost:1080")
if proxy_down > 0:
if proxy_down == 1:
description += ":warning: (NexBox) Proxy check leaked IP.\n"
elif proxy_down == 2:
description += ":warning: (NexBox) Proxy connection failed\n"
else:
description += ":warning: (NexBox) Unknown proxy error\n"
proxy_url = None
else:
proxy_url = "socks5h://localhost:1080"
except Exception as e:
traceback.print_exc()
description += f":warning: Failed to check proxy (`{e}`). Going unproxied."
if proxy_url:
args["proxy"] = proxy_url
if extract_audio: if extract_audio:
args["postprocessors"] = [ args["postprocessors"] = [
{ {
@ -992,7 +1042,7 @@ class OtherCog(commands.Cog):
try: try:
await ctx.respond( await ctx.respond(
embed=discord.Embed( embed=discord.Embed(
title="Downloading...", colour=discord.Colour.blurple() title="Downloading...", description=description, colour=discord.Colour.blurple()
) )
) )
await self.bot.loop.run_in_executor(None, partial(downloader.download, [url])) await self.bot.loop.run_in_executor(None, partial(downloader.download, [url]))
@ -1004,7 +1054,7 @@ class OtherCog(commands.Cog):
description=f"Download failed:\n```\n{e}\n```", description=f"Download failed:\n```\n{e}\n```",
colour=discord.Colour.red() colour=discord.Colour.red()
), ),
delete_after=30 delete_after=60
) )
else: else:
parsed_qs = parse_qs(url) parsed_qs = parse_qs(url)

View file

@ -1,7 +1,7 @@
py-cord[voice]>=2.4.0 py-cord[voice]>=2.4.0
aiosmtplib>=1.1.7 aiosmtplib>=1.1.7
orm[sqlite]>=0.3.1 orm[sqlite]>=0.3.1
httpx>=0.23.0 httpx[http2,brotli,socks]>=0.23.0
jishkucord>=2.5.2 jishkucord>=2.5.2
rich>=12.5.1 rich>=12.5.1
nltk>=3.7 nltk>=3.7