Skip to content

Commit

Permalink
feat: models tg-notify
Browse files Browse the repository at this point in the history
  • Loading branch information
deanxv committed Jun 3, 2024
1 parent 58117cf commit bd10222
Show file tree
Hide file tree
Showing 12 changed files with 571 additions and 555 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
custom: ['https://cdp-docs.pages.dev/page/sponsors.html']
custom: [ 'https://cdp-docs.pages.dev/page/sponsors.html' ]
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ labels: bug
assignees: ''

---

**温馨提示: 未`star`项目会被自动关闭issue哦!**

**例行检查**
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ labels: enhancement
assignees: ''

---

**温馨提示: 未`star`项目会被自动关闭issue哦!**

**例行检查**
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CloseIssue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CloseIssue
on:
workflow_dispatch:
issues:
types: [opened]
types: [ opened ]

jobs:
run-python-script:
Expand Down
2 changes: 1 addition & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package common

var Version = "v4.4.12" // this hard coding will be replaced automatically when building, no need to manually change
var Version = "v4.5.0" // this hard coding will be replaced automatically when building, no need to manually change

const (
RequestIdKey = "X-Request-Id"
Expand Down
7 changes: 7 additions & 0 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,10 @@ func FilterSlice(slice []string, filter string) []string {
}
return result
}

// isSameDay 检查两个时间是否为同一天
func IsSameDay(t1, t2 time.Time) bool {
y1, m1, d1 := t1.Date()
y2, m2, d2 := t2.Date()
return y1 == y2 && m1 == m2 && d1 == d2
}
3 changes: 2 additions & 1 deletion controller/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,12 @@ func checkUserAuths(c *gin.Context) error {
if len(discord.UserAuthorizations) == 0 {
common.LogError(c, fmt.Sprintf("无可用的 user_auth"))
// tg发送通知
if telegram.NotifyTelegramBotToken != "" && telegram.TgBot != nil {
if !common.IsSameDay(discord.NoAvailableUserAuthPreNotifyTime, time.Now()) && telegram.NotifyTelegramBotToken != "" && telegram.TgBot != nil {
go func() {
discord.NoAvailableUserAuthChan <- "stop"
}()
}

return fmt.Errorf("no_available_user_auth")
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion discord/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func CreateChannelWithRetry(c *gin.Context, guildID, channelName string, channel
}
}
// tg发送通知
if telegram.NotifyTelegramBotToken != "" && telegram.TgBot != nil {
if !common.IsSameDay(CreateChannelRiskPreNotifyTime, time.Now()) && telegram.NotifyTelegramBotToken != "" && telegram.TgBot != nil {
go func() {
CreateChannelRiskChan <- "stop"
}()
Expand Down
12 changes: 9 additions & 3 deletions discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ var UserAuthorizations = strings.Split(UserAuthorization, ",")
var NoAvailableUserAuthChan = make(chan string)
var CreateChannelRiskChan = make(chan string)

var NoAvailableUserAuthPreNotifyTime time.Time
var CreateChannelRiskPreNotifyTime time.Time

var BotConfigList []model.BotConfig

var RepliesChans = make(map[string]chan model.ReplyResp)
Expand Down Expand Up @@ -114,6 +117,7 @@ func StartBot(ctx context.Context, token string) {
}

func telegramNotifyMsgTask() {

for NoAvailableUserAuthChan != nil || CreateChannelRiskChan != nil {
select {
case msg, ok := <-NoAvailableUserAuthChan:
Expand All @@ -123,7 +127,8 @@ func telegramNotifyMsgTask() {
if err != nil {
common.LogWarn(nil, fmt.Sprintf("Telegram 推送消息异常 error:%s", err.Error()))
} else {
NoAvailableUserAuthChan = nil // 停止监听ch1
//NoAvailableUserAuthChan = nil // 停止监听ch1
NoAvailableUserAuthPreNotifyTime = time.Now()
}
} else if !ok {
NoAvailableUserAuthChan = nil // 如果ch1已关闭,停止监听
Expand All @@ -135,7 +140,8 @@ func telegramNotifyMsgTask() {
if err != nil {
common.LogWarn(nil, fmt.Sprintf("Telegram 推送消息异常 error:%s", err.Error()))
} else {
CreateChannelRiskChan = nil
//CreateChannelRiskChan = nil
CreateChannelRiskPreNotifyTime = time.Now()
}
} else if !ok {
CreateChannelRiskChan = nil
Expand Down Expand Up @@ -457,7 +463,7 @@ func SendMessage(c *gin.Context, channelID, cozeBotId, message string) (*discord
common.LogError(ctx, fmt.Sprintf("无可用的 user_auth"))

// tg发送通知
if telegram.NotifyTelegramBotToken != "" && telegram.TgBot != nil {
if !common.IsSameDay(NoAvailableUserAuthPreNotifyTime, time.Now()) && telegram.NotifyTelegramBotToken != "" && telegram.TgBot != nil {
go func() {
NoAvailableUserAuthChan <- "stop"
}()
Expand Down
Binary file modified docs/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit bd10222

Please sign in to comment.