Fix inline
This commit is contained in:
parent
2499cae3da
commit
3de7da9916
5 changed files with 17 additions and 21 deletions
|
@ -9,6 +9,7 @@ min_time = 3
|
|||
admins = [
|
||||
452970435 # klafyvel
|
||||
]
|
||||
inline="ping"
|
||||
[cmd.ping]
|
||||
quotes = []
|
||||
python = [
|
||||
|
|
|
@ -74,7 +74,7 @@ class Bot:
|
|||
return
|
||||
quote = random.choice(self.commands[name])
|
||||
if callable(quote):
|
||||
quote = quote(self, update, context)
|
||||
quote = quote(update, context)
|
||||
else:
|
||||
c = {
|
||||
"channel": update.effective_chat.title,
|
||||
|
@ -124,7 +124,7 @@ class Bot:
|
|||
if not callable(quote):
|
||||
actual_quote = quote.format(**c)
|
||||
else:
|
||||
actual_quote = quote(self, username, channel, message)
|
||||
actual_quote = quote(update, context)
|
||||
if re.search(query, actual_quote) or not query:
|
||||
results.append(
|
||||
InlineQueryResultArticle(
|
||||
|
@ -139,10 +139,7 @@ class Bot:
|
|||
def on_message(self, update, context):
|
||||
if not self.is_allowed(update, context):
|
||||
return
|
||||
user = update.effective_user
|
||||
channel = update.effective_chat
|
||||
message = update.effective_message
|
||||
answer = self.get_reaction(user, channel, message)
|
||||
answer = self.get_reaction(update, context)
|
||||
if answer:
|
||||
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)
|
||||
return getattr(module, callback)
|
||||
|
||||
def get_reaction(self, user, channel, message):
|
||||
def get_reaction(self, update, context):
|
||||
"""Get a reaction to a message.
|
||||
|
||||
Args:
|
||||
user: The user who sent the message.
|
||||
channel: The channel on which the bot speak.
|
||||
message: The message to which the bot has to react.
|
||||
update: tg update
|
||||
context: tg context
|
||||
|
||||
Returns:
|
||||
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:
|
||||
return []
|
||||
|
||||
|
@ -198,7 +197,7 @@ class Bot:
|
|||
if search:
|
||||
r = self.reactions[m]
|
||||
if callable(r):
|
||||
r = r(self, username, channel, message)
|
||||
r = r(update, context)
|
||||
else:
|
||||
r = r.format(**context)
|
||||
result.append(r)
|
||||
|
|
|
@ -10,5 +10,5 @@ def get_content():
|
|||
return json.loads(r.content)["value"]
|
||||
|
||||
|
||||
def on_ping(bot, update, context):
|
||||
def on_ping(update, context):
|
||||
return get_content()
|
||||
|
|
|
@ -9,7 +9,7 @@ def make_it_dodgy(update, context):
|
|||
result = requests.post(API_URL, data=dict(long_url=message))
|
||||
article = InlineQueryResultArticle(
|
||||
id=0,
|
||||
title=message,
|
||||
title=message or "Your link",
|
||||
input_message_content=InputTextMessageContent(result.text)
|
||||
)
|
||||
context.bot.answer_inline_query(update.inline_query.id, [article])
|
|
@ -41,10 +41,6 @@ def attack():
|
|||
link = "de "
|
||||
return ' '.join([adj, link+nun, '!'])
|
||||
|
||||
def on_attack(bot, update, context):
|
||||
# you can choose to reply here or to simply return a str wich will be returned.
|
||||
context.bot.send_message(
|
||||
chat_id=update.effective_chat.id,
|
||||
text=attack(),
|
||||
reply_to_message_id=update.effective_message.message_id
|
||||
)
|
||||
def on_attack(update, context):
|
||||
# you can choose to reply here or to simply return a str wich will be returned (second option is required for inline).
|
||||
return attack()
|
||||
|
|
Loading…
Reference in a new issue