feat: add (incomplete) nix flake
dave.py isn't packaged yet. Will try to do this myself but dealing with vcpkg is a bit annoying.
This commit is contained in:
33
errornocord/tasks.py
Normal file
33
errornocord/tasks.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import asyncio
|
||||
import time
|
||||
from logging import debug, error
|
||||
|
||||
import disnake
|
||||
|
||||
from .state import client, idle_tracker, players
|
||||
|
||||
|
||||
async def cleanup():
|
||||
debug("spawned cleanup thread")
|
||||
|
||||
while True:
|
||||
await asyncio.sleep(3600)
|
||||
|
||||
targets = []
|
||||
for guild_id, player in players.items():
|
||||
if len(player.queue) == 0 and not player.current:
|
||||
targets.append(guild_id)
|
||||
for target in targets:
|
||||
del players[target]
|
||||
if len(targets):
|
||||
debug(f"cleanup thread removed {len(targets)} empty players")
|
||||
|
||||
if (
|
||||
not idle_tracker["is_idle"]
|
||||
and time.time() - idle_tracker["last_used"] >= 3600
|
||||
):
|
||||
try:
|
||||
await client.change_presence(status=disnake.Status.idle)
|
||||
idle_tracker["is_idle"] = True
|
||||
except Exception as e:
|
||||
error(f"failed to change status to idle: {e}")
|
||||
Reference in New Issue
Block a user