MusicClient

This commit is contained in:
AF 2022-10-11 17:40:32 +00:00
parent dabbc6c452
commit 897db8ab31

View File

@ -3,6 +3,7 @@ import os
import subprocess
import sys
import time
import traceback
import discord
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()
asyncio.set_event_loop(loop)
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(
members=True,
guilds=True,
@ -106,16 +118,17 @@ async def save_commit():
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_vcs(delay)
if save_playing:
await save_vcs(delay)
await save_commit()
async def save_job():
while True:
await asyncio.sleep(1)
await save_all(True)
await save_all(True, True)
async def save_daemon():
@ -155,8 +168,7 @@ async def main():
except FileNotFoundError:
print('no tor')
await client.connect()
save_task.cancel()
await save_all(False)
print('exited')
if __name__ == '__main__':