@@ -10,9 +10,22 @@ def normalize(text, *args, **kwargs):
10
10
return text
11
11
12
12
13
- class Message (_MycroftMessage ):
13
+ class _MessageMeta (type ):
14
+ """ To override isinstance checks we need to use a metaclass """
15
+ def __instancecheck__ (self , instance ):
16
+ return isinstance (instance , _MycroftMessage )
17
+
18
+
19
+ class Message (_MycroftMessage , metaclass = _MessageMeta ):
14
20
"""Mycroft specific Message class."""
15
21
22
+ def __eq__ (self , other ):
23
+ if not isinstance (other , _MycroftMessage ):
24
+ return False
25
+ return other .msg_type == self .msg_type and \
26
+ other .data == self .data and \
27
+ other .context == self .context
28
+
16
29
def utterance_remainder (self ):
17
30
"""
18
31
DEPRECATED - mycroft-core hack, used by some skills in the wild
@@ -33,3 +46,14 @@ def utterance_remainder(self):
33
46
# Substitute only whole words matching the token
34
47
utt = re .sub (r'\b' + token .get ("key" , "" ) + r"\b" , "" , utt )
35
48
return normalize (utt )
49
+
50
+
51
+ if __name__ == "__main__" :
52
+ m1 = _MycroftMessage ("" )
53
+ m2 = Message ("" )
54
+ print (m1 == m2 )
55
+ print (m2 == m1 )
56
+ print (isinstance (m1 , _MycroftMessage ))
57
+ print (isinstance (m1 , Message ))
58
+ print (isinstance (m2 , _MycroftMessage ))
59
+ print (isinstance (m2 , Message ))
0 commit comments