File botly/reaction.py changed (mode: 100644) (index 4c0e2c3..3bcc62a) |
... |
... |
class ReactionBase: |
102 |
102 |
elif 'reaction' in self.eventName: |
elif 'reaction' in self.eventName: |
103 |
103 |
self.reaction = eventInfo['reaction'] |
self.reaction = eventInfo['reaction'] |
104 |
104 |
self.user = eventInfo['user'] |
self.user = eventInfo['user'] |
105 |
|
|
|
|
105 |
|
self.channel = self.reaction.message.channel |
|
106 |
|
self.author = self.reaction.message.author |
106 |
107 |
|
|
107 |
108 |
def load_reactions(bot, reactionsParent): |
def load_reactions(bot, reactionsParent): |
108 |
109 |
"""Function that loads reactions from given parent module directory.""" |
"""Function that loads reactions from given parent module directory.""" |
File botly/trigger.py changed (mode: 100644) (index 049d3b0..cbaf9c0) |
... |
... |
class Trigger: |
38 |
38 |
assert eventName != 'on_ready', \ |
assert eventName != 'on_ready', \ |
39 |
39 |
'author not supported for on_ready event.' |
'author not supported for on_ready event.' |
40 |
40 |
|
|
41 |
|
# TODO: add possibility to react on reactions |
|
|
41 |
|
# TODO: add possibility to react on reactions with regular conditions |
|
42 |
|
# (for now, can only trigger on that based on adv_condition) |
42 |
43 |
|
|
43 |
44 |
condition = [] |
condition = [] |
44 |
45 |
condition.append(variable) |
condition.append(variable) |
|
... |
... |
class Trigger: |
68 |
69 |
assert isinstance(value, bool), 'Bool expected for require mention.' |
assert isinstance(value, bool), 'Bool expected for require mention.' |
69 |
70 |
self.requireMention = value |
self.requireMention = value |
70 |
71 |
|
|
71 |
|
def is_triggered(self, botly, **eventInfo): |
|
|
72 |
|
def is_triggered(self, bot, **eventInfo): |
72 |
73 |
"""This should only be called from Bot class. |
"""This should only be called from Bot class. |
73 |
74 |
|
|
74 |
75 |
Checks whether or not the trigger object activates based on the |
Checks whether or not the trigger object activates based on the |
|
... |
... |
class Trigger: |
81 |
82 |
|
|
82 |
83 |
# Checks if bot is mentioned if it is required: |
# Checks if bot is mentioned if it is required: |
83 |
84 |
if self.requireMention and 'message' in self.eventName: |
if self.requireMention and 'message' in self.eventName: |
84 |
|
if not botly.me.mentioned_in(eventInfo['message']): |
|
|
85 |
|
if not bot.me.mentioned_in(eventInfo['message']): |
85 |
86 |
return False |
return False |
86 |
87 |
|
|
87 |
88 |
# Check for conditions: |
# Check for conditions: |
|
... |
... |
class Trigger: |
102 |
103 |
return randrange(1, 101) < self.triggerChance |
return randrange(1, 101) < self.triggerChance |
103 |
104 |
|
|
104 |
105 |
def _is_condition_true(self, condition, **eventInfo): |
def _is_condition_true(self, condition, **eventInfo): |
105 |
|
v = condition[0] |
|
106 |
|
p = condition[1] |
|
|
106 |
|
variable = condition[0] |
|
107 |
|
pattern = condition[1] |
107 |
108 |
|
|
108 |
|
if v == 'author': |
|
|
109 |
|
if variable == 'author': |
109 |
110 |
if 'message' in self.eventName: |
if 'message' in self.eventName: |
110 |
|
if re.match(p, eventInfo['message'].author.id): |
|
|
111 |
|
if re.match(pattern, eventInfo['message'].author.id): |
111 |
112 |
return True |
return True |
112 |
113 |
if 'on_typing' == self.eventName: |
if 'on_typing' == self.eventName: |
113 |
|
if re.match(p, eventInfo['user'].id): |
|
|
114 |
|
if re.match(pattern, eventInfo['user'].id): |
114 |
115 |
return True |
return True |
115 |
|
elif v == 'message': |
|
|
116 |
|
elif variable == 'message': |
116 |
117 |
if 'message' in self.eventName: |
if 'message' in self.eventName: |
117 |
|
if re.match(p, eventInfo['message'].content): |
|
|
118 |
|
if re.match(pattern, eventInfo['message'].content): |
118 |
119 |
return True |
return True |
119 |
120 |
|
|
120 |
121 |
def _is_pattern_valid(self, pattern): |
def _is_pattern_valid(self, pattern): |