-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path__init__.py
67 lines (57 loc) · 2.4 KB
/
__init__.py
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
59
60
61
62
63
64
65
66
67
from os.path import dirname
import os
from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill
from mycroft.util.log import getLogger
from mycroft.util import read_stripped_lines
from random import randrange
from random import randint
__author__ = "Friday811"
LOGGER = getLogger(__name__)
class RollSkill(MycroftSkill):
def __init__(self):
super(RollSkill, self).__init__(name="RollSkill")
self.feedback = read_stripped_lines(dirname(__file__) +
'/dialog/' + self.lang + '/roll.dialog')
def initialize(self):
self.load_data_files(dirname(__file__))
roll_intent = IntentBuilder("RollIntent").\
require("DiceKeyword").require("Dice").build()
self.register_intent(roll_intent, self.handle_roll_intent)
def handle_roll_intent(self, message):
dice = message.data.get("Dice")
if "sided" not in dice and "d" in dice:
feedback = self.feedback[randrange(len(self.feedback))]
dice = dice.split("d")
dice_phrase = dice[0] + " " + dice[1] + " sided dice"
dice_array = []
for i in range(int(dice[0])):
dice_array.append(randint(1, int(dice[1])))
dice_string = ''
for i in dice_array:
dice_string = dice_string + " " + str(i)
dice_string += " for a total of " + str(sum(dice_array))
sentence = feedback.replace('<dice>', dice_phrase)\
.replace('<results>', dice_string)
self.speak(sentence)
elif "sided" in dice:
feedback = self.feedback[randrange(len(self.feedback))]
dice = dice.split("sided")
dice = dice[0].split(" ")
dice_phrase = dice[0] + " " + dice[1] + " sided dice"
dice_array = []
for i in range(int(dice[0])):
dice_array.append(randint(1, int(dice[1])))
dice_string = ''
for i in dice_array:
dice_string = dice_string + " " + str(i)
dice_string += " for a total of " + str(sum(dice_array))
sentence = feedback.replace('<dice>', dice_phrase)\
.replace('<results>', dice_string)
self.speak(sentence)
else:
self.speak("Please use RPG dice notation.")
def stop(self):
pass
def create_skill():
return RollSkill()