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
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):
c = kwargs['message'].split()[0]
command = kwargs['message'].split()[0]
print(command)
if c in commands:
commands[c](kwargs)
else:
error_response(kwargs)
def custom_roll(character, message):
print('asd')
@command('/roll')
def custom_roll(kwargs):
print(f'/roll received {kwargs}')
commands: Dict = {
'/roll': custom_roll
}
def error_response(kwargs):
print(f'Error, received unknown command: {kwargs}')