feat: set status to idle appropriately
This commit is contained in:
parent
d7ab46a20e
commit
3848deb887
6
core.py
6
core.py
@ -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,
|
||||
|
@ -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)
|
||||
|
||||
|
2
main.py
2
main.py
@ -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"])
|
||||
|
1
state.py
1
state.py
@ -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
28
tasks.py
Normal 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]
|
Loading…
x
Reference in New Issue
Block a user