-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol_daemon.py
62 lines (51 loc) · 1.56 KB
/
control_daemon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from aioconsole import ainput
import hikari
import lightbulb
import sys
import asyncio
import logging
import time
logging.getLogger()
class CommandRegistry:
_commands = {}
@classmethod
def register(cls, *args):
def decorator(fn) -> 'function':
cls._commands[fn.__name__] = fn
return fn
return decorator
@classmethod
async def execute(cls, command, ctx) -> None:
if command in cls._commands:
await cls._commands[command](ctx)
else:
logging.warning(f'{command} is not a valid command. Please enter a valid command, or type "help" for a list of commands.')
@CommandRegistry.register()
async def exit(ctx: dict) -> None:
print(ctx)
await ctx['bot'].close()
asyncio.get_event_loop().stop()
@CommandRegistry.register()
async def help(ctx: dict) -> None:
pass
async def prompt(bot: lightbulb.BotApp) -> None:
await asyncio.sleep(3)
while True:
user_input = await ainput('> ')
if user_input not in [None, '']:
split_input = user_input.split()
print(user_input, '\n', split_input)
await CommandRegistry.execute(
split_input[0],
{
'command': split_input[0],
'args': split_input[1:],
'raw_command': user_input,
'bot': bot
}
)
async def tests() -> None:
print(CommandRegistry._commands)
await prompt('test_bot')
if __name__ == '__main__':
print(CommandRegistry._commands)