ソースを参照

Update simple plugin to use new API

It's still very simple, giving evidence that the new API isn't too
complicated.
Clara Hobbs 6年前
コミット
af358379cf
1個のファイルの変更19行の追加12行の削除
  1. 19
    12
      kayleevc/plugins/simple.py

+ 19
- 12
kayleevc/plugins/simple.py ファイルの表示

@@ -11,7 +11,7 @@ option, "phrase", which is a sentence to be recognized.  Once this is
11 11
 heard, the plugin prints "Simple plugin says: [phrase]".
12 12
 """
13 13
 
14
-from .pluginbase import PluginBase
14
+from . import PluginBase, Handler
15 15
 
16 16
 
17 17
 class Plugin(PluginBase):
@@ -23,16 +23,23 @@ class Plugin(PluginBase):
23 23
 
24 24
         self.corpus_strings.add(self.options['phrase'])
25 25
 
26
-    def confidence(self, text):
27
-        """Return 0 if text is not the phrase, 1 if it is"""
28
-        return 1 if text == self.options['phrase'] else 0
26
+    def get_handler(self, text):
27
+        """Return a handler if and only if the phrase is heard"""
28
+        if text == self.options['phrase']:
29
+            return SimpleHandler(1, text)
30
+        else:
31
+            return None
32
+
33
+
34
+class SimpleHandler(Handler):
35
+    """Handler for the simple plugin"""
29 36
 
30
-    def handle(self, text):
37
+    def __init__(self, confidence, text):
38
+        """Store the phrase that was heard"""
39
+        super().__init__(confidence)
40
+        self.text = text
41
+
42
+    def __call__(self, tts):
31 43
         """Print and speak the phrase"""
32
-        # Is there a matching command?
33
-        if self.confidence(text):
34
-            print("Simple plugin says:", text)
35
-            self.emit('tts', text)
36
-            return True
37
-        else:
38
-            return False
44
+        print("Simple plugin says:", self.text)
45
+        tts(self.text)

読み込み中…
キャンセル
保存