feat(commands/bot): add uptime
This commit is contained in:
parent
59c4b37831
commit
6b9172ef1b
@ -3,13 +3,16 @@ import inspect
|
||||
|
||||
from state import reloaded_modules
|
||||
|
||||
from . import tools, utils, voice
|
||||
from . import bot, tools, utils, voice
|
||||
from .utils import *
|
||||
|
||||
|
||||
def __reload_module__():
|
||||
for name, module in globals().items():
|
||||
if inspect.ismodule(module) and name not in constants.RELOAD_BLACKLISTED_MODULES:
|
||||
if (
|
||||
inspect.ismodule(module)
|
||||
and name not in constants.RELOAD_BLACKLISTED_MODULES
|
||||
):
|
||||
importlib.reload(module)
|
||||
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
||||
reloaded_modules.add(name)
|
||||
|
43
commands/bot.py
Normal file
43
commands/bot.py
Normal file
@ -0,0 +1,43 @@
|
||||
import importlib
|
||||
import inspect
|
||||
import time
|
||||
|
||||
import arguments
|
||||
import constants
|
||||
from state import reloaded_modules, start_time
|
||||
|
||||
import commands
|
||||
import utils
|
||||
|
||||
|
||||
async def uptime(message):
|
||||
tokens = commands.tokenize(message.content)
|
||||
parser = arguments.ArgumentParser(
|
||||
tokens[0],
|
||||
"print bot uptime",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--since",
|
||||
action="store_true",
|
||||
help="bot up since",
|
||||
)
|
||||
if not (args := await parser.parse_args(message, tokens)):
|
||||
return
|
||||
|
||||
if args.since:
|
||||
await utils.reply(message, f"{round(start_time)}")
|
||||
else:
|
||||
await utils.reply(message, f"up {round(time.time() - start_time)} seconds")
|
||||
|
||||
|
||||
def __reload_module__():
|
||||
for name, module in globals().items():
|
||||
if (
|
||||
inspect.ismodule(module)
|
||||
and name not in constants.RELOAD_BLACKLISTED_MODULES
|
||||
):
|
||||
importlib.reload(module)
|
||||
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
||||
reloaded_modules.add(name)
|
||||
module.__reload_module__()
|
@ -4,17 +4,18 @@ import constants
|
||||
|
||||
|
||||
class Command(enum.Enum):
|
||||
RELOAD = "reload"
|
||||
EXECUTE = "execute"
|
||||
CLEAR = "clear"
|
||||
PURGE = "purge"
|
||||
EXECUTE = "execute"
|
||||
JOIN = "join"
|
||||
LEAVE = "leave"
|
||||
QUEUE = "queue"
|
||||
PLAY = "play"
|
||||
SKIP = "skip"
|
||||
RESUME = "resume"
|
||||
PAUSE = "pause"
|
||||
PLAY = "play"
|
||||
PURGE = "purge"
|
||||
QUEUE = "queue"
|
||||
RELOAD = "reload"
|
||||
RESUME = "resume"
|
||||
SKIP = "skip"
|
||||
UPTIME = "uptime"
|
||||
VOLUME = "volume"
|
||||
|
||||
|
||||
|
@ -92,6 +92,8 @@ async def on_message(message):
|
||||
await commands.voice.pause(message)
|
||||
case C.VOLUME:
|
||||
await commands.voice.volume(message)
|
||||
case C.UPTIME:
|
||||
await commands.bot.uptime(message)
|
||||
except Exception as e:
|
||||
await message.reply(
|
||||
f"exception occurred while processing command: ```\n{''.join(traceback.format_exception(e)).replace('`', '\\`')}```",
|
||||
|
10
main.py
10
main.py
@ -2,13 +2,12 @@ import importlib
|
||||
import inspect
|
||||
import time
|
||||
|
||||
import commands
|
||||
import constants
|
||||
import core
|
||||
import events
|
||||
from state import client, reloaded_modules
|
||||
from state import client, reloaded_modules, start_time
|
||||
|
||||
start_time = time.time()
|
||||
import commands
|
||||
|
||||
|
||||
@client.event
|
||||
@ -36,7 +35,10 @@ async def on_message(message):
|
||||
commands.Command.RELOAD
|
||||
]:
|
||||
for name, module in globals().items():
|
||||
if inspect.ismodule(module) and name not in constants.RELOAD_BLACKLISTED_MODULES:
|
||||
if (
|
||||
inspect.ismodule(module)
|
||||
and name not in constants.RELOAD_BLACKLISTED_MODULES
|
||||
):
|
||||
importlib.reload(module)
|
||||
if "__reload_module__" in dir(module) and name not in reloaded_modules:
|
||||
reloaded_modules.add(name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user