feat: add /summary, /setbreak, weekly totals, and fix command dispatch for arg-bearing commands

- Add /summary [YYYY-MM] command for monthly work/break/day-off totals

- Add weekly totals row to main menu status

- Add /setbreak <minutes> for configurable daily break threshold

- Fix HandleMessage routing: extract command name instead of exact match (fixes /export YYYY-MM, /edit, /note, /summary, /setbreak)

- Update README with full command table and configurable break docs
This commit is contained in:
2026-06-24 20:39:51 +03:30
parent 323c1bc010
commit 834c318271
6 changed files with 255 additions and 15 deletions

View File

@@ -106,6 +106,9 @@ func (h *Handler) HandleMessage(ctx context.Context, msg *models.Message) {
if len(h.AllowedUsers) > 0 && !h.AllowedUsers[msg.Chat.ID] {
return
}
if msg.Text == "" {
return
}
user, err := h.getOrCreateUser(msg.Chat.ID)
if err != nil {
return
@@ -122,7 +125,7 @@ func (h *Handler) HandleMessage(ctx context.Context, msg *models.Message) {
delete(h.pendingNotes, msg.Chat.ID)
}
h.mu.Unlock()
if hasPN && msg.Text != "" && msg.Text[0] != '/' {
if hasPN && msg.Text[0] != '/' {
loc := loadLocation(user.Timezone)
event, err := h.getEventByID(user.ID, pn.eventID)
if err == nil {
@@ -135,7 +138,17 @@ func (h *Handler) HandleMessage(ctx context.Context, msg *models.Message) {
return
}
switch msg.Text {
if msg.Text[0] != '/' {
h.sendText(ctx, msg.Chat.ID, "Unknown command")
return
}
cmd := msg.Text
if i := strings.IndexByte(msg.Text, ' '); i >= 0 {
cmd = msg.Text[:i]
}
switch cmd {
case "/start":
h.handleStart(ctx, msg)
case "/help":
@@ -166,6 +179,10 @@ func (h *Handler) HandleMessage(ctx context.Context, msg *models.Message) {
h.handleSetTimezone(ctx, msg)
case "/note":
h.handleNoteMsg(ctx, msg)
case "/summary":
h.handleSummaryMsg(ctx, msg)
case "/setbreak":
h.handleSetBreakMsg(ctx, msg)
default:
h.sendText(ctx, msg.Chat.ID, "Unknown command")
}
@@ -294,10 +311,12 @@ func (h *Handler) handleHelp(ctx context.Context, msg *models.Message) {
/history - View calendar history
/edit YYYY-MM-DD - Edit a specific day
/note [YYYY-MM-DD] HH:MM <text> - Set note for an event
/summary [YYYY-MM] - Show monthly summary (current month if omitted)
/reporttoggle - Enable/disable auto report
/setreporttime HH:MM - Set daily report time
/setaccent - Select accent color
/settimezone <name> - Set your timezone (e.g. Asia/Tehran)
/setbreak <minutes> - Set minimum break threshold in minutes
Dates use your calendar type (Gregorian/Jalali/Hijri).
Buttons on the main menu also work.`