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 = [
|
admins = [
|
||||||
452970435 # klafyvel
|
452970435 # klafyvel
|
||||||
]
|
]
|
||||||
|
inline="ping"
|
||||||
[cmd.ping]
|
[cmd.ping]
|
||||||
quotes = []
|
quotes = []
|
||||||
python = [
|
python = [
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -10,5 +10,5 @@ def get_content():
|
||||||
return json.loads(r.content)["value"]
|
return json.loads(r.content)["value"]
|
||||||
|
|
||||||
|
|
||||||
def on_ping(bot, update, context):
|
def on_ping(update, context):
|
||||||
return get_content()
|
return get_content()
|
||||||
|
|
|
@ -9,7 +9,7 @@ def make_it_dodgy(update, context):
|
||||||
result = requests.post(API_URL, data=dict(long_url=message))
|
result = requests.post(API_URL, data=dict(long_url=message))
|
||||||
article = InlineQueryResultArticle(
|
article = InlineQueryResultArticle(
|
||||||
id=0,
|
id=0,
|
||||||
title=message,
|
title=message or "Your link",
|
||||||
input_message_content=InputTextMessageContent(result.text)
|
input_message_content=InputTextMessageContent(result.text)
|
||||||
)
|
)
|
||||||
context.bot.answer_inline_query(update.inline_query.id, [article])
|
context.bot.answer_inline_query(update.inline_query.id, [article])
|
|
@ -41,10 +41,6 @@ def attack():
|
||||||
link = "de "
|
link = "de "
|
||||||
return ' '.join([adj, link+nun, '!'])
|
return ' '.join([adj, link+nun, '!'])
|
||||||
|
|
||||||
def on_attack(bot, update, context):
|
def on_attack(update, context):
|
||||||
# you can choose to reply here or to simply return a str wich will be returned.
|
# you can choose to reply here or to simply return a str wich will be returned (second option is required for inline).
|
||||||
context.bot.send_message(
|
return attack()
|
||||||
chat_id=update.effective_chat.id,
|
|
||||||
text=attack(),
|
|
||||||
reply_to_message_id=update.effective_message.message_id
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in a new issue