added command and error handling. added comman /roll as a placeholder
This commit is contained in:
@@ -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}')
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user