diff --git a/etc/klafytg/bots.d/chuck.toml b/etc/klafytg/bots.d/chuck.toml index 6c6c859..988edd9 100644 --- a/etc/klafytg/bots.d/chuck.toml +++ b/etc/klafytg/bots.d/chuck.toml @@ -9,6 +9,7 @@ min_time = 3 admins = [ 452970435 # klafyvel ] +inline="ping" [cmd.ping] quotes = [] python = [ diff --git a/klafytg/bot.py b/klafytg/bot.py index 5a5dfad..c5d74a9 100644 --- a/klafytg/bot.py +++ b/klafytg/bot.py @@ -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) diff --git a/klafytg/bots/chuck_norris.py b/klafytg/bots/chuck_norris.py index dd64699..2e4bd75 100644 --- a/klafytg/bots/chuck_norris.py +++ b/klafytg/bots/chuck_norris.py @@ -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() diff --git a/klafytg/bots/dodgy.py b/klafytg/bots/dodgy.py index 90a1b88..de6e725 100644 --- a/klafytg/bots/dodgy.py +++ b/klafytg/bots/dodgy.py @@ -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]) \ No newline at end of file + context.bot.answer_inline_query(update.inline_query.id, [article]) diff --git a/klafytg/bots/klafyvel.py b/klafytg/bots/klafyvel.py index 3f70561..50ab24e 100644 --- a/klafytg/bots/klafyvel.py +++ b/klafytg/bots/klafyvel.py @@ -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()