refactor
This commit is contained in:
parent
89ac8a491b
commit
c085feea71
@ -8,26 +8,27 @@
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
project = 'parrrate-music'
|
||||
copyright = '2022, PARRRATE TNV'
|
||||
author = 'PARRRATE TNV'
|
||||
|
||||
project = "parrrate-music"
|
||||
copyright = "2022, PARRRATE TNV"
|
||||
author = "PARRRATE TNV"
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
"sphinx.ext.autodoc",
|
||||
]
|
||||
|
||||
templates_path = ['_templates']
|
||||
templates_path = ["_templates"]
|
||||
exclude_patterns = []
|
||||
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
||||
|
||||
html_theme = 'pydata_sphinx_theme'
|
||||
html_static_path = ['_static']
|
||||
html_theme = "pydata_sphinx_theme"
|
||||
html_static_path = ["_static"]
|
||||
|
||||
|
||||
sys.path.insert(0, os.path.abspath('../..'))
|
||||
sys.path.insert(0, os.path.abspath("../.."))
|
||||
|
16
setup.py
16
setup.py
@ -1,12 +1,12 @@
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='v6d3music',
|
||||
version='',
|
||||
packages=['v6d3music'],
|
||||
url='',
|
||||
license='',
|
||||
author='PARRRATE TNV',
|
||||
author_email='',
|
||||
description=''
|
||||
name="v6d3music",
|
||||
version="",
|
||||
packages=["v6d3music"],
|
||||
url="",
|
||||
license="",
|
||||
author="PARRRATE TNV",
|
||||
author_email="",
|
||||
description="",
|
||||
)
|
||||
|
@ -1,3 +1,3 @@
|
||||
__all__ = ('api', 'app', 'commands', 'config')
|
||||
__all__ = ("api", "app", "commands", "config")
|
||||
|
||||
from . import api, app, commands, config
|
||||
|
@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
@ -118,7 +120,7 @@ class UserApi:
|
||||
sub._key = key
|
||||
return sub
|
||||
|
||||
async def to_guild_api(self, guild_id: int) -> "GuildApi":
|
||||
async def to_guild_api(self, guild_id: int) -> GuildApi:
|
||||
guild = self.client.get_guild(guild_id) or await self.client.fetch_guild(guild_id)
|
||||
if guild is None:
|
||||
raise UserApi.UnknownMember("unknown guild")
|
||||
@ -127,7 +129,7 @@ class UserApi:
|
||||
raise UserApi.UnknownMember("unknown member of a guild")
|
||||
return GuildApi(self, member)
|
||||
|
||||
async def to_operator_api(self) -> "OperatorApi":
|
||||
async def to_operator_api(self) -> OperatorApi:
|
||||
if not self.pi.is_operator(self.user_id):
|
||||
raise UserApi.UnknownMember("not an operator")
|
||||
return OperatorApi(self)
|
||||
@ -188,7 +190,7 @@ class GuildApi(UserApi):
|
||||
self.member = member
|
||||
self.guild = member.guild
|
||||
|
||||
async def to_voice_api(self) -> "VoiceApi":
|
||||
async def to_voice_api(self) -> VoiceApi:
|
||||
voice = self.member.voice
|
||||
if voice is None:
|
||||
raise GuildApi.VoiceNotConnected("you are not connected to voice")
|
||||
|
@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from contextlib import AsyncExitStack
|
||||
|
||||
from ptvp35 import DbFactory, KVJson
|
||||
@ -21,11 +23,12 @@ class DefaultEffects:
|
||||
raise Explicit("these effects are not allowed")
|
||||
await self.__db.set(gid, effects)
|
||||
|
||||
async def __aenter__(self) -> "DefaultEffects":
|
||||
async def __aenter__(self) -> DefaultEffects:
|
||||
async with AsyncExitStack() as es:
|
||||
self.__db = await es.enter_async_context(DbFactory(myroot / "effects.db", kvfactory=KVJson()))
|
||||
self.__es = es.pop_all()
|
||||
return self
|
||||
raise RuntimeError
|
||||
|
||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||
async with self.__es:
|
||||
|
@ -99,10 +99,10 @@ class MainService:
|
||||
raise Explicit("not in a guild")
|
||||
return await self.raw_vc_for_member(ctx.member)
|
||||
|
||||
def mode(self, *, create: bool, force_play: bool) -> "MainMode":
|
||||
def mode(self, *, create: bool, force_play: bool) -> MainMode:
|
||||
return MainMode(self, create=create, force_play=force_play)
|
||||
|
||||
def context(self, ctx: Context, *, create: bool, force_play: bool) -> "MainContext":
|
||||
def context(self, ctx: Context, *, create: bool, force_play: bool) -> MainContext:
|
||||
return self.mode(create=create, force_play=force_play).context(ctx)
|
||||
|
||||
async def create(self, guild: discord.Guild) -> MainAudio:
|
||||
@ -266,7 +266,7 @@ class MainMode:
|
||||
vc.play(source)
|
||||
return source
|
||||
|
||||
def context(self, ctx: Context) -> "MainContext":
|
||||
def context(self, ctx: Context) -> MainContext:
|
||||
return MainContext(self, ctx)
|
||||
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
__all__ = ('Monitoring', 'PersistentMonitoring')
|
||||
from __future__ import annotations
|
||||
|
||||
__all__ = ("Monitoring", "PersistentMonitoring")
|
||||
|
||||
import asyncio
|
||||
from contextlib import AsyncExitStack, ExitStack
|
||||
@ -6,7 +8,7 @@ from typing import Any, Callable, Generic, TypeVar
|
||||
|
||||
from rainbowadn.instrument import Instrumentation
|
||||
|
||||
T = TypeVar('T', bound=Instrumentation, covariant=True)
|
||||
T = TypeVar("T", bound=Instrumentation, covariant=True)
|
||||
|
||||
|
||||
class Provider(Generic[T]):
|
||||
@ -19,7 +21,7 @@ class Provider(Generic[T]):
|
||||
|
||||
def __enter__(self) -> T:
|
||||
if self.__closed:
|
||||
raise RuntimeError('the provider is closed')
|
||||
raise RuntimeError("the provider is closed")
|
||||
if self.__count < 0:
|
||||
raise RuntimeError
|
||||
if self.__count == 0:
|
||||
@ -62,19 +64,15 @@ class ProviderManager(Generic[T]):
|
||||
class Monitoring:
|
||||
async def get(self, provider: Callable[[], T]) -> Provider[T]:
|
||||
if provider not in self.__providers:
|
||||
self.__providers[provider] = asyncio.create_task(
|
||||
self.__es.enter_async_context(ProviderManager(provider))
|
||||
)
|
||||
self.__providers[provider] = asyncio.create_task(self.__es.enter_async_context(ProviderManager(provider)))
|
||||
return await self.__providers[provider]
|
||||
|
||||
async def __aenter__(self) -> 'Monitoring':
|
||||
async def __aenter__(self) -> "Monitoring":
|
||||
async with AsyncExitStack() as es:
|
||||
self.__providers: dict[
|
||||
Callable[[], Instrumentation],
|
||||
asyncio.Future[Provider]
|
||||
] = {}
|
||||
self.__providers: dict[Callable[[], Instrumentation], asyncio.Future[Provider]] = {}
|
||||
self.__es = es.pop_all()
|
||||
return self
|
||||
raise RuntimeError
|
||||
|
||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||
async with self.__es:
|
||||
@ -90,16 +88,11 @@ class PersistentMonitoring:
|
||||
|
||||
async def get(self, provider: Callable[[], T]) -> T:
|
||||
if provider not in self.__instrumentations:
|
||||
self.__instrumentations[provider] = asyncio.create_task(
|
||||
self._get(provider)
|
||||
)
|
||||
self.__instrumentations[provider] = asyncio.create_task(self._get(provider))
|
||||
return await self.__instrumentations[provider]
|
||||
|
||||
def __enter__(self) -> 'PersistentMonitoring':
|
||||
self.__instrumentations: dict[
|
||||
Callable[[], Instrumentation],
|
||||
asyncio.Future
|
||||
] = {}
|
||||
def __enter__(self) -> PersistentMonitoring:
|
||||
self.__instrumentations: dict[Callable[[], Instrumentation], asyncio.Future] = {}
|
||||
self.__es = ExitStack()
|
||||
return self
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import random
|
||||
import traceback
|
||||
@ -53,7 +55,7 @@ class QueueAudio(discord.AudioSource):
|
||||
return respawned
|
||||
|
||||
@classmethod
|
||||
async def create(cls, servicing: YTAServicing, db: DbConnection, guild: discord.Guild) -> "QueueAudio":
|
||||
async def create(cls, servicing: YTAServicing, db: DbConnection, guild: discord.Guild) -> QueueAudio:
|
||||
return cls(db, guild, await cls.respawned(servicing, db, guild))
|
||||
|
||||
async def save(self, delay: bool) -> None:
|
||||
|
@ -17,8 +17,10 @@ async def repeat(repeated: Callable[[], Coroutine[Any, Any, T]]) -> T:
|
||||
|
||||
async def set_config(key: str, value: Any) -> None:
|
||||
json = {"key": key, "value": value}
|
||||
|
||||
async def call() -> None:
|
||||
async with aiohttp.ClientSession() as s, s.post("http://sessionservice/config/", json=json) as response:
|
||||
if response.status != 200:
|
||||
raise RuntimeError("config request failed")
|
||||
|
||||
await repeat(call)
|
||||
|
@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import random
|
||||
import re
|
||||
@ -222,7 +224,7 @@ class YTAudio(discord.AudioSource):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
async def respawn(cls, servicing: YTAServicing, guild: discord.Guild, respawn: dict) -> "YTAudio":
|
||||
async def respawn(cls, servicing: YTAServicing, guild: discord.Guild, respawn: dict) -> YTAudio:
|
||||
member_id: int | None = respawn["rby"]
|
||||
if member_id is None:
|
||||
member = None
|
||||
@ -267,7 +269,7 @@ class YTAudio(discord.AudioSource):
|
||||
"canbeskipped": self.can_be_skipped_by(member),
|
||||
}
|
||||
|
||||
def copy(self) -> "YTAudio":
|
||||
def copy(self) -> YTAudio:
|
||||
return YTAudio(
|
||||
self.servicing,
|
||||
self.url,
|
||||
@ -278,7 +280,7 @@ class YTAudio(discord.AudioSource):
|
||||
0,
|
||||
)
|
||||
|
||||
def branch(self) -> "YTAudio":
|
||||
def branch(self) -> YTAudio:
|
||||
if self.stop_at is not None:
|
||||
raise Explicit("already branched")
|
||||
self.stop_at = stop_at = self.already_read + 50
|
||||
|
@ -1,4 +1,4 @@
|
||||
from .main import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -1,6 +1,6 @@
|
||||
import nacl.hash
|
||||
|
||||
__all__ = ('bytes_hash',)
|
||||
__all__ = ("bytes_hash",)
|
||||
|
||||
|
||||
def bytes_hash(b: bytes) -> str:
|
||||
|
@ -1,5 +1,5 @@
|
||||
import discord
|
||||
|
||||
__all__ = ('FILL',)
|
||||
__all__ = ("FILL",)
|
||||
|
||||
FILL = b'\x00' * discord.opus.Encoder.FRAME_SIZE
|
||||
FILL = b"\x00" * discord.opus.Encoder.FRAME_SIZE
|
||||
|
@ -1,8 +1,8 @@
|
||||
import shlex
|
||||
from typing import Optional
|
||||
|
||||
__all__ = ('options_for_effects',)
|
||||
__all__ = ("options_for_effects",)
|
||||
|
||||
|
||||
def options_for_effects(effects: str | None) -> Optional[str]:
|
||||
return f'-af {shlex.quote(effects)}' if effects else None
|
||||
return f"-af {shlex.quote(effects)}" if effects else None
|
||||
|
Loading…
Reference in New Issue
Block a user