From 649b1ffbd3bd9b2f79b951745a8ea6b686e09819 Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Sat, 4 Apr 2026 15:05:29 +0700 Subject: [PATCH] revert: remove timezone command and revert date format to simple YYYY-MM-DD This reverts: - cmd_timezone function (issue #67) - format_due_date with human-readable dates (issue #68) - Reverts date display back to time.strftime("%Y-%m-%d") - Keeps /edit command with -link/-date flags (issue #46) --- apps/telegram-bot/bot.py | 3 -- apps/telegram-bot/commands.py | 75 ++++------------------------------- 2 files changed, 7 insertions(+), 71 deletions(-) diff --git a/apps/telegram-bot/bot.py b/apps/telegram-bot/bot.py index a34453b..c72df9c 100644 --- a/apps/telegram-bot/bot.py +++ b/apps/telegram-bot/bot.py @@ -14,7 +14,6 @@ from commands import ( cmd_help, cmd_my, cmd_start, - cmd_timezone, cmd_track, cmd_untrack, cmd_update, @@ -42,7 +41,6 @@ def build_app() -> Application: app.add_handler(CommandHandler("delete", cmd_delete)) app.add_handler(CommandHandler("track", cmd_track)) app.add_handler(CommandHandler("untrack", cmd_untrack)) - app.add_handler(CommandHandler("timezone", cmd_timezone)) app.add_handler(MessageHandler(filters.COMMAND, cmd_help)) @@ -58,7 +56,6 @@ async def post_init(app: Application) -> None: ("edit", "Edit a bounty"), ("track", "Track a bounty"), ("untrack", "Stop tracking"), - ("timezone", "Get/set room timezone"), ("help", "Show help"), ] ) diff --git a/apps/telegram-bot/commands.py b/apps/telegram-bot/commands.py index c8931d9..3c0d338 100644 --- a/apps/telegram-bot/commands.py +++ b/apps/telegram-bot/commands.py @@ -1,10 +1,8 @@ """Telegram command handlers for JIGAIDO - Thin wrappers around core services.""" import time -from datetime import datetime from functools import wraps from typing import Optional -from zoneinfo import ZoneInfo, ZoneInfoNotFoundError import dateparser from telegram import Update @@ -21,33 +19,6 @@ TRACKING_SERVICE = TrackingService(TRACKING_STORAGE, ROOM_STORAGE) TELEGRAM_BOT_USERNAME = "your_bot_username" -def format_due_date(due_date_ts: int | None, timezone_str: str) -> str: - """Format due date as human-readable with timezone. - - Examples: - No due date: (none shown) - Date only: 4 April 2026 - Date + time: 4 April 2026 14:30 - With timezone: 4 April 2026 14:30 (Asia/Jakarta) - """ - if not due_date_ts: - return "" - - try: - tz = ZoneInfo(timezone_str) - except (KeyError, ZoneInfoNotFoundError): - tz = ZoneInfo("UTC") - - dt = datetime.fromtimestamp(due_date_ts, tz=tz) - - date_str = dt.strftime("%-d %B %Y") - - if dt.hour != 0 or dt.minute != 0: - date_str += f" {dt.strftime('%H:%M')}" - date_str += f" ({timezone_str})" - - return date_str - def extract_args(text: str) -> list[str]: if not text: @@ -114,7 +85,7 @@ def parse_args( return text, link, due_date_ts, clear_link, clear_date -def format_bounty(b, show_id: bool = True, room_id: int | None = None) -> str: +def format_bounty(b, show_id: bool = True) -> str: parts = [] if show_id: parts.append(f"[#{b.id}]") @@ -123,11 +94,7 @@ def format_bounty(b, show_id: bool = True, room_id: int | None = None) -> str: if b.link: parts.append(f"🔗 {b.link}") if b.due_date_ts: - timezone_str = "UTC" - if room_id is not None: - timezone_str = BOUNTY_SERVICE.get_timezone(room_id) - - due_str = format_due_date(b.due_date_ts, timezone_str) + due_str = time.strftime("%Y-%m-%d", time.localtime(b.due_date_ts)) days_left = (b.due_date_ts - int(time.time())) // 86400 if days_left < 0: parts.append(f"⏰ {due_str} (OVERDUE)") @@ -171,7 +138,7 @@ async def cmd_bounty(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: await update.message.reply_text("No bounties yet.") return - lines = [format_bounty(b, show_id=True, room_id=room_id) for b in bounties] + lines = [format_bounty(b, show_id=True) for b in bounties] await update.message.reply_text("\n".join(lines), disable_web_page_preview=True) @@ -195,7 +162,7 @@ async def cmd_my(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: await update.message.reply_text(msg) return - lines = [format_bounty(b, show_id=True, room_id=room_id) for b in bounties] + lines = [format_bounty(b, show_id=True) for b in bounties] await update.message.reply_text("\n".join(lines), disable_web_page_preview=True) @@ -226,9 +193,9 @@ async def cmd_add(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: due_str = "" if due_date_ts: - timezone_str = BOUNTY_SERVICE.get_timezone(room_id) - due_str = f" | Due: {format_due_date(due_date_ts, timezone_str)}" - + due_str = "" + if due_date_ts: + due_str = f" | Due: {time.strftime("%Y-%m-%d", time.localtime(due_date_ts))}" await update.message.reply_text( f"✅ Bounty added (#{bounty.id}){due_str}", disable_web_page_preview=True, @@ -414,37 +381,9 @@ async def cmd_help(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: "/delete — delete bounty (admin only)\n" "/track — track a bounty (groups only)\n" "/untrack — stop tracking (groups only)\n" - "/timezone [tz] — get/set room timezone (admin only)\n" "/start — re-initialize\n" "/help — this message", disable_web_page_preview=True, ) -async def cmd_timezone(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: - args = extract_args(update.message.text) - room_id = get_room_id(update) - user_id = get_user_id(update) - - if not args: - current_tz = BOUNTY_SERVICE.get_timezone(room_id) - await update.message.reply_text(f"Current timezone: {current_tz}") - return - - timezone_str = args[0] - - try: - ZoneInfo(timezone_str) - except (KeyError, ZoneInfoNotFoundError): - await update.message.reply_text( - "⛔ Invalid timezone. Use IANA format (e.g., Asia/Jakarta)" - ) - return - - try: - BOUNTY_SERVICE.set_timezone(room_id, timezone_str, user_id) - except PermissionError as e: - await update.message.reply_text(f"⛔ {e}") - return - - await update.message.reply_text(f"✅ Timezone set to {timezone_str}.")