trial + _upgrade_abm
This commit is contained in:
parent
9588493288
commit
1c825918d5
1
.gitignore
vendored
1
.gitignore
vendored
@ -215,3 +215,4 @@ fabric.properties
|
|||||||
/data/
|
/data/
|
||||||
.token.txt
|
.token.txt
|
||||||
*.exe
|
*.exe
|
||||||
|
.trial_token.env
|
||||||
|
1
.trial_token_example.env
Normal file
1
.trial_token_example.env
Normal file
@ -0,0 +1 @@
|
|||||||
|
trial_token=paste here
|
12
README.md
Normal file
12
README.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# music bot
|
||||||
|
## try for yourself
|
||||||
|
default prefix is `?/`
|
||||||
|
### set token
|
||||||
|
```sh
|
||||||
|
cp .trial_token_example.env .trial_token.env
|
||||||
|
vim .trial_token.env
|
||||||
|
```
|
||||||
|
### start or update
|
||||||
|
```sh
|
||||||
|
docker compose up -d --build
|
||||||
|
```
|
14
docker-compose.yml
Normal file
14
docker-compose.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
services:
|
||||||
|
music-bot-trial:
|
||||||
|
build: .
|
||||||
|
volumes:
|
||||||
|
- "/v6data"
|
||||||
|
env_file:
|
||||||
|
- .trial_token.env
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '2'
|
||||||
|
memory: 2G
|
||||||
|
tty: true
|
||||||
|
stop_signal: SIGINT
|
@ -144,6 +144,7 @@ async def default(ctx: Context, args: list[str]) -> None:
|
|||||||
await ctx.reply(f'effects set to `{effects}`')
|
await ctx.reply(f'effects set to `{effects}`')
|
||||||
|
|
||||||
|
|
||||||
|
@at('commands', '//')
|
||||||
@at('commands', 'queue')
|
@at('commands', 'queue')
|
||||||
async def queue_(ctx: Context, args: list[str]) -> None:
|
async def queue_(ctx: Context, args: list[str]) -> None:
|
||||||
await catch(
|
await catch(
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
|
import time
|
||||||
|
import contextlib
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from v6d1tokens.client import request_token
|
|
||||||
from v6d2ctx.handle_content import handle_content
|
|
||||||
from v6d2ctx.lock_for import lock_for
|
|
||||||
from v6d2ctx.serve import serve
|
|
||||||
from v6d2ctx.pain import ABlockMonitor
|
|
||||||
|
|
||||||
from v6d3music.app import MusicAppFactory, session_db
|
from v6d3music.app import MusicAppFactory, session_db
|
||||||
from v6d3music.commands import register_commands
|
from v6d3music.commands import register_commands
|
||||||
from v6d3music.config import prefix
|
from v6d3music.config import prefix
|
||||||
@ -19,6 +15,13 @@ from v6d3music.core.mainaudio import volume_db
|
|||||||
from v6d3music.core.queueaudio import queue_db
|
from v6d3music.core.queueaudio import queue_db
|
||||||
from v6d3music.utils.entries_effects_for_args import effects_db
|
from v6d3music.utils.entries_effects_for_args import effects_db
|
||||||
|
|
||||||
|
from rainbowadn.instrument import Instrumentation
|
||||||
|
from v6d1tokens.client import request_token
|
||||||
|
from v6d2ctx.handle_content import handle_content
|
||||||
|
from v6d2ctx.lock_for import lock_for
|
||||||
|
from v6d2ctx.pain import ABlockMonitor
|
||||||
|
from v6d2ctx.serve import serve
|
||||||
|
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
register_commands()
|
register_commands()
|
||||||
@ -34,6 +37,7 @@ class MusicClient(discord.Client):
|
|||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
client = MusicClient(
|
client = MusicClient(
|
||||||
intents=discord.Intents(
|
intents=discord.Intents(
|
||||||
members=True,
|
members=True,
|
||||||
@ -61,7 +65,15 @@ async def restore_vcs():
|
|||||||
async with lock_for(guild, 'not in a guild'):
|
async with lock_for(guild, 'not in a guild'):
|
||||||
channels = await guild.fetch_channels()
|
channels = await guild.fetch_channels()
|
||||||
channel: discord.VoiceChannel
|
channel: discord.VoiceChannel
|
||||||
channel, = [ch for ch in (chc for chc in channels if isinstance(chc, discord.VoiceChannel)) 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()
|
vp: discord.VoiceProtocol = await channel.connect()
|
||||||
assert isinstance(vp, discord.VoiceClient)
|
assert isinstance(vp, discord.VoiceClient)
|
||||||
vc = vp
|
vc = vp
|
||||||
@ -148,9 +160,47 @@ async def setup_tasks():
|
|||||||
loop.create_task(start_app())
|
loop.create_task(start_app())
|
||||||
|
|
||||||
|
|
||||||
|
class UpgradeABMInit(Instrumentation):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(ABlockMonitor, '__init__')
|
||||||
|
|
||||||
|
def instrument(self, method, abm, *, threshold=0.0, delta=10.0, interval=0.0):
|
||||||
|
print('created upgraded')
|
||||||
|
method(abm, threshold=threshold, delta=delta, interval=interval)
|
||||||
|
abm.threshold = threshold
|
||||||
|
|
||||||
|
|
||||||
|
class UpgradeABMTask(Instrumentation):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(ABlockMonitor, '_monitor')
|
||||||
|
|
||||||
|
async def instrument(self, _, abm):
|
||||||
|
print('started upgraded')
|
||||||
|
while True:
|
||||||
|
delta = abm.delta
|
||||||
|
t = time.time()
|
||||||
|
await asyncio.sleep(delta)
|
||||||
|
spent = time.time() - t
|
||||||
|
delay = spent - delta
|
||||||
|
if delay > abm.threshold:
|
||||||
|
abm.threshold = delay
|
||||||
|
print(
|
||||||
|
f'upgraded block monitor reached new peak delay {delay:.4f}')
|
||||||
|
interval = abm.interval
|
||||||
|
if interval > 0:
|
||||||
|
await asyncio.sleep(interval)
|
||||||
|
|
||||||
|
|
||||||
|
def _upgrade_abm() -> contextlib.ExitStack:
|
||||||
|
with contextlib.ExitStack() as es:
|
||||||
|
es.enter_context(UpgradeABMInit())
|
||||||
|
es.enter_context(UpgradeABMTask())
|
||||||
|
return es.pop_all()
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
async with volume_db, queue_db, cache_db, session_db, effects_db, ABlockMonitor():
|
async with volume_db, queue_db, cache_db, session_db, effects_db, ABlockMonitor(delta=0.5):
|
||||||
if 'guerilla' in sys.argv:
|
if 'guerilla' in sys.argv:
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
tokenpath = Path('.token.txt')
|
tokenpath = Path('.token.txt')
|
||||||
@ -159,6 +209,8 @@ async def main():
|
|||||||
else:
|
else:
|
||||||
token = input('token:')
|
token = input('token:')
|
||||||
tokenpath.write_text(token)
|
tokenpath.write_text(token)
|
||||||
|
elif (token_ := os.getenv('trial_token')):
|
||||||
|
token = token_
|
||||||
else:
|
else:
|
||||||
token = await request_token('music', 'token')
|
token = await request_token('music', 'token')
|
||||||
await client.login(token)
|
await client.login(token)
|
||||||
@ -170,4 +222,5 @@ async def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
with _upgrade_abm():
|
||||||
serve(main(), client, loop)
|
serve(main(), client, loop)
|
||||||
|
Loading…
Reference in New Issue
Block a user