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

Test4 #36

Merged
merged 56 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
fad0d50
Compiled main.go and pushed changes
Hoshinonyaruko Oct 23, 2023
fda2572
test
Hoshinonyaruko Oct 23, 2023
34cfac1
适配了频道私聊,用bolt数据库取代ini
Hoshinonyaruko Oct 23, 2023
7fc1f10
适配了nonebot2
Hoshinonyaruko Oct 24, 2023
28f9a73
Merge branch 'main' of https://github.com/Hoshinonyaruko/Gensokyo
Hoshinonyaruko Oct 24, 2023
9fadda4
适配私域
Hoshinonyaruko Oct 24, 2023
1336c6a
add license
Hoshinonyaruko Oct 24, 2023
b094949
add a lot
Hoshinonyaruko Oct 25, 2023
f4787f5
Resolved merge conflicts
Hoshinonyaruko Oct 25, 2023
86698c6
trss support
Hoshinonyaruko Oct 26, 2023
045f3e9
fix
Hoshinonyaruko Oct 26, 2023
618561c
add action
Hoshinonyaruko Oct 26, 2023
7e803aa
add action
Hoshinonyaruko Oct 26, 2023
ece4cef
add action
Hoshinonyaruko Oct 26, 2023
f864a50
fixbug
Hoshinonyaruko Oct 26, 2023
4564731
add wss
Hoshinonyaruko Oct 26, 2023
070e4df
merge
Hoshinonyaruko Oct 26, 2023
84e8fe9
bugfix
Hoshinonyaruko Oct 26, 2023
0e4fd50
fix action
Hoshinonyaruko Oct 26, 2023
fe2234a
fix action again
Hoshinonyaruko Oct 26, 2023
cf67a11
fix action againnn
Hoshinonyaruko Oct 26, 2023
0875837
fa
Hoshinonyaruko Oct 26, 2023
3a3c33f
fix
Hoshinonyaruko Oct 26, 2023
8789fa8
add a lot
Hoshinonyaruko Oct 27, 2023
7943466
add ws server token
Hoshinonyaruko Oct 28, 2023
4660983
merge
Hoshinonyaruko Oct 28, 2023
2a1026a
bugifx
Hoshinonyaruko Oct 28, 2023
4186970
fix
Hoshinonyaruko Oct 28, 2023
2f26828
fixat
Hoshinonyaruko Oct 28, 2023
007e1af
bugfix
Hoshinonyaruko Oct 28, 2023
c41fd77
bugfix
Hoshinonyaruko Oct 28, 2023
d8354b7
test
Hoshinonyaruko Oct 28, 2023
6e3c63c
test
Hoshinonyaruko Oct 28, 2023
f08d9d7
test2
Hoshinonyaruko Oct 28, 2023
4dd6e15
add url service
Hoshinonyaruko Oct 31, 2023
1f8c174
add url service
Hoshinonyaruko Oct 31, 2023
240f569
add url service
Hoshinonyaruko Oct 31, 2023
b191cb7
bugfix
Hoshinonyaruko Oct 31, 2023
42daab3
merge
Hoshinonyaruko Oct 31, 2023
8fec03f
fix
Hoshinonyaruko Oct 31, 2023
cca528b
fix
Hoshinonyaruko Oct 31, 2023
463a182
fix
Hoshinonyaruko Oct 31, 2023
e9187a1
bug fix
Hoshinonyaruko Nov 1, 2023
5ba2815
fix
Hoshinonyaruko Nov 1, 2023
c16e1af
fix
Hoshinonyaruko Nov 1, 2023
ec7863d
test
Hoshinonyaruko Nov 2, 2023
e8a7e73
ok
Hoshinonyaruko Nov 2, 2023
122d17d
add webui
Hoshinonyaruko Nov 2, 2023
4e9c209
merge
Hoshinonyaruko Nov 2, 2023
b502d61
add image_compress
Hoshinonyaruko Nov 3, 2023
3519e3e
merge
Hoshinonyaruko Nov 3, 2023
530ff96
bug fix
Hoshinonyaruko Nov 3, 2023
155a701
fix cq code
Hoshinonyaruko Nov 3, 2023
2f5ee4a
fixbug
Hoshinonyaruko Nov 3, 2023
afa03e3
bugfix
Hoshinonyaruko Nov 3, 2023
fdd1a73
merge
Hoshinonyaruko Nov 3, 2023
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
Prev Previous commit
Next Next commit
add wss
  • Loading branch information
