MusicClient
This commit is contained in:
parent
dabbc6c452
commit
897db8ab31
@ -3,6 +3,7 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import traceback
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from v6d1tokens.client import request_token
|
from v6d1tokens.client import request_token
|
||||||
@ -22,7 +23,18 @@ from v6d3music.utils.entries_effects_for_args import effects_db
|
|||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
register_commands()
|
register_commands()
|
||||||
client = discord.Client(
|
|
||||||
|
|
||||||
|
class MusicClient(discord.Client):
|
||||||
|
async def close(self) -> None:
|
||||||
|
save_task.cancel()
|
||||||
|
try:
|
||||||
|
await save_all(False, False)
|
||||||
|
except Exception:
|
||||||
|
traceback.print_exc()
|
||||||
|
await super().close()
|
||||||
|
|
||||||
|
client = MusicClient(
|
||||||
intents=discord.Intents(
|
intents=discord.Intents(
|
||||||
members=True,
|
members=True,
|
||||||
guilds=True,
|
guilds=True,
|
||||||
@ -106,8 +118,9 @@ async def save_commit():
|
|||||||
await queue_db.set('commit', time.time())
|
await queue_db.set('commit', time.time())
|
||||||
|
|
||||||
|
|
||||||
async def save_all(delay: bool):
|
async def save_all(delay: bool, save_playing: bool):
|
||||||
await save_queues(delay)
|
await save_queues(delay)
|
||||||
|
if save_playing:
|
||||||
await save_vcs(delay)
|
await save_vcs(delay)
|
||||||
await save_commit()
|
await save_commit()
|
||||||
|
|
||||||
@ -115,7 +128,7 @@ async def save_all(delay: bool):
|
|||||||
async def save_job():
|
async def save_job():
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
await save_all(True)
|
await save_all(True, True)
|
||||||
|
|
||||||
|
|
||||||
async def save_daemon():
|
async def save_daemon():
|
||||||
@ -155,8 +168,7 @@ async def main():
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print('no tor')
|
print('no tor')
|
||||||
await client.connect()
|
await client.connect()
|
||||||
save_task.cancel()
|
print('exited')
|
||||||
await save_all(False)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user