-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole_controller.py
More file actions
58 lines (52 loc) · 2.34 KB
/
console_controller.py
File metadata and controls
58 lines (52 loc) · 2.34 KB
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
import asyncio
from commands import (
DMCommand, ServerCommand, MemberCommand,
ClearCommand, KickCommand, MessageServerCommand,
DualDamage, DataCommand, JoinCallByIdCommand, SaveCallCommand,
FollowUserCommand, VoiceStatusTracker, VoiceControlCommand # Assuming this is the correct import path
)
class ConsoleController:
def __init__(self, client):
self.client = client
self.commands = {
'dm': DMCommand(),
'servers': ServerCommand(),
'members': MemberCommand(),
'clear': ClearCommand(),
'kick': KickCommand(),
'message': MessageServerCommand(),
'dd': DualDamage(),
'data': DataCommand(self.client),
'vc': JoinCallByIdCommand(),
'savecall': SaveCallCommand(),
'channels': SaveCallCommand(),
'help': None, # Placeholder for a help command handler
'harass': FollowUserCommand(client),
'voicestatus': VoiceStatusTracker(client),
# 'vccommand' : VoiceControlCommand(client)# Placeholder for a voice status command handler
}
async def process_command(self, cmd_input):
parts = cmd_input.split(maxsplit=1)
cmd = parts[0].lower()
args = parts[1] if len(parts) > 1 else ""
if cmd in self.commands:
try:
# Pass the client and arguments when executing the command
await self.commands[cmd].execute(self.client, args)
except Exception as e:
print(f"Error while executing {cmd}: {e}")
else:
print(f"Unknown command: {cmd}. Available: {', '.join(self.commands.keys())}")
async def run_interface(self):
print("\nAvailable commands:", ', '.join(self.commands.keys()), ", exit")
while True:
try:
cmd = await self.run_in_thread(input, "BotConsole> ")
if cmd.lower() in ['exit', 'quit']:
print("Exiting the interface.")
return True
await self.process_command(cmd)
except Exception as e:
print(f"Error: {e}")
async def run_in_thread(self, func, *args):
return await asyncio.get_event_loop().run_in_executor(None, func, *args)