Compare commits
1 Commits
350ecbf867
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bac6830fc3 |
@@ -1,8 +1,6 @@
|
|||||||
"""Telegram command handlers for JIGAIDO - Thin wrappers around core services."""
|
"""Telegram command handlers for JIGAIDO - Thin wrappers around core services."""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from datetime import datetime, timezone
|
|
||||||
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
||||||
@@ -22,36 +20,6 @@ TRACKING_SERVICE = TrackingService(TRACKING_STORAGE, ROOM_STORAGE)
|
|||||||
TELEGRAM_BOT_USERNAME = "your_bot_username"
|
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]:
|
def extract_args(text: str) -> list[str]:
|
||||||
if not text:
|
if not text:
|
||||||
return []
|
return []
|
||||||
@@ -261,18 +229,24 @@ async def cmd_add(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|||||||
user_id = get_user_id(update)
|
user_id = get_user_id(update)
|
||||||
room_id = get_room_id(update)
|
room_id = get_room_id(update)
|
||||||
|
|
||||||
bounty = BOUNTY_SERVICE.add_bounty(
|
try:
|
||||||
room_id=room_id,
|
bounty = BOUNTY_SERVICE.add_bounty(
|
||||||
user_id=user_id,
|
room_id=room_id,
|
||||||
text=text,
|
user_id=user_id,
|
||||||
link=link,
|
text=text,
|
||||||
due_date_ts=due_date_ts,
|
link=link,
|
||||||
)
|
due_date_ts=due_date_ts,
|
||||||
|
)
|
||||||
|
except PermissionError as e:
|
||||||
|
await update.message.reply_text(f"⛔ {e}")
|
||||||
|
return
|
||||||
|
except ValueError as e:
|
||||||
|
await update.message.reply_text(f"⛔ {e}")
|
||||||
|
return
|
||||||
|
|
||||||
due_str = ""
|
due_str = ""
|
||||||
if due_date_ts:
|
if due_date_ts:
|
||||||
timezone_str = BOUNTY_SERVICE.get_timezone(room_id)
|
due_str = f" | Due: {time.strftime('%Y-%m-%d', time.localtime(due_date_ts))}"
|
||||||
due_str = f" | Due: {format_due_date(due_date_ts, timezone_str)}"
|
|
||||||
await update.message.reply_text(
|
await update.message.reply_text(
|
||||||
f"✅ Bounty added (#{bounty.id}){due_str}",
|
f"✅ Bounty added (#{bounty.id}){due_str}",
|
||||||
disable_web_page_preview=True,
|
disable_web_page_preview=True,
|
||||||
|
|||||||
Reference in New Issue
Block a user