2020-07-23 20:05:13 +03:00
|
|
|
from typing import Dict
|
2020-07-27 16:38:26 +03:00
|
|
|
import re
|
2020-07-27 18:07:00 +03:00
|
|
|
import numpy as np
|
2020-07-29 20:31:10 +03:00
|
|
|
from dice.dice import Dice
|
2020-07-23 20:05:13 +03:00
|
|
|
|
2020-07-23 20:53:13 +03:00
|
|
|
commands: Dict = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def command(*commandlist):
|
|
|
|
|
def add_command(function):
|
|
|
|
|
for command in commandlist:
|
|
|
|
|
commands[command] = function
|
|
|
|
|
return function
|
|
|
|
|
return add_command
|
|
|
|
|
|
2020-07-23 20:05:13 +03:00
|
|
|
|
|
|
|
|
def handle_command(kwargs):
|
2020-07-23 20:53:13 +03:00
|
|
|
c = kwargs['message'].split()[0]
|
2020-07-27 18:07:00 +03:00
|
|
|
params = kwargs['message'].replace(c, '')
|
2020-07-23 20:05:13 +03:00
|
|
|
|
2020-07-23 20:53:13 +03:00
|
|
|
if c in commands:
|
2020-07-27 16:38:26 +03:00
|
|
|
commands[c](kwargs, params)
|
2020-07-23 20:53:13 +03:00
|
|
|
else:
|
2020-07-27 16:38:26 +03:00
|
|
|
error_response(kwargs, params)
|
2020-07-23 20:05:13 +03:00
|
|
|
|
|
|
|
|
|
2020-07-23 20:53:13 +03:00
|
|
|
@command('/roll')
|
2020-07-27 16:38:26 +03:00
|
|
|
def custom_roll(kwargs, params):
|
2020-07-29 20:31:10 +03:00
|
|
|
print(f'Kwargs: {kwargs}. Params: {params}')
|
|
|
|
|
dice = Dice()
|
|
|
|
|
print(dice.roll(params))
|
2020-07-23 20:05:13 +03:00
|
|
|
|
|
|
|
|
|
2020-07-27 16:38:26 +03:00
|
|
|
def error_response(kwargs, params):
|
2020-07-23 20:53:13 +03:00
|
|
|
print(f'Error, received unknown command: {kwargs}')
|