added command and error handling. added comman /roll as a placeholder

This commit is contained in:
2020-07-23 20:53:13 +03:00
parent 4f5c790dc1
commit c5a482c9b1

View File

@@ -2,17 +2,30 @@ from typing import Dict
import random import random
commands: Dict = {}
def command(*commandlist):
def add_command(function):
for command in commandlist:
commands[command] = function
return function
return add_command
def handle_command(kwargs): def handle_command(kwargs):
c = kwargs['message'].split()[0]
command = kwargs['message'].split()[0] if c in commands:
print(command) commands[c](kwargs)
else:
error_response(kwargs)
def custom_roll(character, message): @command('/roll')
print('asd') def custom_roll(kwargs):
print(f'/roll received {kwargs}')
commands: Dict = { def error_response(kwargs):
'/roll': custom_roll print(f'Error, received unknown command: {kwargs}')
}