Hoshinonyaruko committed Oct 26, 2023
commit 4564731703d3fa8d546b7e1f99ba484eb824ce77
18 changes: 18 additions & 0 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ func (p *Processor) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
Avatar: "",
Echo: echostr,
}
// 获取MasterID数组
masterIDs := config.GetMasterID()

// 判断userid64是否在masterIDs数组里
isMaster := false
for _, id := range masterIDs {
if strconv.FormatInt(userid64, 10) == id {
isMaster = true
break
}
}

// 根据isMaster的值为groupMsg的Sender赋值role字段
if isMaster {
groupMsg.Sender.Role = "owner"
} else {
groupMsg.Sender.Role = "member"
}
//将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "group_private")
Expand Down
35 changes: 35 additions & 0 deletions Processor/ProcessChannelDirectMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,24 @@ func (p *Processor) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) e
Avatar: data.Author.Avatar,
Echo: echostr,
}
// 获取MasterID数组
masterIDs := config.GetMasterID()

// 判断userid64是否在masterIDs数组里
isMaster := false
for _, id := range masterIDs {
if strconv.FormatInt(userid64, 10) == id {
isMaster = true
break
}
}

// 根据isMaster的值为groupMsg的Sender赋值role字段
if isMaster {
onebotMsg.Sender.Role = "owner"
} else {
onebotMsg.Sender.Role = "member"
}
//将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
//通过echo始终得知真实的事件类型,来对应调用正确的api
Expand Down Expand Up @@ -217,6 +234,24 @@ func (p *Processor) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) e
Avatar: data.Author.Avatar,
Echo: echostr,
}
// 获取MasterID数组
masterIDs := config.GetMasterID()

// 判断userid64是否在masterIDs数组里
isMaster := false
for _, id := range masterIDs {
if strconv.FormatInt(userid64, 10) == id {
isMaster = true
break
}
}

// 根据isMaster的值为groupMsg的Sender赋值role字段
if isMaster {
groupMsg.Sender.Role = "owner"
} else {
groupMsg.Sender.Role = "member"
}
//将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "guild_private")
Expand Down
17 changes: 17 additions & 0 deletions Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,24 @@ func (p *Processor) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
Avatar: "",
Echo: echostr,
}
// 获取MasterID数组
masterIDs := config.GetMasterID()

// 判断userid64是否在masterIDs数组里
isMaster := false
for _, id := range masterIDs {
if strconv.FormatInt(userid64, 10) == id {
isMaster = true
break
}
}

// 根据isMaster的值为groupMsg的Sender赋值role字段
if isMaster {
groupMsg.Sender.Role = "owner"
} else {
groupMsg.Sender.Role = "member"
}
// 将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "group")
Expand Down
35 changes: 35 additions & 0 deletions Processor/ProcessGuildATMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,24 @@ func (p *Processor) ProcessGuildATMessage(data *dto.WSATMessageData) error {
Avatar: data.Author.Avatar,
Echo: echostr,
}
// 获取MasterID数组
masterIDs := config.GetMasterID()

// 判断userid64是否在masterIDs数组里
isMaster := false
for _, id := range masterIDs {
if strconv.FormatInt(userid64, 10) == id {
isMaster = true
break
}
}

// 根据isMaster的值为groupMsg的Sender赋值role字段
if isMaster {
onebotMsg.Sender.Role = "owner"
} else {
onebotMsg.Sender.Role = "member"
}
//将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "guild")
Expand Down Expand Up @@ -143,6 +160,24 @@ func (p *Processor) ProcessGuildATMessage(data *dto.WSATMessageData) error {
Avatar: data.Author.Avatar,
Echo: echostr,
}
// 获取MasterID数组
masterIDs := config.GetMasterID()

