mirror of
https://github.com/deanxv/coze-discord-proxy.git
synced 2026-06-04 21:02:47 +08:00
feat: models tg-notify
This commit is contained in:
parent
58117cfd9f
commit
bd10222eb0
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@ -1 +1 @@
|
||||
custom: ['https://cdp-docs.pages.dev/page/sponsors.html']
|
||||
custom: [ 'https://cdp-docs.pages.dev/page/sponsors.html' ]
|
||||
|
||||
1
.github/ISSUE_TEMPLATE/bug_report.md
vendored
1
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -6,6 +6,7 @@ labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**温馨提示: 未`star`项目会被自动关闭issue哦!**
|
||||
|
||||
**例行检查**
|
||||
|
||||
1
.github/ISSUE_TEMPLATE/feature_request.md
vendored
1
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -6,6 +6,7 @@ labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**温馨提示: 未`star`项目会被自动关闭issue哦!**
|
||||
|
||||
**例行检查**
|
||||
|
||||
2
.github/workflows/CloseIssue.yml
vendored
2
.github/workflows/CloseIssue.yml
vendored
@ -3,7 +3,7 @@ name: CloseIssue
|
||||
on:
|
||||
workflow_dispatch:
|
||||
issues:
|
||||
types: [opened]
|
||||
types: [ opened ]
|
||||
|
||||
jobs:
|
||||
run-python-script:
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
}()
|
||||
|
||||
@ -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)
|
||||
@ -114,6 +117,7 @@ func StartBot(ctx context.Context, token string) {
|
||||
}
|
||||
|
||||
func telegramNotifyMsgTask() {
|
||||
|
||||
for NoAvailableUserAuthChan != nil || CreateChannelRiskChan != nil {
|
||||
select {
|
||||
case msg, ok := <-NoAvailableUserAuthChan:
|
||||
@ -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已关闭,停止监听
|
||||
@ -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
|
||||
@ -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"
|
||||
}()
|
||||
|
||||
BIN
docs/img.png
BIN
docs/img.png
Binary file not shown.
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 108 KiB |
File diff suppressed because it is too large
Load Diff
@ -53,7 +53,7 @@ definitions:
|
||||
type: object
|
||||
model.OpenAIChatMessage:
|
||||
properties:
|
||||
content: {}
|
||||
content: { }
|
||||
role:
|
||||
type: string
|
||||
type: object
|
||||
@ -159,7 +159,7 @@ definitions:
|
||||
type: string
|
||||
type: object
|
||||
info:
|
||||
contact: {}
|
||||
contact: { }
|
||||
description: COZE-DISCORD-PROXY 代理服务
|
||||
title: COZE-DISCORD-PROXY
|
||||
version: 1.0.0
|
||||
@ -167,17 +167,17 @@ paths:
|
||||
/api/channel/create:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
- application/json
|
||||
description: 创建频道
|
||||
parameters:
|
||||
- description: channelModel
|
||||
in: body
|
||||
name: channelModel
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/model.ChannelReq'
|
||||
- description: channelModel
|
||||
in: body
|
||||
name: channelModel
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/model.ChannelReq'
|
||||
produces:
|
||||
- application/json
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Successful response
|
||||
@ -185,20 +185,20 @@ paths:
|
||||
$ref: '#/definitions/model.ChannelResp'
|
||||
summary: 创建频道
|
||||
tags:
|
||||
- channel
|
||||
- channel
|
||||
/api/channel/del/{id}:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
- application/json
|
||||
description: 删除频道
|
||||
parameters:
|
||||
- description: id
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: string
|
||||
- description: id
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Successful response
|
||||
@ -206,14 +206,14 @@ paths:
|
||||
type: string
|
||||
summary: 删除频道
|
||||
tags:
|
||||
- channel
|
||||
- channel
|
||||
/api/del/all/cdp:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
- application/json
|
||||
description: 删除全部CDP临时频道[谨慎调用]
|
||||
produces:
|
||||
- application/json
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Successful response
|
||||
@ -221,21 +221,21 @@ paths:
|
||||
type: string
|
||||
summary: 删除全部CDP临时频道[谨慎调用]
|
||||
tags:
|
||||
- channel
|
||||
- channel
|
||||
/api/thread/create:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
- application/json
|
||||
description: 创建线程
|
||||
parameters:
|
||||
- description: threadModel
|
||||
in: body
|
||||
name: threadModel
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/model.ThreadReq'
|
||||
- description: threadModel
|
||||
in: body
|
||||
name: threadModel
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/model.ThreadReq'
|
||||
produces:
|
||||
- application/json
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Successful response
|
||||
@ -243,29 +243,29 @@ paths:
|
||||
$ref: '#/definitions/model.ThreadResp'
|
||||
summary: 创建线程
|
||||
tags:
|
||||
- thread
|
||||
- thread
|
||||
/v1/chat/completions:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
- application/json
|
||||
description: 发送消息-openai
|
||||
parameters:
|
||||
- description: request
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/model.OpenAIChatCompletionRequest'
|
||||
- description: Authorization
|
||||
in: header
|
||||
name: Authorization
|
||||
type: string
|
||||
- description: out-time
|
||||
in: header
|
||||
name: out-time
|
||||
type: string
|
||||
- description: request
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/model.OpenAIChatCompletionRequest'
|
||||
- description: Authorization
|
||||
in: header
|
||||
name: Authorization
|
||||
type: string
|
||||
- description: out-time
|
||||
in: header
|
||||
name: out-time
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Successful response
|
||||
@ -273,29 +273,29 @@ paths:
|
||||
$ref: '#/definitions/model.OpenAIChatCompletionResponse'
|
||||
summary: 发送消息-openai
|
||||
tags:
|
||||
- openai
|
||||
- openai
|
||||
/v1/images/generations:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
- application/json
|
||||
description: 图片生成-openai
|
||||
parameters:
|
||||
- description: request
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/model.OpenAIImagesGenerationRequest'
|
||||
- description: Authorization
|
||||
in: header
|
||||
name: Authorization
|
||||
type: string
|
||||
- description: out-time
|
||||
in: header
|
||||
name: out-time
|
||||
type: string
|
||||
- description: request
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/model.OpenAIImagesGenerationRequest'
|
||||
- description: Authorization
|
||||
in: header
|
||||
name: Authorization
|
||||
type: string
|
||||
- description: out-time
|
||||
in: header
|
||||
name: out-time
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Successful response
|
||||
@ -303,19 +303,19 @@ paths:
|
||||
$ref: '#/definitions/model.OpenAIImagesGenerationResponse'
|
||||
summary: 图片生成-openai
|
||||
tags:
|
||||
- openai
|
||||
- openai
|
||||
/v1/models:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
- application/json
|
||||
description: 模型列表-openai
|
||||
parameters:
|
||||
- description: Authorization
|
||||
in: header
|
||||
name: Authorization
|
||||
type: string
|
||||
- description: Authorization
|
||||
in: header
|
||||
name: Authorization
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Successful response
|
||||
@ -323,5 +323,5 @@ paths:
|
||||
$ref: '#/definitions/model.OpenaiModelListResponse'
|
||||
summary: 模型列表-openai
|
||||
tags:
|
||||
- openai
|
||||
- openai
|
||||
swagger: "2.0"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user