Skip to content

Commit

Permalink
fix: max_token
Browse files Browse the repository at this point in the history
  • Loading branch information
deanxv committed Aug 24, 2024
1 parent b06b0c1 commit db067a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
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.6.1" // this hard coding will be replaced automatically when building, no need to manually change
var Version = "v4.6.2" // this hard coding will be replaced automatically when building, no need to manually change

const (
RequestIdKey = "X-Request-Id"
Expand Down
22 changes: 15 additions & 7 deletions discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var CreateChannelRiskChan = make(chan string)
var NoAvailableUserAuthPreNotifyTime time.Time
var CreateChannelRiskPreNotifyTime time.Time

var BotConfigList []model.BotConfig
var BotConfigList []*model.BotConfig
var BotConfigExist bool

var RepliesChans = make(map[string]chan model.ReplyResp)
Expand Down Expand Up @@ -313,7 +313,15 @@ func loadBotConfig() {
}

BotConfigExist = true
common.SysLog(fmt.Sprintf("载入配置文件成功 BotConfigs: %+v", BotConfigList))

// 将结构体切片转换为 JSON 字符串
jsonData, err := json.MarshalIndent(BotConfigList, "", " ")
if err != nil {
common.FatalLog(fmt.Sprintf("Error marshalling BotConfigs: %v", err))
}

// 打印 JSON 字符串
common.SysLog(fmt.Sprintf("载入配置文件成功 BotConfigs:\n%s", string(jsonData)))
}

// messageCreate handles the create messages in Discord.
Expand Down Expand Up @@ -637,7 +645,7 @@ func stayActiveMessageTask() {

var taskBotConfigs = BotConfigList

taskBotConfigs = append(taskBotConfigs, model.BotConfig{
taskBotConfigs = append(taskBotConfigs, &model.BotConfig{
ChannelId: ChannelId,
CozeBotId: CozeBotId,
})
Expand Down Expand Up @@ -728,8 +736,8 @@ func UploadToDiscordAndGetURL(channelID string, base64Data string) (string, erro
}

// FilterConfigs 根据proxySecret和channelId过滤BotConfig
func FilterConfigs(configs []model.BotConfig, secret, gptModel string, channelId *string) []model.BotConfig {
var filteredConfigs []model.BotConfig
func FilterConfigs(configs []*model.BotConfig, secret, gptModel string, channelId *string) []*model.BotConfig {
var filteredConfigs []*model.BotConfig
for _, config := range configs {
matchSecret := secret == "" || config.ProxySecret == secret
matchGptModel := gptModel == "" || common.SliceContains(config.Model, gptModel)
Expand All @@ -751,8 +759,8 @@ func DelLimitBot(botId string) {
}
}

func FilterBotConfigByBotId(slice []model.BotConfig, filter string) []model.BotConfig {
var result []model.BotConfig
func FilterBotConfigByBotId(slice []*model.BotConfig, filter string) []*model.BotConfig {
var result []*model.BotConfig
for _, value := range slice {
if value.CozeBotId != filter {
result = append(result, value)
Expand Down
4 changes: 2 additions & 2 deletions model/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ type BotConfig struct {
}

// FilterUniqueBotChannel 给定BotConfig切片,筛选出具有不同CozeBotId+ChannelId组合的元素
func FilterUniqueBotChannel(configs []BotConfig) []BotConfig {
func FilterUniqueBotChannel(configs []*BotConfig) []*BotConfig {
seen := make(map[string]struct{}) // 使用map来跟踪已见的CozeBotId+ChannelId组合
var uniqueConfigs []BotConfig
var uniqueConfigs []*BotConfig

for _, config := range configs {
combo := config.CozeBotId + "+" + config.ChannelId // 创建组合键
Expand Down

0 comments on commit db067a0

Please sign in to comment.