|
|
@ -74,7 +74,7 @@ class Bot: |
|
|
return |
|
|
return |
|
|
quote = random.choice(self.commands[name]) |
|
|
quote = random.choice(self.commands[name]) |
|
|
if callable(quote): |
|
|
if callable(quote): |
|
|
quote = quote(self, update, context) |
|
|
quote = quote(update, context) |
|
|
else: |
|
|
else: |
|
|
c = { |
|
|
c = { |
|
|
"channel": update.effective_chat.title, |
|
|
"channel": update.effective_chat.title, |
|
|
@ -124,7 +124,7 @@ class Bot: |
|
|
if not callable(quote): |
|
|
if not callable(quote): |
|
|
actual_quote = quote.format(**c) |
|
|
actual_quote = quote.format(**c) |
|
|
else: |
|
|
else: |
|
|
actual_quote = quote(self, username, channel, message) |
|
|
actual_quote = quote(update, context) |
|
|
if re.search(query, actual_quote) or not query: |
|
|
if re.search(query, actual_quote) or not query: |
|
|
results.append( |
|
|
results.append( |
|
|
InlineQueryResultArticle( |
|
|
InlineQueryResultArticle( |
|
|
@ -139,10 +139,7 @@ class Bot: |
|
|
def on_message(self, update, context): |
|
|
def on_message(self, update, context): |
|
|
if not self.is_allowed(update, context): |
|
|
if not self.is_allowed(update, context): |
|
|
return |
|
|
return |
|
|
user = update.effective_user |
|
|
answer = self.get_reaction(update, context) |
|
|
channel = update.effective_chat |
|
|
|
|
|
message = update.effective_message |
|
|
|
|
|
answer = self.get_reaction(user, channel, message) |
|
|
|
|
|
if answer: |
|
|
if answer: |
|
|
context.bot.send_message(chat_id=update.effective_chat.id, text=answer[0], reply_to_message_id=update.effective_message.message_id) |
|
|
context.bot.send_message(chat_id=update.effective_chat.id, text=answer[0], reply_to_message_id=update.effective_message.message_id) |
|
|
|
|
|
|
|
|
@ -171,17 +168,19 @@ class Bot: |
|
|
module = importlib.import_module(module) |
|
|
module = importlib.import_module(module) |
|
|
return getattr(module, callback) |
|
|
return getattr(module, callback) |
|
|
|
|
|
|
|
|
def get_reaction(self, user, channel, message): |
|
|
def get_reaction(self, update, context): |
|
|
"""Get a reaction to a message. |
|
|
"""Get a reaction to a message. |
|
|
|
|
|
|
|
|
Args: |
|
|
Args: |
|
|
user: The user who sent the message. |
|
|
update: tg update |
|
|
channel: The channel on which the bot speak. |
|
|
context: tg context |
|
|
message: The message to which the bot has to react. |
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
Returns: |
|
|
Every matched reactions. |
|
|
Every matched reactions. |
|
|
""" |
|
|
""" |
|
|
|
|
|
user = update.effective_user |
|
|
|
|
|
channel = update.effective_chat |
|
|
|
|
|
message = update.effective_message |
|
|
if channel.id in self.channels and (datetime.datetime.now() - self.channels[channel.id]).total_seconds() < self.min_time: |
|
|
if channel.id in self.channels and (datetime.datetime.now() - self.channels[channel.id]).total_seconds() < self.min_time: |
|
|
return [] |
|
|
return [] |
|
|
|
|
|
|
|
|
@ -198,7 +197,7 @@ class Bot: |
|
|
if search: |
|
|
if search: |
|
|
r = self.reactions[m] |
|
|
r = self.reactions[m] |
|
|
if callable(r): |
|
|
if callable(r): |
|
|
r = r(self, username, channel, message) |
|
|
r = r(update, context) |
|
|
else: |
|
|
else: |
|
|
r = r.format(**context) |
|
|
r = r.format(**context) |
|
|
result.append(r) |
|
|
result.append(r) |
|
|
|