feat(sender/onebot): 新增onebot协议支持

This commit is contained in:
mei
2026-03-01 15:27:45 +08:00
parent e68d48e816
commit 4f305cfeda
19 changed files with 214 additions and 245 deletions
+23
View File
@@ -0,0 +1,23 @@
package reminder
import (
"fmt"
"log"
"time"
"github.com/ssdomei232/goodBaby/configs"
"github.com/ssdomei232/goodBaby/internal/sender"
)
func Reminder() {
config, err := configs.GetConfig()
if err != nil {
log.Printf("获取配置文件失败: %v", err)
}
remainingTime := GlobalTimerManager.GetRemainingTime()
if remainingTime <= 48*time.Hour {
sendMsg := fmt.Sprintf("距离摇篮系统触发还有%d小时,请尽快发送Signal", int(remainingTime.Hours()))
sender.SendDingTalkMsg("摇篮系统触发提醒", sendMsg, config.DingtalkBot.AccessToken, config.DingtalkBot.Secret)
}
}
+52
View File
@@ -0,0 +1,52 @@
package reminder
import (
"net/http"
"sync"
"time"
"github.com/gin-gonic/gin"
)
type TimerManager struct {
duration time.Duration
resetTime time.Time
mutex sync.RWMutex
}
var GlobalTimerManager *TimerManager
func InitTimerManager(duration time.Duration) {
GlobalTimerManager = &TimerManager{
duration: duration,
resetTime: time.Now(),
}
}
func (tm *TimerManager) Reset() {
tm.mutex.Lock()
defer tm.mutex.Unlock()
tm.resetTime = time.Now()
}
func (tm *TimerManager) GetRemainingTime() time.Duration {
tm.mutex.RLock()
defer tm.mutex.RUnlock()
elapsed := time.Since(tm.resetTime)
remaining := tm.duration - elapsed
if remaining < 0 {
return 0
}
return remaining
}
func HandleTimerStatus(c *gin.Context) {
remainingTime := GlobalTimerManager.GetRemainingTime()
c.JSON(http.StatusOK, gin.H{
"code": 200,
"remaining_time": remainingTime.Seconds(), // 返回剩余秒数
"message": "ok",
})
}