feat: set status to idle appropriately

This commit is contained in:
Ryan 2025-01-05 19:23:50 -05:00
parent d7ab46a20e
commit 3848deb887
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
5 changed files with 41 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import importlib
import inspect
import io
import textwrap
import time
import traceback
import disnake_paginator
@ -12,7 +13,7 @@ import commands
import constants
import core
import utils
from state import client, command_locks, executed_messages
from state import client, command_locks, last_used
async def on_message(message, edited=False):
@ -26,6 +27,9 @@ async def on_message(message, edited=False):
if not matched:
return
global last_used
last_used = time.time()
if len(matched) > 1:
await utils.reply(
message,

View File

@ -1,8 +1,13 @@
import commands
import core
import tasks
from state import client
async def on_ready():
await tasks.check_idle()
async def on_message(message):
await core.on_message(message)

View File

@ -9,5 +9,7 @@ from state import client, start_time
async def on_ready():
print(f"logged in as {client.user} in {round(time.time() - start_time, 1)}s")
await events.on_ready()
client.run(constants.SECRETS["TOKEN"])

View File

@ -11,4 +11,5 @@ intents.message_content = True
intents.members = True
client = disnake.Client(intents=intents)
last_used = time.time()
start_time = time.time()

28
tasks.py Normal file
View File

@ -0,0 +1,28 @@
import asyncio
import time
import disnake
from state import client, last_used, players
async def check_idle():
while True:
await asyncio.sleep(3600)
if time.time() - last_used >= 3600:
await client.change_presence(status=disnake.Status.idle)
else:
await client.change_presence(status=disnake.Status.online)
async def cleanup():
while True:
await asyncio.sleep(3600)
targets = []
for id, player in players:
if len(player.queue) == 0:
targets.append(id)
for target in targets:
del players[target]