@@ -32,6 +32,7 @@ class TriggerObj(object):
3232 pound: Number of numeric wildcards (``#``)
3333 under: Number of alphabetical wildcards (``_``)
3434 option: Number of optional tags ("[man]" in "hey [man]"), assume that the template is properly formatted
35+ is_empty: Boolean variable indicating whether the trigger has non-zero wordcount
3536 """
3637
3738 def __init__ (self , pattern , index , weight , inherit = sys .maxsize ):
@@ -45,24 +46,8 @@ def __init__(self, pattern, index, weight, inherit = sys.maxsize):
4546 self .pound = self .alphabet .count ('#' ) # Number of numeric wildcards 0 < 1
4647 self .under = self .alphabet .count ('_' ) # Number of alphabetical wildcards 0 < 1
4748 self .option = self .alphabet .count ('[' ) + self .alphabet .count ('(' ) # Number of option 0 < 1
49+ self .is_empty = self .wordcount == 0 # Triggers with words precede triggers with no words, False < True
4850
49- if self .star > 0 :
50- if (self .pound == 0 ) & (self .under == 0 ) & (self .option == 0 ): # Place single star last in the rank
51- self .pound = sys .maxsize
52- self .under = sys .maxsize
53- self .option = sys .maxsize
54- if self .wordcount == 0 : # The special case for single star "*", or a grey case "* *"
55- self .wordcount = sys .maxsize # Make sure template "hello *" > "*"
56- # Without any words number of stars does not matter, they all mean match any.
57- self .star = sys .maxsize # Make sure "*" is last in the list, "* love *" > "*"
58-
59- # Special handle for the case "[*]", since self.len is not re-set, self.len = -2 < 0. Thus, "[*]" > "*"
60- elif (self .option == 1 ) & (self .wordcount == - 2 ):
61- self .wordcount = sys .maxsize
62- self .star = sys .maxsize
63- self .pound = sys .maxsize
64- self .under = sys .maxsize
65- self .option = sys .maxsize
6651
6752def sort_trigger_set (triggers , exclude_previous = True , say = None ):
6853 """Sort a group of triggers in optimal sorting order.
@@ -125,9 +110,10 @@ def sort_trigger_set(triggers, exclude_previous=True, say=None):
125110
126111 trigger_object_list .append (TriggerObj (pattern , index , weight , inherit ))
127112
128- # Priority order of sorting criteria: weight, inherit, star, pound, under, option, wordcount, len, alphabet
113+ # Priority order of sorting criteria:
114+ # weight, inherit, is_empty, star, pound, under, option, wordcount, len, alphabet
129115 sorted_list = sorted (trigger_object_list ,
130- key = attrgetter ('weight' , 'inherit' , 'star' , 'pound' ,
116+ key = attrgetter ('weight' , 'inherit' , 'is_empty' , ' star' , 'pound' ,
131117 'under' , 'option' , 'wordcount' , 'len' , 'alphabet' ))
132118 return [triggers [item .index ] for item in sorted_list ]
133119
0 commit comments