From 40145ae3da8bef32123f75085cbcaf579d9d934e Mon Sep 17 00:00:00 2001 From: timofey Date: Tue, 1 Nov 2022 17:47:22 +0000 Subject: [PATCH] temporary support for adaas + remove bundled tor --- Dockerfile | 4 +--- requirements.txt | 5 +++-- v6d3music/core/create_ytaudio.py | 1 + v6d3music/core/ffmpegnormalaudio.py | 5 ++++- v6d3music/core/mainasrc.py | 12 +++++++----- v6d3music/core/real_url.py | 4 ++++ v6d3music/run-bot.py | 4 ++-- 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4ef7acf..9f24388 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,12 +4,10 @@ WORKDIR /v6 ENV v6root=/v6data RUN apt-get update RUN apt-get install -y libopus0 opus-tools ffmpeg +RUN apt-get install -y tor COPY requirements.txt requirements.txt RUN pip install -r requirements.txt -RUN apt-get install -y tor obfs4proxy COPY v6d3music v6d3music -RUN printf "\nClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy\nBridge obfs4 185.177.207.210:11210 044DEFCA9726828CAE0F880DFEDB6D957006087A cert=mLCpY31wGw9Vs1tQdCXGIyZaAQ6RCdWvw50klpDAk/4mZvA+wekmLZQRqatcbuMp2y36TQ iat-mode=1\nUseBridges 1\n" >> "/etc/tor/torrc" ENV v6host=0.0.0.0 -EXPOSE 5930 ENV v6port=5930 CMD ["python3", "-m", "v6d3music.run-bot"] diff --git a/requirements.txt b/requirements.txt index 194c28b..50e6e80 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ aiohttp~=3.7.4.post0 discord.py[voice]~=1.7.3 -git+https://gitea.parrrate.ru/PTV/v6d1tokens.git@c4c6cf43b1082c666e6891f73df825acee6ae86d -git+https://gitea.parrrate.ru/PTV/v6d2ctx.git@096314b9bbb6153a9a75afcc16ddf7833384df18 youtube_dl~=2021.12.17 +git+https://gitea.parrrate.ru/PTV/v6d1tokens.git@d382a0aa59525c40009bc9e6c30aaec3e506062a +git+https://gitea.parrrate.ru/PTV/v6d2ctx.git@096314b9bbb6153a9a75afcc16ddf7833384df18 +git+https://gitea.parrrate.ru/PTV/adaas.git@2052448b19f895dee5cec9eaec470243d130d253 diff --git a/v6d3music/core/create_ytaudio.py b/v6d3music/core/create_ytaudio.py index 20dba64..bd6fb62 100644 --- a/v6d3music/core/create_ytaudio.py +++ b/v6d3music/core/create_ytaudio.py @@ -13,6 +13,7 @@ from v6d3music.utils.presets import allowed_effects async def create_ytaudio( ctx: Context, info: dict[str, Any], effects: Optional[str], already_read: int, tor: bool ) -> YTAudio: + assert ctx.member is not None if effects: if effects not in allowed_effects: assert_admin(ctx.member) diff --git a/v6d3music/core/ffmpegnormalaudio.py b/v6d3music/core/ffmpegnormalaudio.py index 836e42c..8cb33dc 100644 --- a/v6d3music/core/ffmpegnormalaudio.py +++ b/v6d3music/core/ffmpegnormalaudio.py @@ -72,7 +72,10 @@ class FFmpegNormalAudio(discord.FFmpegAudio): return chunk def droppable(self) -> bool: - return self._loaded and time.time() - self.loaded_at < 600 + if self.loaded_at is None: + return False + else: + return self._loaded and time.time() - self.loaded_at < 600 def read(self): ret = self._raw_read() diff --git a/v6d3music/core/mainasrc.py b/v6d3music/core/mainasrc.py index 7293003..8125e76 100644 --- a/v6d3music/core/mainasrc.py +++ b/v6d3music/core/mainasrc.py @@ -10,18 +10,20 @@ mainasrcs: dict[discord.Guild, MainAudio] = {} async def raw_vc_for(ctx: Context) -> discord.VoiceClient: if ctx.guild is None: raise Explicit('not in a guild') - vc: discord.VoiceProtocol = ctx.guild.voice_client + assert ctx.member is not None + vc: discord.VoiceProtocol | None = ctx.guild.voice_client if vc is None or isinstance(vc, discord.VoiceClient) and not vc.is_connected(): - vs: discord.VoiceState = ctx.member.voice + vs: discord.VoiceState | None = ctx.member.voice if vs is None: raise Explicit('not connected') - vch: discord.VoiceChannel = vs.channel + vch: discord.VoiceChannel | None = vs.channel # type: ignore if vch is None: raise Explicit('not connected') try: - vc: discord.VoiceProtocol = await vch.connect() + vc = await vch.connect() except discord.ClientException: - vc: discord.VoiceProtocol = ctx.guild.voice_client + vc = ctx.guild.voice_client + assert vc is not None await ctx.guild.fetch_channels() await vc.disconnect(force=True) raise Explicit('try again later') diff --git a/v6d3music/core/real_url.py b/v6d3music/core/real_url.py index 3f27dbd..c8a00bf 100644 --- a/v6d3music/core/real_url.py +++ b/v6d3music/core/real_url.py @@ -1,6 +1,7 @@ import asyncio import subprocess from typing import Optional +from adaas.cachedb import RemoteCache from v6d2ctx.context import Benchmark @@ -10,6 +11,8 @@ from v6d3music.utils.tor_prefix import tor_prefix async def real_url(url: str, override: bool, tor: bool) -> str: + if not tor: + return await RemoteCache().real_url(url, override, tor) hurl: str = bytes_hash(url.encode()) if not override: curl: Optional[str] = cache_db.get(f'url:{hurl}', None) @@ -33,6 +36,7 @@ async def real_url(url: str, override: bool, tor: bool) -> str: code = await loop.run_in_executor(None, p.wait) if code: raise RuntimeError(code) + assert p.stdout is not None rurl: str = p.stdout.readline().decode()[:-1] loop.create_task(cache_url(hurl, rurl, override, tor)) return rurl diff --git a/v6d3music/run-bot.py b/v6d3music/run-bot.py index 4f58f03..93994ee 100644 --- a/v6d3music/run-bot.py +++ b/v6d3music/run-bot.py @@ -61,7 +61,7 @@ async def restore_vcs(): async with lock_for(guild, 'not in a guild'): channels = await guild.fetch_channels() channel: discord.VoiceChannel - channel, = [ch for ch in channels if ch.id == vccid] + channel, = [ch for ch in (chc for chc in channels if isinstance(chc, discord.VoiceChannel)) if ch.id == vccid] vp: discord.VoiceProtocol = await channel.connect() assert isinstance(vp, discord.VoiceClient) vc = vp @@ -105,7 +105,7 @@ async def save_vcs(delay: bool): if vcs_restored: vcs = [] vc: discord.VoiceClient - for vc in list(client.voice_clients): + for vc in (vcc for vcc in client.voice_clients if isinstance(vcc, discord.VoiceClient)): if delay: await asyncio.sleep(0.01) if vc.is_playing():