You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.4 KiB
61 lines
1.4 KiB
6 months ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
livev1 "git.gz.internal.jumaiyx.cn/jm/jmproto/live/v1"
|
||
|
"git.gz.internal.jumaiyx.cn/pkg/client"
|
||
|
"git.gz.internal.jumaiyx.cn/pkg/jtime"
|
||
|
k8sclient "git.gz.internal.jumaiyx.cn/pkg/k8s-client/v2"
|
||
|
"git.gz.internal.jumaiyx.cn/pkg/webhook/wechat"
|
||
|
"strconv"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
start := time.Now().Unix()
|
||
|
err := task()
|
||
|
times := time.Now().Unix() - start
|
||
|
if times == 0 {
|
||
|
times = 1
|
||
|
}
|
||
|
wechatHook(times, err)
|
||
|
}
|
||
|
|
||
|
func task() error {
|
||
|
ctx := context.Background()
|
||
|
liveClient, liveClientClose, err := client.GetLiveClient(ctx)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer func() { _ = liveClientClose() }()
|
||
|
_, err = liveClient.ClearMessage(ctx, &livev1.ClearMessageReq{
|
||
|
LtCreateTimes: jtime.SecondsAgoTime(time.Now(), -(86400 * 7)).Unix(),
|
||
|
})
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func wechatHook(times int64, err error) {
|
||
|
if err == nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
envi := "测试"
|
||
|
if k8sclient.Environment() == k8sclient.MasterNamespace {
|
||
|
envi = "正式"
|
||
|
}
|
||
|
hook := wechat.NewMarkdown("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=88967358-abc1-4e06-bac6-ec202f18875a").
|
||
|
Title(1, "聊天记录清除").Br().
|
||
|
Text("环境:" + envi).Br().
|
||
|
Text("耗时:" + strconv.Itoa(int(times)) + "s").Br().Text("状态:")
|
||
|
if err != nil {
|
||
|
hook = hook.FontColor("失败", wechat.Warning).Br().Text("异常:").FontColor(err.Error(), wechat.Warning)
|
||
|
} else {
|
||
|
hook = hook.FontColor("完成", wechat.Info)
|
||
|
}
|
||
|
_ = hook.Send()
|
||
|
|
||
|
}
|