|
@@ -41,6 +41,11 @@ class Handler:
|
41
|
41
|
"""Base class for Kaylee plugin handlers
|
42
|
42
|
|
43
|
43
|
Plugins should subclass this for their own command handlers.
|
|
44
|
+
|
|
45
|
+ Rich comparison methods are defined for use with queue.PriorityQueue.
|
|
46
|
+ They compare Handler objects based on their confidence alone, with
|
|
47
|
+ Handlers of high confidence comparing less than ones of low
|
|
48
|
+ confidence.
|
44
|
49
|
"""
|
45
|
50
|
|
46
|
51
|
def __init__(self, confidence):
|
|
@@ -61,3 +66,32 @@ class Handler:
|
61
|
66
|
When called, ``tts`` is a function which takes a string as its only
|
62
|
67
|
parameter and passes it to Kaylee's configured text-to-speech system.
|
63
|
68
|
"""
|
|
69
|
+
|
|
70
|
+ def __eq__(self, other):
|
|
71
|
+ if isinstance(other, Handler):
|
|
72
|
+ return (self.confidence == other.confidence)
|
|
73
|
+ return NotImplemented
|
|
74
|
+
|
|
75
|
+ def __lt__(self, other):
|
|
76
|
+ if isinstance(other, Handler):
|
|
77
|
+ # Intentionally reversed
|
|
78
|
+ return (self.confidence > other.confidence)
|
|
79
|
+ return NotImplemented
|
|
80
|
+
|
|
81
|
+ def __le__(self, other):
|
|
82
|
+ if isinstance(other, Handler):
|
|
83
|
+ # Intentionally reversed
|
|
84
|
+ return (self.confidence >= other.confidence)
|
|
85
|
+ return NotImplemented
|
|
86
|
+
|
|
87
|
+ def __ge__(self, other):
|
|
88
|
+ if isinstance(other, Handler):
|
|
89
|
+ # Intentionally reversed
|
|
90
|
+ return (self.confidence <= other.confidence)
|
|
91
|
+ return NotImplemented
|
|
92
|
+
|
|
93
|
+ def __gt__(self, other):
|
|
94
|
+ if isinstance(other, Handler):
|
|
95
|
+ # Intentionally reversed
|
|
96
|
+ return (self.confidence < other.confidence)
|
|
97
|
+ return NotImplemented
|