// 判断userid64是否在masterIDs数组里
isMaster := false
for _, id := range masterIDs {
if strconv.FormatInt(userid64, 10) == id {
isMaster = true
break
}
}

// 根据isMaster的值为groupMsg的Sender赋值role字段
if isMaster {
groupMsg.Sender.Role = "owner"
} else {
groupMsg.Sender.Role = "member"
}
//将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "guild")
Expand Down
35 changes: 35 additions & 0 deletions Processor/ProcessGuildNormalMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,24 @@ func (p *Processor) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
Avatar: data.Author.Avatar,
Echo: echostr,
}
// 获取MasterID数组
masterIDs := config.GetMasterID()

// 判断userid64是否在masterIDs数组里
isMaster := false
for _, id := range masterIDs {
if strconv.FormatInt(userid64, 10) == id {
isMaster = true
break
}
}

// 根据isMaster的值为groupMsg的Sender赋值role字段
if isMaster {
onebotMsg.Sender.Role = "owner"
} else {
onebotMsg.Sender.Role = "member"
}
//将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "guild")
Expand Down Expand Up @@ -142,6 +159,24 @@ func (p *Processor) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
Avatar: data.Author.Avatar,
Echo: echostr,
}
// 获取MasterID数组
masterIDs := config.GetMasterID()

// 判断userid64是否在masterIDs数组里
isMaster := false
for _, id := range masterIDs {
if strconv.FormatInt(userid64, 10) == id {
isMaster = true
break
}
}

// 根据isMaster的值为groupMsg的Sender赋值role字段
if isMaster {
groupMsg.Sender.Role = "owner"
} else {
groupMsg.Sender.Role = "member"
}
//将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
echo.AddMsgType(AppIDString, s, "guild")
Expand Down
1 change: 1 addition & 0 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Sender struct {
Nickname string `json:"nickname"`
TinyID string `json:"tiny_id"`
UserID int64 `json:"user_id"`
Role string `json:"role,omitempty"`
}

