From 9bf6d3d9a4a4e2ae6b8e0b689a95b533a692287c Mon Sep 17 00:00:00 2001 From: purofle Date: Sun, 13 Apr 2025 15:37:40 +0800 Subject: [PATCH] fix: adjust message deletion timing and handle private chat cases --- Dockerfile | 2 +- handlers.go | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 61d075b..b2c388c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:latest as build +FROM golang:latest AS build WORKDIR /src diff --git a/handlers.go b/handlers.go index 2ace500..e267ea4 100644 --- a/handlers.go +++ b/handlers.go @@ -96,7 +96,11 @@ func CommandRemake(c tele.Context) error { return err } - time.AfterFunc(3*time.Second, func() { + if c.Chat().Type == tele.ChatPrivate { + return nil + } + + time.AfterFunc(5*time.Second, func() { err = c.Bot().Delete(reply) err = c.Bot().Delete(msg) if err != nil { @@ -107,6 +111,9 @@ func CommandRemake(c tele.Context) error { } func CommandRemakeData(c tele.Context) error { + + msg := c.Message() + var text string userData, hasKey := remakeCount[c.Sender().ID] if hasKey { @@ -115,7 +122,23 @@ func CommandRemakeData(c tele.Context) error { text = "您还没有 remake 过呢,快 /remake 吧" } - return c.Reply(text) + reply, err := c.Bot().Reply(msg, text) + if err != nil { + return err + } + + if c.Chat().Type == tele.ChatPrivate { + return nil + } + + time.AfterFunc(10*time.Second, func() { + err = c.Bot().Delete(reply) + err = c.Bot().Delete(msg) + if err != nil { + return + } + }) + return nil } func CommandEat(c tele.Context) error {