@@ -45,24 +45,8 @@ def __init__(self, pattern, index, weight, inherit = sys.maxsize):
4545 self .pound = self .alphabet .count ('#' ) # Number of numeric wildcards 0 < 1
4646 self .under = self .alphabet .count ('_' ) # Number of alphabetical wildcards 0 < 1
4747 self .option = self .alphabet .count ('[' ) + self .alphabet .count ('(' ) # Number of option 0 < 1
48+ self .is_empty = self .wordcount == 0 # Triggers with words precede triggers with no words, False < True
4849
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
6650
6751def sort_trigger_set (triggers , exclude_previous = True , say = None ):
6852 """Sort a group of triggers in optimal sorting order.
@@ -127,7 +111,7 @@ def sort_trigger_set(triggers, exclude_previous=True, say=None):
127111
128112 # Priority order of sorting criteria: weight, inherit, star, pound, under, option, wordcount, len, alphabet
129113 sorted_list = sorted (trigger_object_list ,
130- key = attrgetter ('weight' , 'inherit' , 'star' , 'pound' ,
114+ key = attrgetter ('weight' , 'inherit' , "is_empty" , 'star' , 'pound' ,
131115 'under' , 'option' , 'wordcount' , 'len' , 'alphabet' ))
132116 return [triggers [item .index ] for item in sorted_list ]
133117
0 commit comments