// 频道信息事件
Expand Down
2 changes: 1 addition & 1 deletion botgo/token/authtoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (atoken *AuthTokenInfo) StartRefreshAccessToken(ctx context.Context, tokenU
// func (atoken *AuthTokenInfo) StartRefreshAccessToken(ctx context.Context, tokenURL, appID, clientSecrent string) (err error) {
// // 创建一个固定的token信息
// fixedTokenInfo := AccessTokenInfo{
// Token: "PpAPgoel0-gTeaxy-ydak0kUKxJrCSlbLcwtuPt99jCPVrahkqh3WSiIy9s63tCZnTEp4asw035u",
// Token: "PyR4PL9_eRfAkIIlWE4nAawocFMlPfQCySgASB5vJRduWgKh0mSOp4zm4AOzDKpweV9iu5zq-OWm",
// ExpiresIn: 3600, // 这里假设token的有效时间是3600秒,你可以根据需要调整
// }
// atoken.setAuthToken(fixedTokenInfo)
Expand Down
2 changes: 1 addition & 1 deletion botgo/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (t *Token) GetAccessToken() string {
// GetAccessToken 取得测试鉴权Token
// func (t *Token) GetAccessToken() string {
// // 固定的token值
// return "PpAPgoel0-gTeaxy-ydak0kUKxJrCSlbLcwtuPt99jCPVrahkqh3WSiIy9s63tCZnTEp4asw035u"
// return "PyR4PL9_eRfAkIIlWE4nAawocFMlPfQCySgASB5vJRduWgKh0mSOp4zm4AOzDKpweV9iu5zq-OWm"
// }

// UpAccessToken 更新accessToken
Expand Down
26 changes: 26 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ type Settings struct {
Server_dir string `yaml:"server_dir"`
Lotus bool `yaml:"lotus"`
Port string `yaml:"port"`

// 连接wss时使用,不是wss可留空
WsToken string `yaml:"ws_token,omitempty"`

// 如果需要在群权限判断是管理员是,将user_id填入这里,master_id是一个文本数组
MasterID []string `yaml:"master_id,omitempty"`
}

// LoadConfig 从文件中加载配置并初始化单例配置
Expand Down Expand Up @@ -123,3 +129,23 @@ func GetAppID() uint64 {
}
return 0 // or whatever default value you'd like to return if instance is nil
}

// 获取WsToken
func GetWsToken() string {
mu.Lock()
defer mu.Unlock()
if instance != nil {
return instance.Settings.WsToken
}
return "" // 返回空字符串,如果instance为nil
}

// 获取MasterID数组
func GetMasterID() []string {
mu.Lock()
defer mu.Unlock()
if instance != nil {
return instance.Settings.MasterID
}
return nil // 返回nil,如果instance为nil
}
2 changes: 2 additions & 0 deletions config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ settings:
lotus: false # lotus特性默认为false,当为true时,将会连接到另一个lotus为false的gensokyo。
# 使用它提供的图床和idmaps服务(场景:同一个机器人在不同服务器运行,或内网需要发送base64图)。
# 如果需要发送base64图片,需要设置正确的公网server_dir和开放对应的port
ws_token: "" #连接wss地址时服务器所需的token,如果是ws,可留空
master_id : ["1","2"] #群场景尚未开放获取管理员和列表能力,手动从日志中获取需要设置为管理,的user_id并填入(适用插件有权限判断场景)
`
4 changes: 3 additions & 1 deletion config_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ settings:
port: "<YOUR_PORT>" # idmaps和图床对外开放的端口号
lotus: false # lotus特性默认为false,当为true时,将会连接到另一个lotus为false的gensokyo。
# 使用它提供的图床和idmaps服务(场景:同一个机器人在不同服务器运行,或内网需要发送base64图)。
# 如果需要发送base64图片,需要设置正确的公网server_dir和开放对应的port
# 如果需要发送base64图片,需要设置正确的公网server_dir和开放对应的port
ws_token: "" #连接wss地址时服务器所需的token,如果是ws,可留空
master_id : ["1","2"] #群场景尚未开放获取管理员和列表能力,手动从日志中获取需要设置为管理,的user_id并填入(适用插件有权限判断场景)
20 changes: 13 additions & 7 deletions handlers/get_group_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ type OnebotGroupInfo struct {
MaxMemberCount int32 `json:"max_member_count"`
}

func ConvertGuildToGroupInfo(guild *dto.Guild) *OnebotGroupInfo {
groupID, err := strconv.ParseInt(guild.ID, 10, 64)
func ConvertGuildToGroupInfo(guild *dto.Guild, GroupId string) *OnebotGroupInfo {
groupidstr, err := strconv.ParseInt(GroupId, 10, 64)
if err != nil {
log.Printf("转换ID失败: %v", err)
log.Printf("groupidstr: %v", err)
return nil
}

ts, err := guild.JoinedAt.Time()
if err != nil {
log.Printf("转换JoinedAt失败: %v", err)
Expand All @@ -42,7 +41,7 @@ func ConvertGuildToGroupInfo(guild *dto.Guild) *OnebotGroupInfo {
groupCreateTime := uint32(ts.Unix())

return &OnebotGroupInfo{
GroupID: groupID,
GroupID: groupidstr,
GroupName: guild.Name,
GroupMemo: guild.Desc,
GroupCreateTime: groupCreateTime,
Expand Down Expand Up @@ -71,8 +70,15 @@ func handleGetGroupInfo(client callapi.Client, api openapi.OpenAPI, apiv2 openap
log.Printf("获取频道信息失败: %v", err)
return
}

groupInfo := ConvertGuildToGroupInfo(guild)
//用group_id还原出channelid 这是虚拟成群的私聊信息
message.Params.ChannelID = message.Params.GroupID.(string)
//读取ini 通过ChannelID取回之前储存的guild_id
GroupId, err := idmap.ReadConfigv2(message.Params.ChannelID, "guild_id")
if err != nil {
log.Printf("Error reading config: %v", err)
return
}
groupInfo := ConvertGuildToGroupInfo(guild, GroupId)

groupInfoMap := structToMap(groupInfo)

Expand Down
Loading