|
|
|
|
@@ -114,12 +114,17 @@ 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, slice_length: int = 0, room_id: int | None = None
|
|
|
|
|
) -> str:
|
|
|
|
|
parts = []
|
|
|
|
|
if show_id:
|
|
|
|
|
parts.append(f"[#{b.id}]")
|
|
|
|
|
if b.text:
|
|
|
|
|
parts.append(b.text)
|
|
|
|
|
text = b.text
|
|
|
|
|
if slice_length > 0 and len(text) > slice_length:
|
|
|
|
|
text = text[:slice_length] + "..."
|
|
|
|
|
parts.append(text)
|
|
|
|
|
if b.link:
|
|
|
|
|
parts.append(f"🔗 {b.link}")
|
|
|
|
|
if b.due_date_ts:
|
|
|
|
|
@@ -132,7 +137,7 @@ def format_bounty(b, show_id: bool = True, room_id: int | None = None) -> str:
|
|
|
|
|
if days_left < 0:
|
|
|
|
|
parts.append(f"⏰ {due_str} (OVERDUE)")
|
|
|
|
|
elif days_left == 0:
|
|
|
|
|
parts.append(f"⏰ {due_str} (TODAY)")
|
|
|
|
|
parts.append(f"⏰ Today (OVERDUE)")
|
|
|
|
|
else:
|
|
|
|
|
parts.append(f"⏰ {due_str} ({days_left}d)")
|
|
|
|
|
if b.created_by_user_id:
|
|
|
|
|
@@ -165,13 +170,60 @@ def get_room_id(update: Update) -> int:
|
|
|
|
|
|
|
|
|
|
async def cmd_bounty(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
|
|
room_id = get_room_id(update)
|
|
|
|
|
bounties = BOUNTY_SERVICE.list_bounties(room_id)
|
|
|
|
|
args = extract_args(update.message.text)
|
|
|
|
|
|
|
|
|
|
if not bounties:
|
|
|
|
|
show_all = "all" in args
|
|
|
|
|
args = [a for a in args if a != "all"]
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
limit = int(args[0]) if args else 5
|
|
|
|
|
except (ValueError, IndexError):
|
|
|
|
|
limit = 5
|
|
|
|
|
|
|
|
|
|
now = int(time.time())
|
|
|
|
|
cutoff_24h = now - 86400
|
|
|
|
|
|
|
|
|
|
all_bounties = BOUNTY_SERVICE.list_bounties(room_id)
|
|
|
|
|
|
|
|
|
|
def is_expired(b) -> bool:
|
|
|
|
|
return b.due_date_ts is not None and b.due_date_ts < cutoff_24h
|
|
|
|
|
|
|
|
|
|
def sort_key(b):
|
|
|
|
|
if b.due_date_ts is not None:
|
|
|
|
|
return (0, b.due_date_ts)
|
|
|
|
|
return (1, b.created_at)
|
|
|
|
|
|
|
|
|
|
filtered_bounties = [b for b in all_bounties if not is_expired(b) or show_all]
|
|
|
|
|
filtered_bounties.sort(key=sort_key)
|
|
|
|
|
|
|
|
|
|
total_count = len(filtered_bounties)
|
|
|
|
|
displayed_bounties = filtered_bounties[:limit]
|
|
|
|
|
|
|
|
|
|
if not displayed_bounties:
|
|
|
|
|
if show_all:
|
|
|
|
|
await update.message.reply_text("No bounties yet.")
|
|
|
|
|
else:
|
|
|
|
|
await update.message.reply_text(
|
|
|
|
|
"No active bounties. Use /bounty all to show expired."
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
lines = [format_bounty(b, show_id=True, room_id=room_id) for b in bounties]
|
|
|
|
|
lines = []
|
|
|
|
|
if limit < total_count:
|
|
|
|
|
lines.append(f"Showing {limit} of {total_count} bounties:")
|
|
|
|
|
slice_length = 40
|
|
|
|
|
elif show_all and total_count > limit:
|
|
|
|
|
lines.append(f"Showing {limit} of {total_count} bounties (including expired):")
|
|
|
|
|
slice_length = 40
|
|
|
|
|
else:
|
|
|
|
|
lines.append(f"Showing {total_count} bounties:")
|
|
|
|
|
slice_length = 0
|
|
|
|
|
|
|
|
|
|
for b in displayed_bounties:
|
|
|
|
|
lines.append(
|
|
|
|
|
format_bounty(b, show_id=True, slice_length=slice_length, room_id=room_id)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
await update.message.reply_text("\n".join(lines), disable_web_page_preview=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -228,7 +280,6 @@ async def cmd_add(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
|
|
if due_date_ts:
|
|
|
|
|
timezone_str = BOUNTY_SERVICE.get_timezone(room_id)
|
|
|
|
|
due_str = f" | Due: {format_due_date(due_date_ts, timezone_str)}"
|
|
|
|
|
|
|
|
|
|
await update.message.reply_text(
|
|
|
|
|
f"✅ Bounty added (#{bounty.id}){due_str}",
|
|
|
|
|
disable_web_page_preview=True,
|
|
|
|
|
@@ -401,6 +452,48 @@ async def cmd_start(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def cmd_show(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
|
|
args = extract_args(update.message.text)
|
|
|
|
|
if not args:
|
|
|
|
|
await update.message.reply_text("Usage: /show <bounty_id>")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
bounty_id = int(args[0])
|
|
|
|
|
except ValueError:
|
|
|
|
|
await update.message.reply_text("Invalid bounty ID.")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
room_id = get_room_id(update)
|
|
|
|
|
bounty = BOUNTY_SERVICE.get_bounty(room_id, bounty_id)
|
|
|
|
|
|
|
|
|
|
if not bounty:
|
|
|
|
|
await update.message.reply_text("Bounty not found.")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
timezone = BOUNTY_SERVICE.get_timezone(room_id)
|
|
|
|
|
|
|
|
|
|
lines = []
|
|
|
|
|
|
|
|
|
|
title = bounty.text or "(no text)"
|
|
|
|
|
lines.append(f"[#{bounty.id}] {title}")
|
|
|
|
|
|
|
|
|
|
if bounty.link:
|
|
|
|
|
lines.append(f"🔗 {bounty.link}")
|
|
|
|
|
|
|
|
|
|
if bounty.due_date_ts:
|
|
|
|
|
due_str = format_due_date(bounty.due_date_ts, timezone)
|
|
|
|
|
lines.append(f"📅 {due_str}")
|
|
|
|
|
|
|
|
|
|
username = bounty.created_by_username or f"user#{bounty.created_by_user_id}"
|
|
|
|
|
lines.append(f"👤 @{username}")
|
|
|
|
|
|
|
|
|
|
created_str = time.strftime("%Y-%m-%d %H:%M", time.localtime(bounty.created_at))
|
|
|
|
|
lines.append(f"📌 Created: {created_str}")
|
|
|
|
|
|
|
|
|
|
await update.message.reply_text("\n".join(lines), disable_web_page_preview=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def cmd_help(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
|
|
await update.message.reply_text(
|
|
|
|
|
"👻 JIGAIDO Commands:\n\n"
|
|
|
|
|
@@ -414,37 +507,8 @@ async def cmd_help(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
|
|
"/delete <id> — delete bounty (admin only)\n"
|
|
|
|
|
"/track <id> — track a bounty (groups only)\n"
|
|
|
|
|
"/untrack <id> — stop tracking (groups only)\n"
|
|
|
|
|
"/timezone [tz] — get/set room timezone (admin only)\n"
|
|
|
|
|
"/show <id> — show bounty details\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}.")
|
|
|
|
|
|