From b49aed6954a08485b79157b65965647475b5bf34 Mon Sep 17 00:00:00 2001 From: misanram Date: Sat, 25 Apr 2026 15:12:14 +0100 Subject: [PATCH] =?UTF-8?q?Suprimir=20el=20m=C3=A9todo=20trace=20y=20recup?= =?UTF-8?q?erar=20el=20formato=20%-style=20en=20los=20mensajes=20del=20log?= =?UTF-8?q?,=20closes=20#47?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pydeckard/bot.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/pydeckard/bot.py b/pydeckard/bot.py index 84e8b57..f284381 100644 --- a/pydeckard/bot.py +++ b/pydeckard/bot.py @@ -47,15 +47,12 @@ def set_logger(self): handlers=[console_handler], force=True, ) - # Ajustamos el nivel del logger bot + # Ajustamos el nivel del logger pydeckard self.logger.setLevel(config.LOG_LEVEL) config.log(self.logger.info) - def trace(self, msg): - self.logger.info(msg) - async def command_status(self, update: Update, context: ContextTypes.DEFAULT_TYPE): - self.trace('Received command: /status') + self.logger.info('Received command: /status') python_version = sys.version.split(maxsplit=1)[0] text = '\n'.join([ config.BOT_GREETING, @@ -67,10 +64,10 @@ async def command_status(self, update: Update, context: ContextTypes.DEFAULT_TYP text=text, parse_mode=ParseMode.HTML, ) - self.trace(text) + self.logger.info(text) async def command_start(self, update: Update, context: ContextTypes.DEFAULT_TYPE): - self.trace('Received command: /start') + self.logger.info('Received command: /start') await context.bot.send_message( chat_id=update.effective_chat.id, text=config.BOT_GREETING, @@ -78,7 +75,7 @@ async def command_start(self, update: Update, context: ContextTypes.DEFAULT_TYPE ) async def command_help(self, update: Update, context: ContextTypes.DEFAULT_TYPE): - self.trace('Received command: /help') + self.logger.info('Received command: /help') await context.bot.send_message( chat_id=update.effective_chat.id, text=( @@ -93,7 +90,7 @@ async def command_help(self, update: Update, context: ContextTypes.DEFAULT_TYPE) ) async def command_zen(self, update: Update, context: ContextTypes.DEFAULT_TYPE): - self.trace('Received command: /zen') + self.logger.info('Received command: /zen') text = '\n'.join(config.THE_ZEN_OF_PYTHON) await context.bot.send_message( chat_id=update.effective_chat.id, @@ -102,7 +99,7 @@ async def command_zen(self, update: Update, context: ContextTypes.DEFAULT_TYPE): ) async def command_config(self, update: Update, context: ContextTypes.DEFAULT_TYPE): - self.trace('Received command: /config') + self.logger.info('Received command: /config') buff = [ f'Probabilidad de responder: {config.VERBOSITY:.2f}', 'Disparadores:', @@ -118,17 +115,17 @@ async def command_config(self, update: Update, context: ContextTypes.DEFAULT_TYP ) async def welcome(self, update: Update, context): - self.trace('Received new user event') + self.logger.info('Received new user event') new_member = update.message.new_chat_members[0] - self.trace(f'Waiting {config.WELCOME_DELAY} seconds until user completes captcha...') + self.logger.info('Waiting %s seconds until user completes captcha...', config.WELCOME_DELAY) time.sleep(config.WELCOME_DELAY) membership_info = await context.bot.get_chat_member(update.message.chat_id, new_member.id) if membership_info['status'] == 'left': - self.trace(f'Skipping welcome message, user {new_member.name} is no longer in the chat') + self.logger.info('Skipping welcome message, user %s is no longer in the chat', new_member.name) return - self.trace(f'Send welcome message for {new_member.name}') + self.logger.info('Send welcome message for %s', new_member.name) msg = None if new_member.is_bot: @@ -154,11 +151,11 @@ async def reply(self, update: Update, context: ContextTypes.DEFAULT_TYPE): msg = update.message.text reply_spec = utils.triggers_reply(msg) if msg else None if reply_spec is not None: - self.trace(f'Sending reply: {reply_spec.reply}') + self.logger.info('Sending reply: %s', reply_spec.reply) await update.message.reply_text(reply_spec.reply) def run(self): - self.trace('Starting bot') + self.logger.info('Starting bot') application = ApplicationBuilder().token(config.TELEGRAM_BOT_TOKEN).build() start_handler = CommandHandler('start', self.command_start) application.add_handler(start_handler) @@ -183,7 +180,7 @@ def run(self): self.reply, ) application.add_handler(reply_handler) - self.trace('Bot is ready') + self.logger.info('Bot is ready') application.run_polling(poll_interval=config.POLL_INTERVAL)