Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta321 #324

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ type Settings struct {
LinkText string `yaml:"link_text"`
LinkPic string `yaml:"link_pic"`
MusicPrefix string `yaml:"music_prefix"`
DisableWebui bool `yaml:"disable_webui"`
}

// LoadConfig 从文件中加载配置并初始化单例配置
Expand Down Expand Up @@ -1776,3 +1777,15 @@ func GetMusicPrefix() string {
}
return instance.Settings.MusicPrefix
}

// 获取 GetDisableWebui 的值
func GetDisableWebui() bool {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to GetDisableWebui value.")
return false
}
return instance.Settings.DisableWebui
}
5 changes: 2 additions & 3 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,21 +1057,20 @@ func SendStackMessages(apiv2 openapi.OpenAPI, messageid string, GroupID string)
mylog.Printf("取出数量: %v", count)
pairs := echo.PopGlobalStackMulti(count)
for i, pair := range pairs {
mylog.Printf("%v: %v", pair.Group, GroupID)
mylog.Printf("发送栈中的消息匹配 %v: %v", pair.Group, GroupID)
if pair.Group == GroupID {
// 发送消息
msgseq := echo.GetMappingSeq(messageid)
echo.AddMappingSeq(messageid, msgseq+1)
pair.GroupMessage.MsgSeq = msgseq + 1
pair.GroupMessage.MsgID = messageid
mylog.Printf("发送栈中的消息 使用MsgSeq[%v]使用MsgID[%v]", pair.GroupMessage.MsgSeq, pair.GroupMessage.MsgID)
_, err := apiv2.PostGroupMessage(context.TODO(), pair.Group, pair.GroupMessage)
if err != nil {
mylog.Printf("发送组合消息失败: %v", err)
continue
} else {
echo.RemoveFromGlobalStack(i)
}

// 检查错误码
if err != nil && strings.Contains(err.Error(), `"code":22009`) {
mylog.Printf("信息再次发送失败,加入到队列中,下次被动信息进行发送")
Expand Down
27 changes: 27 additions & 0 deletions httpapi/httpapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func CombinedMiddleware(api openapi.OpenAPI, apiV2 openapi.OpenAPI) gin.HandlerF
handleSendGuildChannelMessage(c, api, apiV2)
return
}
if c.Request.URL.Path == "/get_group_list" {
handleGetGroupList(c, api, apiV2)
return
}

// 调用c.Next()以继续处理请求链
c.Next()
Expand Down Expand Up @@ -197,3 +201,26 @@ func (c *HttpAPIClient) SendMessage(message map[string]interface{}) error {
// 返回nil占位符
return nil
}

// handleGetGroupList 处理获取群列表
func handleGetGroupList(c *gin.Context, api openapi.OpenAPI, apiV2 openapi.OpenAPI) {
var retmsg string

// 使用解析后的参数处理请求
client := &HttpAPIClient{}
// 创建 ActionMessage 实例
message := callapi.ActionMessage{
Action: "get_group_list",
}

// 调用处理函数
retmsg, err := handlers.GetGroupList(client, api, apiV2, message)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

// 返回处理结果
c.Header("Content-Type", "application/json")
c.String(http.StatusOK, retmsg)
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func main() {
r.POST("/uploadpic", server.UploadBase64ImageHandler(rateLimiter))
r.POST("/uploadrecord", server.UploadBase64RecordHandler(rateLimiter))
r.Static("/channel_temp", "./channel_temp")
if config.GetFrpPort() == "0" {
if config.GetFrpPort() == "0" && !config.GetDisableWebui() {
//webui和它的api
webuiGroup := r.Group("/webui")
{
Expand All @@ -308,6 +308,8 @@ func main() {
webuiGroup.DELETE("/*filepath", webui.CombinedMiddleware(api, apiV2))
webuiGroup.PATCH("/*filepath", webui.CombinedMiddleware(api, apiV2))
}
} else {
mylog.Println("Either FRP port is set to '0' or WebUI is disabled.")
}
//正向http api
http_api_address := config.GetHttpAddress()
Expand Down
1 change: 1 addition & 0 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ settings:
url_pic_transfer : false #把图片url(任意来源图链)变成你备案的白名单url 需要较高上下行+ssl+自备案域名+设置白名单域名(暂时不需要)
idmap_pro : false #需开启hash_id配合,高级id转换增强,可以多个真实值bind到同一个虚拟值,对于每个用户,每个群\私聊\判断私聊\频道,都会产生新的虚拟值,但可以多次bind,bind到同一个数字.数据库负担会变大.
send_delay : 300 #单位 毫秒 默认300ms 可以视情况减少到100或者50
disable_webui: false #禁用webui

title : "Gensokyo © 2023 - Hoshinonyaruko" #程序的标题 如果多个机器人 可根据标题区分
custom_bot_name : "Gensokyo全域机器人" #自定义机器人名字,会在api调用中返回,默认Gensokyo全域机器人
Expand Down
Loading