From fe3d852434b670929c6c173e47aa8d7fbd80ff12 Mon Sep 17 00:00:00 2001 From: Andre Beging Date: Tue, 30 Sep 2025 10:51:22 +0200 Subject: [PATCH] feat: add access control logging and feedback for increment command and button --- bot.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bot.py b/bot.py index 132f037..842c968 100644 --- a/bot.py +++ b/bot.py @@ -151,10 +151,16 @@ async def remove_counter(update: Update, context: ContextTypes.DEFAULT_TYPE): async def increment_counter(update: Update, context: ContextTypes.DEFAULT_TYPE): chat_id = update.effective_chat.id if not context.bot_data['access'](chat_id): + logger.info("Access denied for chat %s on /increment", chat_id) + try: + await update.message.reply_text("Zugriff verweigert: Dieser Chat ist nicht freigeschaltet.") + except Exception: + pass return counters = context.bot_data['counters'] # If no argument: show inline keyboard with counters if not context.args: + logger.debug("/increment without args in chat %s -> showing keyboard (%d counters)", chat_id, len(counters)) if not counters: await update.message.reply_text("Keine Counter vorhanden. Lege einen an mit /add .") return @@ -195,6 +201,7 @@ async def handle_increment_button(update: Update, context: ContextTypes.DEFAULT_ counters = context.bot_data['counters'] chat_id = query.message.chat_id if query.message else None if chat_id is not None and not context.bot_data['access'](chat_id): + logger.info("Access denied for chat %s on increment button %s", chat_id, name) return key = norm_key(name) if key not in counters: @@ -202,6 +209,7 @@ async def handle_increment_button(update: Update, context: ContextTypes.DEFAULT_ return counters[key] += 1 save_counters(counters) + logger.debug("Increment via button: %s -> %d", key, counters[key]) # Rebuild keyboard to reflect new values buttons = [] row: list = []