diff --git a/coolq/api.go b/coolq/api.go index db2b339..98a7c86 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -21,19 +21,19 @@ import ( "github.com/tidwall/gjson" ) -//Version go-cqhttp的版本信息,在编译时使用ldfalgs进行覆盖 +// Version go-cqhttp的版本信息,在编译时使用ldfalgs进行覆盖 var Version = "unknown" -//CQGetLoginInfo : 获取登录号信息 +// CQGetLoginInfo 获取登录号信息 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_login_info-%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E5%8F%B7%E4%BF%A1%E6%81%AF +// https://git.io/Jtz1I func (bot *CQBot) CQGetLoginInfo() MSG { return OK(MSG{"user_id": bot.Client.Uin, "nickname": bot.Client.Nickname}) } -//CQGetFriendList : 获取好友列表 +// CQGetFriendList 获取好友列表 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_friend_list-%E8%8E%B7%E5%8F%96%E5%A5%BD%E5%8F%8B%E5%88%97%E8%A1%A8 +// https://git.io/Jtz1L func (bot *CQBot) CQGetFriendList() MSG { fs := make([]MSG, 0) for _, f := range bot.Client.FriendList { @@ -46,9 +46,9 @@ func (bot *CQBot) CQGetFriendList() MSG { return OK(fs) } -//CQGetGroupList : 获取群列表 +// CQGetGroupList 获取群列表 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%88%97%E8%A1%A8 +// https://git.io/Jtz1t func (bot *CQBot) CQGetGroupList(noCache bool) MSG { gs := make([]MSG, 0) if noCache { @@ -65,9 +65,9 @@ func (bot *CQBot) CQGetGroupList(noCache bool) MSG { return OK(gs) } -//CQGetGroupInfo : 获取群信息 +// CQGetGroupInfo 获取群信息 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E4%BF%A1%E6%81%AF +// https://git.io/Jtz1O func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) MSG { group := bot.Client.FindGroup(groupID) if group == nil { @@ -103,9 +103,9 @@ func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) MSG { }) } -//CQGetGroupMemberList : 获取群成员列表 +// CQGetGroupMemberList 获取群成员列表 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_member_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E5%88%97%E8%A1%A8 +// https://git.io/Jtz13 func (bot *CQBot) CQGetGroupMemberList(groupID int64, noCache bool) MSG { group := bot.Client.FindGroup(groupID) if group == nil { @@ -126,9 +126,9 @@ func (bot *CQBot) CQGetGroupMemberList(groupID int64, noCache bool) MSG { return OK(members) } -//CQGetGroupMemberInfo : 获取群成员信息 +// CQGetGroupMemberInfo 获取群成员信息 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_member_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E4%BF%A1%E6%81%AF +// https://git.io/Jtz1s func (bot *CQBot) CQGetGroupMemberInfo(groupID, userID int64) MSG { group := bot.Client.FindGroup(groupID) if group == nil { @@ -141,9 +141,9 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupID, userID int64) MSG { return OK(convertGroupMemberInfo(groupID, member)) } -//CQGetGroupFileSystemInfo : 扩展API-获取群文件系统信息 +// CQGetGroupFileSystemInfo 扩展API-获取群文件系统信息 // -//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E4%BF%A1%E6%81%AF +// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E4%BF%A1%E6%81%AF func (bot *CQBot) CQGetGroupFileSystemInfo(groupID int64) MSG { fs, err := bot.Client.GetGroupFileSystem(groupID) if err != nil { @@ -153,9 +153,9 @@ func (bot *CQBot) CQGetGroupFileSystemInfo(groupID int64) MSG { return OK(fs) } -//CQGetGroupRootFiles : 扩展API-获取群根目录文件列表 +// CQGetGroupRootFiles 扩展API-获取群根目录文件列表 // -//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%A0%B9%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8 +// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%A0%B9%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8 func (bot *CQBot) CQGetGroupRootFiles(groupID int64) MSG { fs, err := bot.Client.GetGroupFileSystem(groupID) if err != nil { @@ -173,9 +173,9 @@ func (bot *CQBot) CQGetGroupRootFiles(groupID int64) MSG { }) } -//CQGetGroupFilesByFolderID : 扩展API-获取群子目录文件列表 +// CQGetGroupFilesByFolderID 扩展API-获取群子目录文件列表 // -//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%AD%90%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8 +// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%AD%90%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8 func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) MSG { fs, err := bot.Client.GetGroupFileSystem(groupID) if err != nil { @@ -193,9 +193,9 @@ func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) MSG }) } -//CQGetGroupFileURL : 扩展API-获取群文件资源链接 +// CQGetGroupFileURL 扩展API-获取群文件资源链接 // -//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E8%B5%84%E6%BA%90%E9%93%BE%E6%8E%A5 +// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E8%B5%84%E6%BA%90%E9%93%BE%E6%8E%A5 func (bot *CQBot) CQGetGroupFileURL(groupID int64, fileID string, busID int32) MSG { url := bot.Client.GetGroupFileUrl(groupID, fileID, busID) if url == "" { @@ -206,9 +206,9 @@ func (bot *CQBot) CQGetGroupFileURL(groupID int64, fileID string, busID int32) M }) } -//CQGetWordSlices : 隐藏API-获取中文分词 +// CQGetWordSlices 隐藏API-获取中文分词 // -//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E4%B8%AD%E6%96%87%E5%88%86%E8%AF%8D-%E9%9A%90%E8%97%8F-api +// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E4%B8%AD%E6%96%87%E5%88%86%E8%AF%8D-%E9%9A%90%E8%97%8F-api func (bot *CQBot) CQGetWordSlices(content string) MSG { slices, err := bot.Client.GetWordSegmentation(content) if err != nil { @@ -220,9 +220,9 @@ func (bot *CQBot) CQGetWordSlices(content string) MSG { return OK(MSG{"slices": slices}) } -//CQSendGroupMessage : 发送群消息 +// CQSendGroupMessage 发送群消息 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF +// https://git.io/Jtz1c func (bot *CQBot) CQSendGroupMessage(groupID int64, i interface{}, autoEscape bool) MSG { var str string fixAt := func(elem []message.IMessageElement) { @@ -277,9 +277,9 @@ func (bot *CQBot) CQSendGroupMessage(groupID int64, i interface{}, autoEscape bo return OK(MSG{"message_id": mid}) } -//CQSendGroupForwardMessage : 扩展API-发送合并转发(群) +// CQSendGroupForwardMessage 扩展API-发送合并转发(群) // -//https://docs.go-cqhttp.org/api/#%E5%8F%91%E9%80%81%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91-%E7%BE%A4 +// https://docs.go-cqhttp.org/api/#%E5%8F%91%E9%80%81%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91-%E7%BE%A4 func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG { if m.Type != gjson.JSON { return Failed(100) @@ -403,9 +403,9 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG { return Failed(100) } -//CQSendPrivateMessage : 发送私聊消息 +// CQSendPrivateMessage 发送私聊消息 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF +// https://git.io/Jtz1l func (bot *CQBot) CQSendPrivateMessage(userID int64, i interface{}, autoEscape bool) MSG { var str string if m, ok := i.(gjson.Result); ok { @@ -444,9 +444,9 @@ func (bot *CQBot) CQSendPrivateMessage(userID int64, i interface{}, autoEscape b return OK(MSG{"message_id": mid}) } -//CQSetGroupCard : 设置群名片(群备注) +// CQSetGroupCard 设置群名片(群备注) // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_card-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D%E7%89%87%E7%BE%A4%E5%A4%87%E6%B3%A8 +// https://git.io/Jtz1B func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) MSG { if g := bot.Client.FindGroup(groupID); g != nil { if m := g.FindMember(userID); m != nil { @@ -457,9 +457,9 @@ func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) MSG { return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } -//CQSetGroupSpecialTitle : 设置群组专属头衔 +// CQSetGroupSpecialTitle 设置群组专属头衔 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_special_title-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E7%BB%84%E4%B8%93%E5%B1%9E%E5%A4%B4%E8%A1%94 +// https://git.io/Jtz10 func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) MSG { if g := bot.Client.FindGroup(groupID); g != nil { if m := g.FindMember(userID); m != nil { @@ -470,9 +470,9 @@ func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) MS return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } -//CQSetGroupName : 设置群名 +// CQSetGroupName 设置群名 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_name-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D +// https://git.io/Jtz12 func (bot *CQBot) CQSetGroupName(groupID int64, name string) MSG { if g := bot.Client.FindGroup(groupID); g != nil { g.UpdateName(name) @@ -481,9 +481,9 @@ func (bot *CQBot) CQSetGroupName(groupID int64, name string) MSG { return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } -//CQSetGroupMemo : 扩展API-发送群公告 +// CQSetGroupMemo 扩展API-发送群公告 // -//https://docs.go-cqhttp.org/api/#%E5%8F%91%E9%80%81%E7%BE%A4%E5%85%AC%E5%91%8A +// https://docs.go-cqhttp.org/api/#%E5%8F%91%E9%80%81%E7%BE%A4%E5%85%AC%E5%91%8A func (bot *CQBot) CQSetGroupMemo(groupID int64, msg string) MSG { if g := bot.Client.FindGroup(groupID); g != nil { g.UpdateMemo(msg) @@ -492,9 +492,9 @@ func (bot *CQBot) CQSetGroupMemo(groupID int64, msg string) MSG { return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } -//CQSetGroupKick : 群组踢人 +// CQSetGroupKick 群组踢人 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_kick-%E7%BE%A4%E7%BB%84%E8%B8%A2%E4%BA%BA +// https://git.io/Jtz1V func (bot *CQBot) CQSetGroupKick(groupID, userID int64, msg string, block bool) MSG { if g := bot.Client.FindGroup(groupID); g != nil { if m := g.FindMember(userID); m != nil { @@ -505,9 +505,9 @@ func (bot *CQBot) CQSetGroupKick(groupID, userID int64, msg string, block bool) return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } -//CQSetGroupBan : 群组单人禁言 +// CQSetGroupBan 群组单人禁言 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_ban-%E7%BE%A4%E7%BB%84%E5%8D%95%E4%BA%BA%E7%A6%81%E8%A8%80 +// https://git.io/Jtz1w func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) MSG { if g := bot.Client.FindGroup(groupID); g != nil { if m := g.FindMember(userID); m != nil { @@ -518,9 +518,9 @@ func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) MSG { return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } -//CQSetGroupWholeBan : 群组全员禁言 +// CQSetGroupWholeBan 群组全员禁言 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_whole_ban-%E7%BE%A4%E7%BB%84%E5%85%A8%E5%91%98%E7%A6%81%E8%A8%80 +// https://git.io/Jtz1o func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) MSG { if g := bot.Client.FindGroup(groupID); g != nil { g.MuteAll(enable) @@ -529,9 +529,9 @@ func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) MSG { return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } -//CQSetGroupLeave : 退出群组 +// CQSetGroupLeave 退出群组 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_leave-%E9%80%80%E5%87%BA%E7%BE%A4%E7%BB%84 +// https://git.io/Jtz1K func (bot *CQBot) CQSetGroupLeave(groupID int64) MSG { if g := bot.Client.FindGroup(groupID); g != nil { g.Quit() @@ -540,9 +540,9 @@ func (bot *CQBot) CQSetGroupLeave(groupID int64) MSG { return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } -//CQGetAtAllRemain : 扩展API-获取群 @全体成员 剩余次数 +// CQGetAtAllRemain 扩展API-获取群 @全体成员 剩余次数 // -//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4-%E5%85%A8%E4%BD%93%E6%88%90%E5%91%98-%E5%89%A9%E4%BD%99%E6%AC%A1%E6%95%B0 +// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4-%E5%85%A8%E4%BD%93%E6%88%90%E5%91%98-%E5%89%A9%E4%BD%99%E6%AC%A1%E6%95%B0 func (bot *CQBot) CQGetAtAllRemain(groupID int64) MSG { if g := bot.Client.FindGroup(groupID); g != nil { i, err := bot.Client.GetAtAllRemain(groupID) @@ -554,9 +554,9 @@ func (bot *CQBot) CQGetAtAllRemain(groupID int64) MSG { return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } -//CQProcessFriendRequest : 处理加好友请求 +// CQProcessFriendRequest 处理加好友请求 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_friend_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82 +// https://git.io/Jtz11 func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG { req, ok := bot.friendReqCache.Load(flag) if !ok { @@ -570,9 +570,9 @@ func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG { return OK(nil) } -//CQProcessGroupRequest : 处理加群请求/邀请 +// CQProcessGroupRequest 处理加群请求/邀请 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82%E9%82%80%E8%AF%B7 +// https://git.io/Jtz1D func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bool) MSG { msgs, err := bot.Client.GetGroupSystemMessages() if err != nil { @@ -614,9 +614,9 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo return Failed(100, "FLAG_NOT_FOUND", "FLAG不存在") } -//CQDeleteMessage : 撤回消息 +// CQDeleteMessage 撤回消息 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#delete_msg-%E6%92%A4%E5%9B%9E%E6%B6%88%E6%81%AF +// https:// git.io/Jtz1y func (bot *CQBot) CQDeleteMessage(messageID int32) MSG { msg := bot.GetMessage(messageID) if msg == nil { @@ -640,9 +640,9 @@ func (bot *CQBot) CQDeleteMessage(messageID int32) MSG { return OK(nil) } -//CQSetGroupAdmin : 群组设置管理员 +// CQSetGroupAdmin 群组设置管理员 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_admin-%E7%BE%A4%E7%BB%84%E8%AE%BE%E7%BD%AE%E7%AE%A1%E7%90%86%E5%91%98 +// https://git.io/Jtz1S func (bot *CQBot) CQSetGroupAdmin(groupID, userID int64, enable bool) MSG { group := bot.Client.FindGroup(groupID) if group == nil || group.OwnerUin != bot.Client.Uin { @@ -662,9 +662,9 @@ func (bot *CQBot) CQSetGroupAdmin(groupID, userID int64, enable bool) MSG { return OK(nil) } -//CQGetVipInfo : 扩展API-获取VIP信息 +// CQGetVipInfo 扩展API-获取VIP信息 // -//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96vip%E4%BF%A1%E6%81%AF +// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96vip%E4%BF%A1%E6%81%AF func (bot *CQBot) CQGetVipInfo(userID int64) MSG { vip, err := bot.Client.GetVipInfo(userID) if err != nil { @@ -682,9 +682,9 @@ func (bot *CQBot) CQGetVipInfo(userID int64) MSG { return OK(msg) } -//CQGetGroupHonorInfo : 获取群荣誉信息 +// CQGetGroupHonorInfo 获取群荣誉信息 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_honor_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E8%8D%A3%E8%AA%89%E4%BF%A1%E6%81%AF +// https://git.io/Jtz1H func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) MSG { msg := MSG{"group_id": groupID} convertMem := func(memList []client.HonorMemberInfo) (ret []MSG) { @@ -739,9 +739,9 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) MSG { return OK(msg) } -//CQGetStrangerInfo : 获取陌生人信息 +// CQGetStrangerInfo 获取陌生人信息 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_stranger_info-%E8%8E%B7%E5%8F%96%E9%99%8C%E7%94%9F%E4%BA%BA%E4%BF%A1%E6%81%AF +// https://git.io/Jtz17 func (bot *CQBot) CQGetStrangerInfo(userID int64) MSG { info, err := bot.Client.GetSummaryInfo(userID) if err != nil { @@ -766,9 +766,9 @@ func (bot *CQBot) CQGetStrangerInfo(userID int64) MSG { }) } -//CQHandleQuickOperation : 隐藏API-对事件执行快速操作 +// CQHandleQuickOperation 隐藏API-对事件执行快速操作 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/hidden.md#handle_quick_operation-%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%89%A7%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%93%8D%E4%BD%9C +// https://git.io/Jtz15 func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG { postType := context.Get("post_type").Str switch postType { @@ -825,9 +825,9 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG { return OK(nil) } -//CQGetImage : 获取图片(修改自OneBot) +// CQGetImage 获取图片(修改自OneBot) // -//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E5%9B%BE%E7%89%87%E4%BF%A1%E6%81%AF +// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E5%9B%BE%E7%89%87%E4%BF%A1%E6%81%AF func (bot *CQBot) CQGetImage(file string) MSG { if !global.PathExists(path.Join(global.ImagePath, file)) { return Failed(100) @@ -853,7 +853,7 @@ func (bot *CQBot) CQGetImage(file string) MSG { return Failed(100, "LOAD_FILE_ERROR", err.Error()) } -//CQDownloadFile : 使用给定threadCount和给定headers下载给定url +// CQDownloadFile 使用给定threadCount和给定headers下载给定url func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCount int) MSG { hash := md5.Sum([]byte(url)) file := path.Join(global.CachePath, hex.EncodeToString(hash[:])+".cache") @@ -873,9 +873,9 @@ func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCo }) } -//CQGetForwardMessage : 获取合并转发消息 +// CQGetForwardMessage 获取合并转发消息 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_forward_msg-%E8%8E%B7%E5%8F%96%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91%E6%B6%88%E6%81%AF +// https://git.io/Jtz1F func (bot *CQBot) CQGetForwardMessage(resID string) MSG { m := bot.Client.GetForwardMessage(resID) if m == nil { @@ -898,9 +898,9 @@ func (bot *CQBot) CQGetForwardMessage(resID string) MSG { }) } -//CQGetMessage : 获取消息 +// CQGetMessage 获取消息 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_msg-%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF +// https://git.io/Jtz1b func (bot *CQBot) CQGetMessage(messageID int32) MSG { msg := bot.GetMessage(messageID) if msg == nil { @@ -936,9 +936,9 @@ func (bot *CQBot) CQGetMessage(messageID int32) MSG { }) } -//CQGetGroupSystemMessages : 扩展API-获取群文件系统消息 +// CQGetGroupSystemMessages 扩展API-获取群文件系统消息 // -//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E7%B3%BB%E7%BB%9F%E6%B6%88%E6%81%AF +// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E7%B3%BB%E7%BB%9F%E6%B6%88%E6%81%AF func (bot *CQBot) CQGetGroupSystemMessages() MSG { msg, err := bot.Client.GetGroupSystemMessages() if err != nil { @@ -948,9 +948,9 @@ func (bot *CQBot) CQGetGroupSystemMessages() MSG { return OK(msg) } -//CQGetGroupMessageHistory : 获取群消息历史记录 +// CQGetGroupMessageHistory 获取群消息历史记录 // -//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%B6%88%E6%81%AF%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95 +// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%B6%88%E6%81%AF%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95 func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) MSG { if g := bot.Client.FindGroup(groupID); g == nil { return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") @@ -983,9 +983,9 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) MSG { }) } -//CQGetOnlineClients : 扩展API-获取当前账号在线客户端列表 +// CQGetOnlineClients 扩展API-获取当前账号在线客户端列表 // -//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E8%B4%A6%E5%8F%B7%E5%9C%A8%E7%BA%BF%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%88%97%E8%A1%A8 +// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E8%B4%A6%E5%8F%B7%E5%9C%A8%E7%BA%BF%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%88%97%E8%A1%A8 func (bot *CQBot) CQGetOnlineClients(noCache bool) MSG { if noCache { if err := bot.Client.RefreshStatus(); err != nil { @@ -1006,23 +1006,23 @@ func (bot *CQBot) CQGetOnlineClients(noCache bool) MSG { }) } -//CQCanSendImage : 检查是否可以发送图片(此处永远返回true) +// CQCanSendImage 检查是否可以发送图片(此处永远返回true) // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#can_send_image-%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%91%E9%80%81%E5%9B%BE%E7%89%87 +// https://git.io/Jtz1N func (bot *CQBot) CQCanSendImage() MSG { return OK(MSG{"yes": true}) } -//CQCanSendRecord : 检查是否可以发送语音(此处永远返回true) +// CQCanSendRecord 检查是否可以发送语音(此处永远返回true) // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#can_send_record-%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%91%E9%80%81%E8%AF%AD%E9%9F%B3 +// https://git.io/Jtz1x func (bot *CQBot) CQCanSendRecord() MSG { return OK(MSG{"yes": true}) } -//CQOcrImage : 扩展API-图片OCR +// CQOcrImage 扩展API-图片OCR // -//https://docs.go-cqhttp.org/api/#%E5%9B%BE%E7%89%87-ocr +// https://docs.go-cqhttp.org/api/#%E5%9B%BE%E7%89%87-ocr func (bot *CQBot) CQOcrImage(imageID string) MSG { img, err := bot.makeImageOrVideoElem(map[string]string{"file": imageID}, false, true) if err != nil { @@ -1037,17 +1037,17 @@ func (bot *CQBot) CQOcrImage(imageID string) MSG { return OK(rsp) } -//CQReloadEventFilter : 扩展API-重载事件过滤器 +// CQReloadEventFilter 扩展API-重载事件过滤器 // -//https://docs.go-cqhttp.org/api/#%E9%87%8D%E8%BD%BD%E4%BA%8B%E4%BB%B6%E8%BF%87%E6%BB%A4%E5%99%A8 +// https://docs.go-cqhttp.org/api/#%E9%87%8D%E8%BD%BD%E4%BA%8B%E4%BB%B6%E8%BF%87%E6%BB%A4%E5%99%A8 func (bot *CQBot) CQReloadEventFilter() MSG { global.BootFilter() return OK(nil) } -//CQSetGroupPortrait : 扩展API-设置群头像 +// CQSetGroupPortrait 扩展API-设置群头像 // -//https://docs.go-cqhttp.org/api/#%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%A4%B4%E5%83%8F +// https://docs.go-cqhttp.org/api/#%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%A4%B4%E5%83%8F func (bot *CQBot) CQSetGroupPortrait(groupID int64, file, cache string) MSG { if g := bot.Client.FindGroup(groupID); g != nil { img, err := global.FindFile(file, cache, global.ImagePath) @@ -1061,9 +1061,9 @@ func (bot *CQBot) CQSetGroupPortrait(groupID int64, file, cache string) MSG { return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } -//CQSetGroupAnonymousBan : 群组匿名用户禁言 +// CQSetGroupAnonymousBan 群组匿名用户禁言 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_anonymous_ban-%E7%BE%A4%E7%BB%84%E5%8C%BF%E5%90%8D%E7%94%A8%E6%88%B7%E7%A6%81%E8%A8%80 +// https://git.io/Jtz1p func (bot *CQBot) CQSetGroupAnonymousBan(groupID int64, flag string, duration int32) MSG { if flag == "" { return Failed(100, "INVALID_FLAG", "无效的flag") @@ -1084,9 +1084,9 @@ func (bot *CQBot) CQSetGroupAnonymousBan(groupID int64, flag string, duration in return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") } -//CQGetStatus : 获取运行状态 +// CQGetStatus 获取运行状态 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_status-%E8%8E%B7%E5%8F%96%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81 +// https://git.io/JtzMe func (bot *CQBot) CQGetStatus() MSG { return OK(MSG{ "app_initialized": true, @@ -1100,6 +1100,8 @@ func (bot *CQBot) CQGetStatus() MSG { } // CQSetEssenceMessage 设置精华消息 +// +// func (bot *CQBot) CQSetEssenceMessage(messageID int32) MSG { msg := bot.GetMessage(messageID) if msg == nil { @@ -1118,6 +1120,8 @@ func (bot *CQBot) CQSetEssenceMessage(messageID int32) MSG { } // CQDeleteEssenceMessage 移出精华消息 +// +// func (bot *CQBot) CQDeleteEssenceMessage(messageID int32) MSG { msg := bot.GetMessage(messageID) if msg == nil { @@ -1136,6 +1140,8 @@ func (bot *CQBot) CQDeleteEssenceMessage(messageID int32) MSG { } // CQGetEssenceMessageList 获取精华消息列表 +// +// func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) MSG { g := bot.Client.FindGroup(groupCode) if g == nil { @@ -1161,9 +1167,9 @@ func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) MSG { return OK(list) } -//CQGetVersionInfo : 获取版本信息 +// CQGetVersionInfo 获取版本信息 // -//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_version_info-%E8%8E%B7%E5%8F%96%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF +// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_version_info-%E8%8E%B7%E5%8F%96%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF func (bot *CQBot) CQGetVersionInfo() MSG { wd, _ := os.Getwd() return OK(MSG{ @@ -1193,12 +1199,12 @@ func (bot *CQBot) CQGetVersionInfo() MSG { }) } -//OK 生成成功返回值 +// OK 生成成功返回值 func OK(data interface{}) MSG { return MSG{"data": data, "retcode": 0, "status": "ok"} } -//Failed 生成失败返回值 +// Failed 生成失败返回值 func Failed(code int, msg ...string) MSG { m := "" w := "" diff --git a/coolq/bot.go b/coolq/bot.go index 191626e..6930e40 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -28,7 +28,7 @@ import ( var json = jsoniter.ConfigCompatibleWithStandardLibrary -//CQBot CQBot结构体,存储Bot实例相关配置 +// CQBot CQBot结构体,存储Bot实例相关配置 type CQBot struct { Client *client.QQClient @@ -39,13 +39,13 @@ type CQBot struct { oneWayMsgCache sync.Map } -//MSG 消息Map +// MSG 消息Map type MSG map[string]interface{} -//ForceFragmented 是否启用强制分片 +// ForceFragmented 是否启用强制分片 var ForceFragmented = false -//NewQQBot 初始化一个QQBot实例 +// NewQQBot 初始化一个QQBot实例 func NewQQBot(cli *client.QQClient, conf *global.JSONConfig) *CQBot { bot := &CQBot{ Client: cli, @@ -107,12 +107,12 @@ func NewQQBot(cli *client.QQClient, conf *global.JSONConfig) *CQBot { return bot } -//OnEventPush 注册事件上报函数 +// OnEventPush 注册事件上报函数 func (bot *CQBot) OnEventPush(f func(m MSG)) { bot.events = append(bot.events, f) } -//GetMessage 获取给定消息id对应的消息 +// GetMessage 获取给定消息id对应的消息 func (bot *CQBot) GetMessage(mid int32) MSG { if bot.db != nil { m := MSG{} @@ -130,7 +130,7 @@ func (bot *CQBot) GetMessage(mid int32) MSG { return nil } -//UploadLocalImageAsGroup 上传本地图片至群聊 +// UploadLocalImageAsGroup 上传本地图片至群聊 func (bot *CQBot) UploadLocalImageAsGroup(groupCode int64, img *LocalImageElement) (*message.GroupImageElement, error) { if img.Stream != nil { return bot.Client.UploadGroupImage(groupCode, img.Stream) @@ -138,7 +138,7 @@ func (bot *CQBot) UploadLocalImageAsGroup(groupCode int64, img *LocalImageElemen return bot.Client.UploadGroupImageByFile(groupCode, img.File) } -//UploadLocalVideo 上传本地短视频至群聊 +// UploadLocalVideo 上传本地短视频至群聊 func (bot *CQBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message.ShortVideoElement, error) { if v.File != "" { video, err := os.Open(v.File) @@ -155,7 +155,7 @@ func (bot *CQBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message return &v.ShortVideoElement, nil } -//UploadLocalImageAsPrivate 上传本地图片至私聊 +// UploadLocalImageAsPrivate 上传本地图片至私聊 func (bot *CQBot) UploadLocalImageAsPrivate(userID int64, img *LocalImageElement) (*message.FriendImageElement, error) { if img.Stream != nil { return bot.Client.UploadPrivateImage(userID, img.Stream) @@ -169,7 +169,7 @@ func (bot *CQBot) UploadLocalImageAsPrivate(userID int64, img *LocalImageElement return bot.Client.UploadPrivateImage(userID, f) } -//SendGroupMessage 发送群消息 +// SendGroupMessage 发送群消息 func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) int32 { var newElem []message.IMessageElement for _, elem := range m.Elements { @@ -236,7 +236,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) int return bot.InsertGroupMessage(ret) } -//SendPrivateMessage 发送私聊消息 +// SendPrivateMessage 发送私聊消息 func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) int32 { var newElem []message.IMessageElement for _, elem := range m.Elements { @@ -306,7 +306,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in return id } -//InsertGroupMessage 群聊消息入数据库 +// InsertGroupMessage 群聊消息入数据库 func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 { val := MSG{ "message-id": m.Id, @@ -332,7 +332,7 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 { return id } -//InsertPrivateMessage 私聊消息入数据库 +// InsertPrivateMessage 私聊消息入数据库 func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 { val := MSG{ "message-id": m.Id, @@ -357,12 +357,12 @@ func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 { return id } -//toGlobalID 构建`code`-`msgID`的字符串并返回其CRC32 Checksum的值 +// toGlobalID 构建`code`-`msgID`的字符串并返回其CRC32 Checksum的值 func toGlobalID(code int64, msgID int32) int32 { return int32(crc32.ChecksumIEEE([]byte(fmt.Sprintf("%d-%d", code, msgID)))) } -//Release 释放Bot实例 +// Release 释放Bot实例 func (bot *CQBot) Release() { if bot.db != nil { _ = bot.db.Close() @@ -453,7 +453,7 @@ func formatMemberName(mem *client.GroupMemberInfo) string { return fmt.Sprintf("%s(%d)", mem.DisplayName(), mem.Uin) } -//ToJSON 生成JSON字符串 +// ToJSON 生成JSON字符串 func (m MSG) ToJSON() string { b, _ := json.Marshal(m) return string(b) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 7712ef5..2a02a51 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -34,52 +34,52 @@ var typeReg = regexp.MustCompile(`\[CQ:(\w+)`) var paramReg = regexp.MustCompile(`,([\w\-.]+?)=([^,\]]+)`) */ -//IgnoreInvalidCQCode 是否忽略无效CQ码 +// IgnoreInvalidCQCode 是否忽略无效CQ码 var IgnoreInvalidCQCode = false -//SplitURL 是否分割URL +// SplitURL 是否分割URL var SplitURL = false const maxImageSize = 1024 * 1024 * 30 // 30MB const maxVideoSize = 1024 * 1024 * 100 // 100MB -//PokeElement 拍一拍 +// PokeElement 拍一拍 type PokeElement struct { Target int64 } -//GiftElement 礼物 +// GiftElement 礼物 type GiftElement struct { Target int64 GiftID message.GroupGift } -//LocalImageElement 本地图片 +// LocalImageElement 本地图片 type LocalImageElement struct { message.ImageElement Stream io.ReadSeeker File string } -//LocalVoiceElement 本地语音 +// LocalVoiceElement 本地语音 type LocalVoiceElement struct { message.VoiceElement Stream io.ReadSeeker } -//LocalVideoElement 本地视频 +// LocalVideoElement 本地视频 type LocalVideoElement struct { message.ShortVideoElement File string thumb io.ReadSeeker } -//Type 获取元素类型ID +// Type 获取元素类型ID func (e *GiftElement) Type() message.ElementType { - //Make message.IMessageElement Happy + // Make message.IMessageElement Happy return message.At } -//GiftID 礼物ID数组 +// GiftID 礼物ID数组 var GiftID = [...]message.GroupGift{ message.SweetWink, message.HappyCola, @@ -97,13 +97,13 @@ var GiftID = [...]message.GroupGift{ message.LoveMask, } -//Type 获取元素类型ID +// Type 获取元素类型ID func (e *PokeElement) Type() message.ElementType { - //Make message.IMessageElement Happy + // Make message.IMessageElement Happy return message.At } -//ToArrayMessage 将消息元素数组转为MSG数组以用于消息上报 +// ToArrayMessage 将消息元素数组转为MSG数组以用于消息上报 func ToArrayMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r []MSG) { r = []MSG{} ur := false @@ -130,10 +130,10 @@ func ToArrayMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r []M "data": map[string]string{"text": o.Content}, } case *message.LightAppElement: - //m = MSG{ - // "type": "text", - // "data": map[string]string{"text": o.Content}, - //} + // m = MSG{ + // "type": "text", + // "data": map[string]string{"text": o.Content}, + // } m = MSG{ "type": "json", "data": map[string]string{"data": o.Content}, @@ -255,7 +255,7 @@ func ToArrayMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r []M return } -//ToStringMessage 将消息元素数组转为字符串以用于消息上报 +// ToStringMessage 将消息元素数组转为字符串以用于消息上报 func ToStringMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r string) { ur := false if len(isRaw) != 0 { @@ -328,13 +328,13 @@ func ToStringMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r st } case *message.LightAppElement: r += fmt.Sprintf(`[CQ:json,data=%s]`, CQCodeEscapeValue(o.Content)) - //r += CQCodeEscapeText(o.Content) + // r += CQCodeEscapeText(o.Content) } } return } -//ConvertStringMessage 将消息字符串转为消息元素数组 +// ConvertStringMessage 将消息字符串转为消息元素数组 func (bot *CQBot) ConvertStringMessage(msg string, isGroup bool) (r []message.IMessageElement) { index := 0 stat := 0 @@ -491,7 +491,7 @@ func (bot *CQBot) ConvertStringMessage(msg string, isGroup bool) (r []message.IM return } -//ConvertObjectMessage 将消息JSON对象转为消息元素数组 +// ConvertObjectMessage 将消息JSON对象转为消息元素数组 func (bot *CQBot) ConvertObjectMessage(m gjson.Result, isGroup bool) (r []message.IMessageElement) { convertElem := func(e gjson.Result) { t := e.Get("type").Str @@ -782,11 +782,11 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte resID := d["resid"] i, _ := strconv.ParseInt(resID, 10, 64) if i == 0 { - //默认情况下走小程序通道 + // 默认情况下走小程序通道 msg := message.NewLightApp(CQCodeUnescapeValue(d["data"])) return msg, nil } - //resid不为0的情况下走富文本通道,后续补全透传service Id,此处暂时不处理 TODO + // resid不为0的情况下走富文本通道,后续补全透传service Id,此处暂时不处理 TODO msg := message.NewRichJson(CQCodeUnescapeValue(d["data"])) return msg, nil case "cardimage": @@ -866,7 +866,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte return nil, nil } -//XMLEscape 将字符串c转义为XML字符串 +// XMLEscape 将字符串c转义为XML字符串 func XMLEscape(c string) string { buf := new(bytes.Buffer) _ = xml2.EscapeText(buf, []byte(c)) @@ -929,7 +929,7 @@ func CQCodeUnescapeValue(content string) string { return ret } -//makeImageOrVideoElem 图片 elem 生成器,单独拎出来,用于公用 +// makeImageOrVideoElem 图片 elem 生成器,单独拎出来,用于公用 func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (message.IMessageElement, error) { f := d["file"] if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") { @@ -1089,7 +1089,7 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) ( return nil, errors.New("invalid image") } -//makeShowPic 一种xml 方式发送的群消息图片 +// makeShowPic 一种xml 方式发送的群消息图片 func (bot *CQBot) makeShowPic(elem message.IMessageElement, source string, icon string, minWidth int64, minHeight int64, maxWidth int64, maxHeight int64, group bool) ([]message.IMessageElement, error) { xml := "" var suf message.IMessageElement @@ -1122,7 +1122,7 @@ func (bot *CQBot) makeShowPic(elem message.IMessageElement, source string, icon suf = i } if xml != "" { - //log.Warn(xml) + // log.Warn(xml) ret := []message.IMessageElement{suf} ret = append(ret, message.NewRichXml(xml, 5)) return ret, nil diff --git a/coolq/doc.go b/coolq/doc.go index 66c9407..b6b63cf 100644 --- a/coolq/doc.go +++ b/coolq/doc.go @@ -1,2 +1,2 @@ -//Package coolq 包含CQBot实例,CQ码处理,消息发送,消息处理等的相关函数与结构体 +// Package coolq 包含CQBot实例,CQ码处理,消息发送,消息处理等的相关函数与结构体 package coolq diff --git a/coolq/event.go b/coolq/event.go index 5c050eb..55872c1 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -17,12 +17,12 @@ import ( var format = "string" -//SetMessageFormat 设置消息上报格式,默认为string +// SetMessageFormat 设置消息上报格式,默认为string func SetMessageFormat(f string) { format = f } -//ToFormattedMessage 将给定[]message.IMessageElement转换为通过coolq.SetMessageFormat所定义的消息上报格式 +// ToFormattedMessage 将给定[]message.IMessageElement转换为通过coolq.SetMessageFormat所定义的消息上报格式 func ToFormattedMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r interface{}) { if format == "string" { r = ToStringMessage(e, id, isRaw...) diff --git a/docs/cqhttp.md b/docs/cqhttp.md index 4c29eb2..a3b9904 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -68,14 +68,14 @@ Type : `image` 参数: -| 参数名 | 可能的值 | 说明 | -| ------- | --------------- | --------------------------------------------------------------- | -| `file` | - | 图片文件名 | -| `type` | `flash`,`show` | 图片类型,`flash` 表示闪照,`show` 表示秀图,默认普通图片 | -| `url` | - | 图片 URL | -| `cache` | `0` `1` | 只在通过网络 URL 发送时有效,表示是否使用已缓存的文件,默认 `1` | -| `id` | - | 发送秀图时的特效id,默认为40000 | -| `c` | `2` `3` | 通过网络下载图片时的线程数, 默认单线程. (在资源不支持并发时会自动处理)| +| 参数名 | 可能的值 | 说明 | +| ------- | --------------- | ---------------------------------------------------------------------- | +| `file` | - | 图片文件名 | +| `type` | `flash`,`show` | 图片类型,`flash` 表示闪照,`show` 表示秀图,默认普通图片 | +| `url` | - | 图片 URL | +| `cache` | `0` `1` | 只在通过网络 URL 发送时有效,表示是否使用已缓存的文件,默认 `1` | +| `id` | - | 发送秀图时的特效id,默认为40000 | +| `c` | `2` `3` | 通过网络下载图片时的线程数, 默认单线程. (在资源不支持并发时会自动处理) | 可用的特效ID: @@ -102,12 +102,12 @@ Type : `reply` 参数: -| 参数名 | 类型 | 说明 | -| ------ | ---- | ------------------------------------- | -| `id` | int | 回复时所引用的消息id, 必须为本群消息. | -| `text` | string | 自定义回复的信息 | +| 参数名 | 类型 | 说明 | +| ------ | ------ | --------------------------------------------------- | +| `id` | int | 回复时所引用的消息id, 必须为本群消息. | +| `text` | string | 自定义回复的信息 | | `qq` | int64 | 自定义回复时的自定义QQ, 如果使用自定义信息必须指定. | -| `time` | int64 | 自定义回复时的时间, 格式为Unix时间 | +| `time` | int64 | 自定义回复时的时间, 格式为Unix时间 | @@ -131,10 +131,10 @@ Type : `reply` [CQ:music,type=163,id=28949129] ``` -| 参数名 | 收 | 发 | 可能的值 | 说明 | -| --- | --- | --- | --- | --- | -| `type` | | ✓ | `qq` `163` | 分别表示使用 QQ 音乐、网易云音乐 | -| `id` | | ✓ | - | 歌曲 ID | +| 参数名 | 收 | 发 | 可能的值 | 说明 | +| ------ | --- | --- | ---------- | -------------------------------- | +| `type` | | ✓ | `qq` `163` | 分别表示使用 QQ 音乐、网易云音乐 | +| `id` | | ✓ | - | 歌曲 ID | ### 音乐自定义分享 @@ -154,15 +154,15 @@ Type : `reply` [CQ:music,type=custom,url=http://baidu.com,audio=http://baidu.com/1.mp3,title=音乐标题] ``` -| 参数名 | 收 | 发 | 可能的值 | 说明 | -| --- | --- | --- | --- | --- | -| `type` | | ✓ | `custom` | 表示音乐自定义分享 | -| `subtype` | | ✓ | `qq,163,migu,kugou,kuwo` | 表示分享类型,不填写发送为xml卡片,推荐填写提高稳定性 | -| `url` | | ✓ | - | 点击后跳转目标 URL | -| `audio` | | ✓ | - | 音乐 URL | -| `title` | | ✓ | - | 标题 | -| `content` | | ✓ | - | 内容描述 | -| `image` | | ✓ | - | 图片 URL | +| 参数名 | 收 | 发 | 可能的值 | 说明 | +| --------- | --- | --- | ------------------------ | ----------------------------------------------------- | +| `type` | | ✓ | `custom` | 表示音乐自定义分享 | +| `subtype` | | ✓ | `qq,163,migu,kugou,kuwo` | 表示分享类型,不填写发送为xml卡片,推荐填写提高稳定性 | +| `url` | | ✓ | - | 点击后跳转目标 URL | +| `audio` | | ✓ | - | 音乐 URL | +| `title` | | ✓ | - | 标题 | +| `content` | | ✓ | - | 内容描述 | +| `image` | | ✓ | - | 图片 URL | ### 红包 @@ -240,8 +240,8 @@ Type: `forward` 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | +| 参数名 | 类型 | 说明 | +| ------ | ------ | ------------------------------------------------------------- | | `id` | string | 合并转发ID, 需要通过 `/get_forward_msg` API获取转发的具体内容 | 示例: `[CQ:forward,id=xxxx]` @@ -254,12 +254,12 @@ Type: `node` 参数: -| 参数名 | 类型 | 说明 | 特殊说明 | -| --------- | ------- | -------------- | ------------------------------------------------------------ | +| 参数名 | 类型 | 说明 | 特殊说明 | +| --------- | ------- | -------------- | -------------------------------------------------------------------------------------- | | `id` | int32 | 转发消息id | 直接引用他人的消息合并转发, 实际查看顺序为原消息发送顺序 **与下面的自定义消息二选一** | -| `name` | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) | -| `uin` | int64 | 发送者QQ号 | 用于自定义消息 | -| `content` | message | 具体消息 | 用于自定义消息 | +| `name` | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) | +| `uin` | int64 | 发送者QQ号 | 用于自定义消息 | +| `content` | message | 具体消息 | 用于自定义消息 | 特殊说明: **需要使用单独的API `/send_group_forward_msg` 发送,并且由于消息段较为复杂,仅支持Array形式入参。 如果引用消息和自定义消息同时出现,实际查看顺序将取消息段顺序. 另外按 [CQHTTP](https://cqhttp.cc/docs/4.15/#/Message?id=格式) 文档说明, `data` 应全为字符串, 但由于需要接收`message` 类型的消息, 所以 *仅限此Type的content字段* 支持Array套娃** @@ -341,11 +341,11 @@ Type: `video` 参数: -| 参数名 | 类型 | 说明 | -| ------- | ------ | ------------------------------------------------| -| `file` | string | 支持http和file发送 | -| `cover` | string | 视频封面,支持http,file和base64发送,格式必须为jpg | -| `c` | `2` `3`| 通过网络下载视频时的线程数, 默认单线程. (在资源不支持并发时会自动处理)| +| 参数名 | 类型 | 说明 | +| ------- | ------- | ---------------------------------------------------------------------- | +| `file` | string | 支持http和file发送 | +| `cover` | string | 视频封面,支持http,file和base64发送,格式必须为jpg | +| `c` | `2` `3` | 通过网络下载视频时的线程数, 默认单线程. (在资源不支持并发时会自动处理) | 示例: `[CQ:image,file=file:///C:\\Users\Richard\Pictures\1.mp4]` ### XML 消息 @@ -630,8 +630,8 @@ Type: `tts` **参数** -| 字段 | 类型 | 说明 | -| --------- | ------ | ---- | +| 字段 | 类型 | 说明 | +| ------------ | ----- | ------ | | `message_id` | int32 | 消息ID | **响应数据** @@ -644,8 +644,8 @@ Type: `tts` **参数** -| 字段 | 类型 | 说明 | -| --------- | ------ | ---- | +| 字段 | 类型 | 说明 | +| ------------ | ----- | ------ | | `message_id` | int32 | 消息ID | **响应数据** @@ -658,23 +658,23 @@ Type: `tts` **参数** -| 字段 | 类型 | 说明 | -| --------- | ------ | ---- | +| 字段 | 类型 | 说明 | +| ---------- | ----- | ---- | | `group_id` | int64 | 群号 | **响应数据** 响应内容为 JSON 数组,每个元素如下: -| 字段名 | 数据类型 | 说明 | -| ----- | ------- | --- | -| `sender_id` |int64 | 发送者QQ 号 | -| `sender_nick` | string | 发送者昵称 | -| `sender_time` | int64 | 消息发送时间 | -| `operator_id` |int64 | 发送者QQ 号 | -| `operator_nick` | string | 发送者昵称 | -| `operator_time` | int64 | 消息发送时间| -| `message_id` | int32 | 消息ID | +| 字段名 | 数据类型 | 说明 | +| --------------- | -------- | ------------ | +| `sender_id` | int64 | 发送者QQ 号 | +| `sender_nick` | string | 发送者昵称 | +| `sender_time` | int64 | 消息发送时间 | +| `operator_id` | int64 | 发送者QQ 号 | +| `operator_nick` | string | 发送者昵称 | +| `operator_time` | int64 | 消息发送时间 | +| `message_id` | int32 | 消息ID | ### 图片OCR @@ -859,7 +859,7 @@ Type: `tts` | `plugins_good` | bool | 原 `CQHTTP` 字段, 恒定为 `true` | | `app_good` | bool | 原 `CQHTTP` 字段, 恒定为 `true` | | `online` | bool | 表示BOT是否在线 | -| `good` | bool | 同 `online` | +| `good` | bool | 同 `online` | | `stat` | Statistics | 运行统计 | **Statistics** @@ -883,17 +883,17 @@ Type: `tts` **参数** -| 字段 | 类型 | 说明 | -| ---------- | ------ | ------------------------- | -| `group_id` | int64 | 群号 | +| 字段 | 类型 | 说明 | +| ---------- | ----- | ---- | +| `group_id` | int64 | 群号 | **响应数据** -| 字段 | 类型 | 说明 | -| ------------------------------- | ---------- | ------------------------------- | -| `can_at_all` | bool | 是否可以@全体成员 | -| `remain_at_all_count_for_group` | int16 | 群内所有管理当天剩余@全体成员次数 | -| `remain_at_all_count_for_uin` | int16 | BOT当天剩余@全体成员次数 | +| 字段 | 类型 | 说明 | +| ------------------------------- | ----- | --------------------------------- | +| `can_at_all` | bool | 是否可以@全体成员 | +| `remain_at_all_count_for_group` | int16 | 群内所有管理当天剩余@全体成员次数 | +| `remain_at_all_count_for_uin` | int16 | BOT当天剩余@全体成员次数 | ### 下载文件到缓存目录 @@ -901,11 +901,11 @@ Type: `tts` **参数** -| 字段 | 类型 | 说明 | -| ---------- | ------ | ------------------------- | -| `url` | string | 链接地址 | -| `thread_count` | int32 | 下载线程数 | -| `headers` | string or array | 自定义请求头 | +| 字段 | 类型 | 说明 | +| -------------- | --------------- | ------------ | +| `url` | string | 链接地址 | +| `thread_count` | int32 | 下载线程数 | +| `headers` | string or array | 自定义请求头 | **`headers`格式:** @@ -928,9 +928,9 @@ JSON数组: **响应数据** -| 字段 | 类型 | 说明 | -| ---------- | ---------- | ------------ | -| `file` | string | 下载文件的*绝对路径* | +| 字段 | 类型 | 说明 | +| ------ | ------ | -------------------- | +| `file` | string | 下载文件的*绝对路径* | > 通过这个API下载的文件能直接放入CQ码作为图片或语音发送 > 调用后会阻塞直到下载完成后才会返回数据,请注意下载大文件时的超时 @@ -941,16 +941,16 @@ JSON数组: **参数** -| 字段 | 类型 | 说明 | -| ---------- | ------ | ------------------------- | -| `message_seq` | int64 | 起始消息序号, 可通过 `get_msg` 获得 | -| `group_id` | int64 | 群号 | +| 字段 | 类型 | 说明 | +| ------------- | ----- | ----------------------------------- | +| `message_seq` | int64 | 起始消息序号, 可通过 `get_msg` 获得 | +| `group_id` | int64 | 群号 | **响应数据** -| 字段 | 类型 | 说明 | -| ---------- | ---------- | ------------ | -| `messages` | []Message | 从起始序号开始的前19条消息 | +| 字段 | 类型 | 说明 | +| ---------- | --------- | -------------------------- | +| `messages` | []Message | 从起始序号开始的前19条消息 | > 不提供起始序号将默认获取最新的消息 @@ -960,23 +960,23 @@ JSON数组: **参数** -| 字段 | 类型 | 说明 | -| ---------- | ------ | ------------------------- | -| `no_cache` | bool | 是否无视缓存 | +| 字段 | 类型 | 说明 | +| ---------- | ---- | ------------ | +| `no_cache` | bool | 是否无视缓存 | **响应数据** -| 字段 | 类型 | 说明 | -| ---------- | ---------- | ------------ | -| `clients` | []Device | 在线客户端列表 | +| 字段 | 类型 | 说明 | +| --------- | -------- | -------------- | +| `clients` | []Device | 在线客户端列表 | **Device** -| 字段 | 类型 | 说明 | -| ---------- | ---------- | ------------ | -| `app_id` | int64 | 客户端ID | -| `device_name` | string | 设备名称 | -| `device_kind` | string | 设备类型 | +| 字段 | 类型 | 说明 | +| ------------- | ------ | -------- | +| `app_id` | int64 | 客户端ID | +| `device_name` | string | 设备名称 | +| `device_kind` | string | 设备类型 | ### 获取用户VIP信息 @@ -984,19 +984,19 @@ JSON数组: **参数** -| 字段名 | 数据类型 | 默认值 | 说明 | -| ----- | ------- | ----- | --- | -| `user_id` | int64 | | QQ 号 | +| 字段名 | 数据类型 | 默认值 | 说明 | +| --------- | -------- | ------ | ----- | +| `user_id` | int64 | | QQ 号 | **响应数据** -| 字段 | 类型 | 说明 | -| ------------------ | ------- | ---------- | -| `user_id` | int64 | QQ 号 | -| `nickname` | string | 用户昵称 | -| `level` | int64 | QQ 等级 | -| `level_speed` | float64 | 等级加速度 | -| `vip_level` | string | 会员等级 | +| 字段 | 类型 | 说明 | +| ------------------ | ------- | ------------ | +| `user_id` | int64 | QQ 号 | +| `nickname` | string | 用户昵称 | +| `level` | int64 | QQ 等级 | +| `level_speed` | float64 | 等级加速度 | +| `vip_level` | string | 会员等级 | | `vip_growth_speed` | int64 | 会员成长速度 | | `vip_growth_total` | int64 | 会员成长总值 | @@ -1006,10 +1006,10 @@ JSON数组: **参数** -| 字段名 | 数据类型 | 默认值 | 说明 | -| ---------- | ------- | ----- | ------ | -| `group_id` | int64 | | 群号 | -| `content` | string | | 公告内容 | +| 字段名 | 数据类型 | 默认值 | 说明 | +| ---------- | -------- | ------ | -------- | +| `group_id` | int64 | | 群号 | +| `content` | string | | 公告内容 | `该 API 没有响应数据` @@ -1050,16 +1050,16 @@ JSON数组: **事件数据** -| 字段名 | 数据类型 | 可能的值 | 说明 | -| ------------- | ------ | -------- | --- | -| `post_type` | string | `notice` | 上报类型 | -| `notice_type` | string | `notify` | 消息类型 | -| `sub_type` | string | `poke` | 提示类型 | -| `self_id` | int64 | | BOT QQ 号 | -| `sender_id` | int64 | | 发送者 QQ 号 | -| `user_id` | int64 | | 发送者 QQ 号 | -| `target_id` | int64 | | 被戳者 QQ 号 | -| `time` | int64 | | 时间 | +| 字段名 | 数据类型 | 可能的值 | 说明 | +| ------------- | -------- | -------- | ------------ | +| `post_type` | string | `notice` | 上报类型 | +| `notice_type` | string | `notify` | 消息类型 | +| `sub_type` | string | `poke` | 提示类型 | +| `self_id` | int64 | | BOT QQ 号 | +| `sender_id` | int64 | | 发送者 QQ 号 | +| `user_id` | int64 | | 发送者 QQ 号 | +| `target_id` | int64 | | 被戳者 QQ 号 | +| `time` | int64 | | 时间 | ### 群内戳一戳 @@ -1146,22 +1146,22 @@ JSON数组: **上报数据** -| 字段 | 类型 | 可能的值 | 说明 | -| ------------- | ------ | -------------- | -------- | -| `post_type` | string | `notice` | 上报类型 | -| `notice_type` | string | `client_status` | 消息类型 | -| `client` | Device | | 客户端信息 | -| `online` | bool | | 当前是否在线 | +| 字段 | 类型 | 可能的值 | 说明 | +| ------------- | ------ | --------------- | ------------ | +| `post_type` | string | `notice` | 上报类型 | +| `notice_type` | string | `client_status` | 消息类型 | +| `client` | Device | | 客户端信息 | +| `online` | bool | | 当前是否在线 | ### 精华消息 **上报数据** -| 字段 | 类型 | 可能的值 | 说明 | -| ------------- | ------ | -------------- | -------- | -| `post_type` | string | `notice` | 上报类型 | -| `notice_type` | string | `essence` | 消息类型 | -| `sub_type` | string | `add`,`delete` | 添加为`add`,移出为`delete` | -| `sender_id` | int64 | | 消息发送者ID | -| `operator_id` | int64 | | 操作者ID | -| `message_id` | int32 | | 消息ID | +| 字段 | 类型 | 可能的值 | 说明 | +| ------------- | ------ | -------------- | -------------------------- | +| `post_type` | string | `notice` | 上报类型 | +| `notice_type` | string | `essence` | 消息类型 | +| `sub_type` | string | `add`,`delete` | 添加为`add`,移出为`delete` | +| `sender_id` | int64 | | 消息发送者ID | +| `operator_id` | int64 | | 操作者ID | +| `message_id` | int32 | | 消息ID | diff --git a/global/codec.go b/global/codec.go index 1a6b35f..9cff71e 100644 --- a/global/codec.go +++ b/global/codec.go @@ -14,7 +14,7 @@ import ( var useSilkCodec = true -//InitCodec 初始化Silk编码器 +// InitCodec 初始化Silk编码器 func InitCodec() { log.Info("正在加载silk编码器...") err := codec.Init() @@ -24,7 +24,7 @@ func InitCodec() { } } -//EncoderSilk 将音频编码为Silk +// EncoderSilk 将音频编码为Silk func EncoderSilk(data []byte) ([]byte, error) { if !useSilkCodec { return nil, errors.New("no silk encoder") @@ -45,7 +45,7 @@ func EncoderSilk(data []byte) ([]byte, error) { return slk, nil } -//EncodeMP4 将给定视频文件编码为MP4 +// EncodeMP4 将给定视频文件编码为MP4 func EncodeMP4(src string, dst string) error { // -y 覆盖文件 cmd1 := exec.Command("ffmpeg", "-i", src, "-y", "-c", "copy", "-map", "0", dst) err := cmd1.Run() @@ -56,7 +56,7 @@ func EncodeMP4(src string, dst string) error { // -y 覆盖文件 return err } -//ExtractCover 获取给定视频文件的Cover +// ExtractCover 获取给定视频文件的Cover func ExtractCover(src string, target string) error { cmd := exec.Command("ffmpeg", "-i", src, "-y", "-r", "1", "-f", "image2", target) return errors.Wrap(cmd.Run(), "extract video cover failed") diff --git a/global/codec/codec.go b/global/codec/codec.go index 41877a4..03bf3ee 100644 --- a/global/codec/codec.go +++ b/global/codec/codec.go @@ -1,7 +1,7 @@ // +build linux windows darwin // +build 386 amd64 arm arm64 -//Package codec Slik编码核心模块 +// Package codec Slik编码核心模块 package codec import ( @@ -41,7 +41,7 @@ func getEncoderFilePath() string { return encoderFile } -//Init 下载Silk编码器 +// Init 下载Silk编码器 func Init() error { if !fileExist(silkCachePath) { _ = os.MkdirAll(silkCachePath, os.ModePerm) @@ -58,7 +58,7 @@ func Init() error { return nil } -//EncodeToSilk 将音频编码为Silk +// EncodeToSilk 将音频编码为Silk func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) { // 1. 写入缓存文件 rawPath := path.Join(silkCachePath, tempName+".wav") diff --git a/global/codec/codec_unsupportedarch.go b/global/codec/codec_unsupportedarch.go index b0e9890..41cb9d1 100644 --- a/global/codec/codec_unsupportedarch.go +++ b/global/codec/codec_unsupportedarch.go @@ -4,12 +4,12 @@ package codec import "errors" -//Init 下载silk编码器 +// Init 下载silk编码器 func Init() error { return errors.New("Unsupport arch now") } -//EncodeToSilk 将音频编码为Silk +// EncodeToSilk 将音频编码为Silk func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) { return nil, errors.New("Unsupport arch now") } diff --git a/global/codec/codec_unsupportedos.go b/global/codec/codec_unsupportedos.go index 9428fe0..160bc0d 100644 --- a/global/codec/codec_unsupportedos.go +++ b/global/codec/codec_unsupportedos.go @@ -4,12 +4,12 @@ package codec import "errors" -//Init 下载silk编码器 +// Init 下载silk编码器 func Init() error { return errors.New("not support now") } -//EncodeToSilk 将音频编码为Silk +// EncodeToSilk 将音频编码为Silk func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) { return nil, errors.New("not support now") } diff --git a/global/config.go b/global/config.go index 0abf933..399fd06 100644 --- a/global/config.go +++ b/global/config.go @@ -12,7 +12,7 @@ import ( var json = jsoniter.ConfigCompatibleWithStandardLibrary -//DefaultConfigWithComments 为go-cqhttp的默认配置文件 +// DefaultConfigWithComments 为go-cqhttp的默认配置文件 var DefaultConfigWithComments = ` /* go-cqhttp 默认配置文件 @@ -135,10 +135,10 @@ var DefaultConfigWithComments = ` } ` -//PasswordHash 存储QQ密码哈希供登录使用 +// PasswordHash 存储QQ密码哈希供登录使用 var PasswordHash [16]byte -//JSONConfig Config对应的结构体 +// JSONConfig Config对应的结构体 type JSONConfig struct { Uin int64 `json:"uin"` Password string `json:"password"` @@ -171,7 +171,7 @@ type JSONConfig struct { WebUI *GoCQWebUI `json:"web_ui"` } -//CQHTTPAPIConfig HTTPAPI对应的Config结构体 +// CQHTTPAPIConfig HTTPAPI对应的Config结构体 type CQHTTPAPIConfig struct { Host string `json:"host"` Port uint16 `json:"port"` @@ -191,7 +191,7 @@ type CQHTTPAPIConfig struct { PostMessageFormat string `json:"post_message_format"` } -//GoCQHTTPConfig 正向HTTP对应config结构体 +// GoCQHTTPConfig 正向HTTP对应config结构体 type GoCQHTTPConfig struct { Enabled bool `json:"enabled"` Host string `json:"host"` @@ -200,14 +200,14 @@ type GoCQHTTPConfig struct { PostUrls map[string]string `json:"post_urls"` } -//GoCQWebSocketConfig 正向WebSocket对应Config结构体 +// GoCQWebSocketConfig 正向WebSocket对应Config结构体 type GoCQWebSocketConfig struct { Enabled bool `json:"enabled"` Host string `json:"host"` Port uint16 `json:"port"` } -//GoCQReverseWebSocketConfig 反向WebSocket对应Config结构体 +// GoCQReverseWebSocketConfig 反向WebSocket对应Config结构体 type GoCQReverseWebSocketConfig struct { Enabled bool `json:"enabled"` ReverseURL string `json:"reverse_url"` @@ -216,7 +216,7 @@ type GoCQReverseWebSocketConfig struct { ReverseReconnectInterval uint16 `json:"reverse_reconnect_interval"` } -//GoCQWebUI WebUI对应Config结构体 +// GoCQWebUI WebUI对应Config结构体 type GoCQWebUI struct { Enabled bool `json:"enabled"` Host string `json:"host"` @@ -224,7 +224,7 @@ type GoCQWebUI struct { WebInput bool `json:"web_input"` } -//DefaultConfig 返回一份默认配置对应结构体 +// DefaultConfig 返回一份默认配置对应结构体 func DefaultConfig() *JSONConfig { return &JSONConfig{ EnableDB: true, @@ -277,7 +277,7 @@ func DefaultConfig() *JSONConfig { } } -//LoadConfig 加载配置文件 +// LoadConfig 加载配置文件 func LoadConfig(p string) *JSONConfig { if !PathExists(p) { log.Warnf("尝试加载配置文件 %v 失败: 文件不存在", p) @@ -299,7 +299,7 @@ func LoadConfig(p string) *JSONConfig { return &c } -//Save 写入配置文件至path +// Save 写入配置文件至path func (c *JSONConfig) Save(path string) error { data, err := hjson.MarshalWithOptions(c, hjson.EncoderOptions{ Eol: "\n", diff --git a/global/doc.go b/global/doc.go index 210f1c3..ef1145b 100644 --- a/global/doc.go +++ b/global/doc.go @@ -1,2 +1,2 @@ -//Package global 包含文件下载,视频音频编码,本地文件缓存处理,消息过滤器,调用速率限制,gocq主配置等的相关函数与结构体 +// Package global 包含文件下载,视频音频编码,本地文件缓存处理,消息过滤器,调用速率限制,gocq主配置等的相关函数与结构体 package global diff --git a/global/filter.go b/global/filter.go index fdcf5fb..dd4e816 100644 --- a/global/filter.go +++ b/global/filter.go @@ -10,14 +10,14 @@ import ( "github.com/tidwall/gjson" ) -//MSG 消息Map +// MSG 消息Map type MSG map[string]interface{} -//Get 尝试从消息Map中取出key为s的值,若不存在则返回MSG{} +// Get 尝试从消息Map中取出key为s的值,若不存在则返回MSG{} // -//若所给key对应的值的类型是global.MSG,则返回此值 +// 若所给key对应的值的类型是global.MSG,则返回此值 // -//若所给key对应值的类型不是global.MSG,则返回MSG{"__str__": Val} +// 若所给key对应值的类型不是global.MSG,则返回MSG{"__str__": Val} func (m MSG) Get(s string) MSG { if v, ok := m[s]; ok { if msg, ok := v.(MSG); ok { @@ -28,7 +28,7 @@ func (m MSG) Get(s string) MSG { return nil // 不存在为空 } -//String 将消息Map转化为String。若Map存在key "__str__",则返回此key对应的值,否则将输出整张消息Map对应的JSON字符串 +// String 将消息Map转化为String。若Map存在key "__str__",则返回此key对应的值,否则将输出整张消息Map对应的JSON字符串 func (m MSG) String() string { if m == nil { return "" // 空 JSON @@ -43,7 +43,7 @@ func (m MSG) String() string { return str } -//Filter 定义了一个消息上报过滤接口 +// Filter 定义了一个消息上报过滤接口 type Filter interface { Eval(payload MSG) bool } @@ -53,7 +53,7 @@ type operationNode struct { filter Filter } -//NotOperator 定义了过滤器中Not操作符 +// NotOperator 定义了过滤器中Not操作符 type NotOperator struct { operand Filter } @@ -67,12 +67,12 @@ func notOperatorConstruct(argument gjson.Result) *NotOperator { return op } -//Eval 对payload执行Not过滤 +// Eval 对payload执行Not过滤 func (op *NotOperator) Eval(payload MSG) bool { return !op.operand.Eval(payload) } -//AndOperator 定义了过滤器中And操作符 +// AndOperator 定义了过滤器中And操作符 type AndOperator struct { operands []operationNode } @@ -108,7 +108,7 @@ func andOperatorConstruct(argument gjson.Result) *AndOperator { return op } -//Eval 对payload执行And过滤 +// Eval 对payload执行And过滤 func (andOperator *AndOperator) Eval(payload MSG) bool { res := true for _, operand := range andOperator.operands { @@ -129,7 +129,7 @@ func (andOperator *AndOperator) Eval(payload MSG) bool { return res } -//OrOperator 定义了过滤器中Or操作符 +// OrOperator 定义了过滤器中Or操作符 type OrOperator struct { operands []Filter } @@ -146,7 +146,7 @@ func orOperatorConstruct(argument gjson.Result) *OrOperator { return op } -//Eval 对payload执行Or过滤 +// Eval 对payload执行Or过滤 func (op *OrOperator) Eval(payload MSG) bool { res := false for _, operand := range op.operands { @@ -158,7 +158,7 @@ func (op *OrOperator) Eval(payload MSG) bool { return res } -//EqualOperator 定义了过滤器中Equal操作符 +// EqualOperator 定义了过滤器中Equal操作符 type EqualOperator struct { operand string } @@ -169,12 +169,12 @@ func equalOperatorConstruct(argument gjson.Result) *EqualOperator { return op } -//Eval 对payload执行Equal过滤 +// Eval 对payload执行Equal过滤 func (op *EqualOperator) Eval(payload MSG) bool { return payload.String() == op.operand } -//NotEqualOperator 定义了过滤器中NotEqual操作符 +// NotEqualOperator 定义了过滤器中NotEqual操作符 type NotEqualOperator struct { operand string } @@ -185,12 +185,12 @@ func notEqualOperatorConstruct(argument gjson.Result) *NotEqualOperator { return op } -//Eval 对payload执行NotEqual过滤 +// Eval 对payload执行NotEqual过滤 func (op *NotEqualOperator) Eval(payload MSG) bool { return !(payload.String() == op.operand) } -//InOperator 定义了过滤器中In操作符 +// InOperator 定义了过滤器中In操作符 type InOperator struct { operandString string operandArray []string @@ -213,7 +213,7 @@ func inOperatorConstruct(argument gjson.Result) *InOperator { return op } -//Eval 对payload执行In过滤 +// Eval 对payload执行In过滤 func (op *InOperator) Eval(payload MSG) bool { payloadStr := payload.String() if op.operandArray != nil { @@ -227,7 +227,7 @@ func (op *InOperator) Eval(payload MSG) bool { return strings.Contains(op.operandString, payloadStr) } -//ContainsOperator 定义了过滤器中Contains操作符 +// ContainsOperator 定义了过滤器中Contains操作符 type ContainsOperator struct { operand string } @@ -241,12 +241,12 @@ func containsOperatorConstruct(argument gjson.Result) *ContainsOperator { return op } -//Eval 对payload执行Contains过滤 +// Eval 对payload执行Contains过滤 func (op *ContainsOperator) Eval(payload MSG) bool { return strings.Contains(payload.String(), op.operand) } -//RegexOperator 定义了过滤器中Regex操作符 +// RegexOperator 定义了过滤器中Regex操作符 type RegexOperator struct { regex *regexp.Regexp } @@ -260,13 +260,13 @@ func regexOperatorConstruct(argument gjson.Result) *RegexOperator { return op } -//Eval 对payload执行RegexO过滤 +// Eval 对payload执行RegexO过滤 func (op *RegexOperator) Eval(payload MSG) bool { matched := op.regex.MatchString(payload.String()) return matched } -//Generate 根据给定操作符名opName及操作符参数argument创建一个过滤器实例 +// Generate 根据给定操作符名opName及操作符参数argument创建一个过滤器实例 func Generate(opName string, argument gjson.Result) Filter { switch opName { case "not": @@ -290,10 +290,10 @@ func Generate(opName string, argument gjson.Result) Filter { } } -//EventFilter 初始化一个nil过滤器 +// EventFilter 初始化一个nil过滤器 var EventFilter Filter = nil -//BootFilter 启动事件过滤器 +// BootFilter 启动事件过滤器 func BootFilter() { defer func() { if e := recover(); e != nil { diff --git a/global/fs.go b/global/fs.go index a6760a6..741de22 100644 --- a/global/fs.go +++ b/global/fs.go @@ -27,36 +27,36 @@ import ( ) const ( - //ImagePath go-cqhttp使用的图片缓存目录 + // ImagePath go-cqhttp使用的图片缓存目录 ImagePath = "data/images" - //ImagePathOld 兼容旧版go-cqhtto使用的图片缓存目录 + // ImagePathOld 兼容旧版go-cqhtto使用的图片缓存目录 ImagePathOld = "data/image" - //VoicePath go-cqhttp使用的语音缓存目录 + // VoicePath go-cqhttp使用的语音缓存目录 VoicePath = "data/voices" - //VoicePathOld 兼容旧版go-cqhtto使用的语音缓存目录 + // VoicePathOld 兼容旧版go-cqhtto使用的语音缓存目录 VoicePathOld = "data/record" - //VideoPath go-cqhttp使用的视频缓存目录 + // VideoPath go-cqhttp使用的视频缓存目录 VideoPath = "data/videos" - //CachePath go-cqhttp使用的缓存目录 + // CachePath go-cqhttp使用的缓存目录 CachePath = "data/cache" ) var ( - //ErrSyntax Path语法错误时返回的错误 + // ErrSyntax Path语法错误时返回的错误 ErrSyntax = errors.New("syntax error") - //HeaderAmr AMR文件头 + // HeaderAmr AMR文件头 HeaderAmr = []byte("#!AMR") - //HeaderSilk Silkv3文件头 + // HeaderSilk Silkv3文件头 HeaderSilk = []byte("\x02#!SILK_V3") ) -//PathExists 判断给定path是否存在 +// PathExists 判断给定path是否存在 func PathExists(path string) bool { _, err := os.Stat(path) return err == nil || os.IsExist(err) } -//ReadAllText 读取给定path对应文件,无法读取时返回空值 +// ReadAllText 读取给定path对应文件,无法读取时返回空值 func ReadAllText(path string) string { b, err := ioutil.ReadFile(path) if err != nil { @@ -66,25 +66,25 @@ func ReadAllText(path string) string { return string(b) } -//WriteAllText 将给定text写入给定path +// WriteAllText 将给定text写入给定path func WriteAllText(path, text string) error { return ioutil.WriteFile(path, []byte(text), 0644) } -//Check 检测err是否为nil +// Check 检测err是否为nil func Check(err error) { if err != nil { log.Fatalf("遇到错误: %v", err) } } -//IsAMRorSILK 判断给定文件是否为Amr或Silk格式 +// IsAMRorSILK 判断给定文件是否为Amr或Silk格式 func IsAMRorSILK(b []byte) bool { return bytes.HasPrefix(b, HeaderAmr) || bytes.HasPrefix(b, HeaderSilk) } -//FindFile 从给定的File寻找文件,并返回文件byte数组。File是一个合法的URL。Path为文件寻找位置。 -//对于HTTP/HTTPS形式的URL,Cache为"1"或空时表示启用缓存 +// FindFile 从给定的File寻找文件,并返回文件byte数组。File是一个合法的URL。Path为文件寻找位置。 +// 对于HTTP/HTTPS形式的URL,Cache为"1"或空时表示启用缓存 func FindFile(file, cache, PATH string) (data []byte, err error) { data, err = nil, ErrSyntax if strings.HasPrefix(file, "http") || strings.HasPrefix(file, "https") { @@ -128,7 +128,7 @@ func FindFile(file, cache, PATH string) (data []byte, err error) { return } -//DelFile 删除一个给定path,并返回删除结果 +// DelFile 删除一个给定path,并返回删除结果 func DelFile(path string) bool { err := os.Remove(path) if err != nil { @@ -141,7 +141,7 @@ func DelFile(path string) bool { return true } -//ReadAddrFile 从给定path中读取合法的IP地址与端口,每个IP地址以换行符"\n"作为分隔 +// ReadAddrFile 从给定path中读取合法的IP地址与端口,每个IP地址以换行符"\n"作为分隔 func ReadAddrFile(path string) []*net.TCPAddr { d, err := ioutil.ReadFile(path) if err != nil { @@ -160,12 +160,12 @@ func ReadAddrFile(path string) []*net.TCPAddr { return ret } -//WriteCounter 写入量计算实例 +// WriteCounter 写入量计算实例 type WriteCounter struct { Total uint64 } -//Write 方法将写入的byte长度追加至写入的总长度Total中 +// Write 方法将写入的byte长度追加至写入的总长度Total中 func (wc *WriteCounter) Write(p []byte) (int, error) { n := len(p) wc.Total += uint64(n) @@ -173,13 +173,13 @@ func (wc *WriteCounter) Write(p []byte) (int, error) { return n, nil } -//PrintProgress 方法将打印当前的总写入量 +// PrintProgress 方法将打印当前的总写入量 func (wc *WriteCounter) PrintProgress() { fmt.Printf("\r%s", strings.Repeat(" ", 35)) fmt.Printf("\rDownloading... %s complete", humanize.Bytes(wc.Total)) } -//UpdateFromStream copy form getlantern/go-update +// UpdateFromStream copy form getlantern/go-update func UpdateFromStream(updateWith io.Reader) (err error, errRecover error) { updatePath, err := osext.Executable() if err != nil { diff --git a/global/log_hook.go b/global/log_hook.go index 63865f8..aa556cc 100644 --- a/global/log_hook.go +++ b/global/log_hook.go @@ -18,7 +18,7 @@ type LocalHook struct { writer io.Writer // io } -// ref: logrus/hooks.go. impl Hook interface +// Levels ref: logrus/hooks.go. impl Hook interface func (hook *LocalHook) Levels() []logrus.Level { if len(hook.levels) == 0 { return logrus.AllLevels @@ -76,6 +76,7 @@ func (hook *LocalHook) Fire(entry *logrus.Entry) error { return nil } +// SetFormatter 设置日志格式 func (hook *LocalHook) SetFormatter(formatter logrus.Formatter) { hook.lock.Lock() defer hook.lock.Unlock() @@ -96,18 +97,21 @@ func (hook *LocalHook) SetFormatter(formatter logrus.Formatter) { hook.formatter = formatter } +// SetWriter 设置Writer func (hook *LocalHook) SetWriter(writer io.Writer) { hook.lock.Lock() defer hook.lock.Unlock() hook.writer = writer } +// SetPath 设置日志写入路径 func (hook *LocalHook) SetPath(path string) { hook.lock.Lock() defer hook.lock.Unlock() hook.path = path } +// NewLocalHook 初始化本地日志钩子实现 func NewLocalHook(args interface{}, formatter logrus.Formatter, levels ...logrus.Level) *LocalHook { hook := &LocalHook{ lock: new(sync.Mutex), @@ -127,6 +131,11 @@ func NewLocalHook(args interface{}, formatter logrus.Formatter, levels ...logrus return hook } +// GetLogLevel 获取日志等级 +// +// 可能的值有 +// +// "trace","debug","info","warn","warn","error" func GetLogLevel(level string) []logrus.Level { switch level { case "trace": diff --git a/global/net.go b/global/net.go index 33ebb66..1eeaaaa 100644 --- a/global/net.go +++ b/global/net.go @@ -37,17 +37,17 @@ var ( }, } - //Proxy 存储Config.proxy_rewrite,用于设置代理 + // Proxy 存储Config.proxy_rewrite,用于设置代理 Proxy string - //ErrOverSize 响应主体过大时返回此错误 + // ErrOverSize 响应主体过大时返回此错误 ErrOverSize = errors.New("oversize") - //UserAgent HTTP请求时使用的UA + // UserAgent HTTP请求时使用的UA UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66" ) -//GetBytes 对给定URL发送Get请求,返回响应主体 +// GetBytes 对给定URL发送Get请求,返回响应主体 func GetBytes(url string) ([]byte, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { @@ -73,7 +73,7 @@ func GetBytes(url string) ([]byte, error) { return body, nil } -//DownloadFile 将给定URL对应的文件下载至给定Path +// DownloadFile 将给定URL对应的文件下载至给定Path func DownloadFile(url, path string, limit int64, headers map[string]string) error { file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0666) if err != nil { @@ -107,7 +107,7 @@ func DownloadFile(url, path string, limit int64, headers map[string]string) erro return nil } -//DownloadFileMultiThreading 使用threadCount个线程将给定URL对应的文件下载至给定Path +// DownloadFileMultiThreading 使用threadCount个线程将给定URL对应的文件下载至给定Path func DownloadFileMultiThreading(url, path string, limit int64, threadCount int, headers map[string]string) error { if threadCount < 2 { return DownloadFile(url, path, limit, headers) @@ -265,7 +265,7 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int, return lastErr } -//GetSliderTicket 通过给定的验证链接raw和id,获取验证结果Ticket +// GetSliderTicket 通过给定的验证链接raw和id,获取验证结果Ticket func GetSliderTicket(raw, id string) (string, error) { var rsp string if err := gout.POST("https://api.shkong.com/gocqhttpapi/task").SetJSON(gout.H{ @@ -281,7 +281,7 @@ func GetSliderTicket(raw, id string) (string, error) { return g.Get("ticket").Str, nil } -//QQMusicSongInfo 通过给定id在QQ音乐上查找曲目信息 +// QQMusicSongInfo 通过给定id在QQ音乐上查找曲目信息 func QQMusicSongInfo(id string) (gjson.Result, error) { d, err := GetBytes(`https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0&data={%22comm%22:{%22ct%22:24,%22cv%22:0},%22songinfo%22:{%22method%22:%22get_song_detail_yqq%22,%22param%22:{%22song_type%22:0,%22song_mid%22:%22%22,%22song_id%22:` + id + `},%22module%22:%22music.pf_song_detail_svr%22}}`) if err != nil { @@ -290,7 +290,7 @@ func QQMusicSongInfo(id string) (gjson.Result, error) { return gjson.ParseBytes(d).Get("songinfo.data"), nil } -//NeteaseMusicSongInfo 通过给定id在wdd音乐上查找曲目信息 +// NeteaseMusicSongInfo 通过给定id在wdd音乐上查找曲目信息 func NeteaseMusicSongInfo(id string) (gjson.Result, error) { d, err := GetBytes(fmt.Sprintf("http://music.163.com/api/song/detail/?id=%s&ids=%%5B%s%%5D", id, id)) if err != nil { diff --git a/global/param.go b/global/param.go index d89d7d2..eaaae6a 100644 --- a/global/param.go +++ b/global/param.go @@ -21,15 +21,15 @@ var falseSet = map[string]struct{}{ "0": {}, } -//EnsureBool 判断给定的p是否可表示为合法Bool类型,否则返回defaultVal +// EnsureBool 判断给定的p是否可表示为合法Bool类型,否则返回defaultVal // -//支持的合法类型有 +// 支持的合法类型有 // -//type bool +// type bool // -//type gjson.True or gjson.False +// type gjson.True or gjson.False // -//type string "true","yes","1" or "false","no","0" (case insensitive) +// type string "true","yes","1" or "false","no","0" (case insensitive) func EnsureBool(p interface{}, defaultVal bool) bool { var str string if b, ok := p.(bool); ok { @@ -85,7 +85,7 @@ func VersionNameCompare(current, remote string) bool { return len(cur) < len(re) } -//SplitURL 将给定URL字符串分割为两部分,用于URL预处理防止风控 +// SplitURL 将给定URL字符串分割为两部分,用于URL预处理防止风控 func SplitURL(s string) []string { reg := regexp.MustCompile(`(?i)[a-z\d][-a-z\d]{0,62}(\.[a-z\d][-a-z\d]{0,62})+\.?`) idx := reg.FindAllStringIndex(s, -1) diff --git a/global/ratelimit.go b/global/ratelimit.go index 5983922..60a92ea 100644 --- a/global/ratelimit.go +++ b/global/ratelimit.go @@ -9,14 +9,14 @@ import ( var limiter *rate.Limiter var limitEnable = false -//RateLimit 执行API调用速率限制 +// RateLimit 执行API调用速率限制 func RateLimit(ctx context.Context) { if limitEnable { _ = limiter.Wait(ctx) } } -//InitLimiter 初始化速率限制器 +// InitLimiter 初始化速率限制器 func InitLimiter(frequency float64, bucketSize int) { limitEnable = true limiter = rate.NewLimiter(rate.Limit(frequency), bucketSize) diff --git a/go.mod b/go.mod index 5fc6b11..4348257 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.15 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20210202135946-553229fea92e + github.com/Mrs4s/MiraiGo v0.0.0-20210204122237-7dcda89bd00e github.com/dustin/go-humanize v1.0.0 github.com/gin-contrib/pprof v1.3.0 github.com/gin-gonic/gin v1.6.3 @@ -12,7 +12,7 @@ require ( github.com/google/go-cmp v0.5.4 // indirect github.com/google/uuid v1.2.0 // indirect github.com/gorilla/websocket v1.4.2 - github.com/guonaihong/gout v0.1.4 + github.com/guonaihong/gout v0.1.5 github.com/hjson/hjson-go v3.1.0+incompatible github.com/jonboulle/clockwork v0.2.2 // indirect github.com/json-iterator/go v1.1.10 @@ -24,21 +24,22 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect github.com/nxadm/tail v1.4.6 // indirect - github.com/onsi/ginkgo v1.14.2 // indirect - github.com/onsi/gomega v1.10.4 // indirect + github.com/onsi/ginkgo v1.15.0 // indirect + github.com/onsi/gomega v1.10.5 // indirect github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.7.0 github.com/stretchr/testify v1.7.0 // indirect github.com/syndtr/goleveldb v1.0.0 github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 - github.com/tidwall/gjson v1.6.7 - github.com/ugorji/go v1.2.3 // indirect + github.com/tidwall/gjson v1.6.8 + github.com/ugorji/go v1.2.4 // indirect github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 - golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 + golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad + golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect + golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf golang.org/x/text v0.3.5 // indirect golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect diff --git a/go.sum b/go.sum index dac6632..ec90b95 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Mrs4s/MiraiGo v0.0.0-20210202135946-553229fea92e h1:5rZXeo+KW1vNq5fM7DowITQgm8r7HuH6w9tScWJ5GQQ= -github.com/Mrs4s/MiraiGo v0.0.0-20210202135946-553229fea92e/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU= +github.com/Mrs4s/MiraiGo v0.0.0-20210204122237-7dcda89bd00e h1:CxPsCMdqj6QlP2S7+EbXaY8I1ozAhGv48MmAUypxZ8A= +github.com/Mrs4s/MiraiGo v0.0.0-20210204122237-7dcda89bd00e/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -62,8 +62,8 @@ github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/guonaihong/gout v0.1.4 h1:uBBoyztMX9okC27OQxqhn6bZ0ROkGyvnEIHwtp3TM4g= -github.com/guonaihong/gout v0.1.4/go.mod h1:0rFYAYyzbcxEg11eY2qUbffJs7hHRPeugAnlVYSp8Ic= +github.com/guonaihong/gout v0.1.5 h1:1FeFFJWWdWYApBW9d6vzMDB4eR4Zr8T/gaVrjDVcl5U= +github.com/guonaihong/gout v0.1.5/go.mod h1:0rFYAYyzbcxEg11eY2qUbffJs7hHRPeugAnlVYSp8Ic= github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw= github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -106,13 +106,13 @@ github.com/nxadm/tail v1.4.6/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.2 h1:8mVmC9kjFFmA8H4pKMUhcblgifdkOIXPvbhN1T36q1M= -github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= +github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4= +github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.10.4 h1:NiTx7EEvBzu9sFOD1zORteLSt3o8gnlvZZwSE9TnY9U= -github.com/onsi/gomega v1.10.4/go.mod h1:g/HbgYopi++010VEqkFgJHKC09uJiW9UkXvMUuKHUCQ= +github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ= +github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -134,41 +134,51 @@ github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFd github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk= github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA= -github.com/tidwall/gjson v1.6.7 h1:Mb1M9HZCRWEcXQ8ieJo7auYyyiSux6w9XN3AdTpxJrE= -github.com/tidwall/gjson v1.6.7/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI= +github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w= +github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI= github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE= github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU= github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= -github.com/ugorji/go v1.2.3 h1:WbFSXLxDFKVN69Sk8t+XHGzVCD7R8UoAATR8NqZgTbk= -github.com/ugorji/go v1.2.3/go.mod h1:5l8GZ8hZvmL4uMdy+mhCO1LjswGRYco9Q3HfuisB21A= +github.com/ugorji/go v1.2.4 h1:cTciPbZ/VSOzCLKclmssnfQ/jyoVyOcJ3aoJyUV1Urc= +github.com/ugorji/go v1.2.4/go.mod h1:EuaSCk8iZMdIspsu6HXH7X2UGKw1ezO4wCfGszGmmo4= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -github.com/ugorji/go/codec v1.2.3 h1:/mVYEV+Jo3IZKeA5gBngN0AvNnQltEDkR+eQikkWQu0= -github.com/ugorji/go/codec v1.2.3/go.mod h1:5FxzDJIgeiWJZslYHPj+LS1dq1ZBQVelZFnjsFGI/Uc= +github.com/ugorji/go/codec v1.2.4 h1:C5VurWRRCKjuENsbM6GYVw8W++WVW9rSxoACKIvxzz8= +github.com/ugorji/go/codec v1.2.4/go.mod h1:bWBu1+kIRWcF8uMklKaJrR6fTWQOwAlrIzX22pHwryA= github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if55Fu3HOwbfcaQlJ27p3oeJU2JZqoeT3ITJQk= github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= +golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U= golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew= +golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -180,10 +190,14 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -198,6 +212,10 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/main.go b/main.go index 327663b..86a1b1b 100644 --- a/main.go +++ b/main.go @@ -199,8 +199,8 @@ func main() { log.Infof("密码加密已启用, 使用运行时传递的参数进行解密,按 Ctrl+C 取消.") } - //升级客户端密码加密方案,MD5+TEA 加密密码 -> PBKDF2+AES 加密 MD5 - //升级后的 PasswordEncrypted 字符串以"AES:"开始,其后为 Hex 编码的16字节加密 MD5 + // 升级客户端密码加密方案,MD5+TEA 加密密码 -> PBKDF2+AES 加密 MD5 + // 升级后的 PasswordEncrypted 字符串以"AES:"开始,其后为 Hex 编码的16字节加密 MD5 if !strings.HasPrefix(conf.PasswordEncrypted, "AES:") { password := OldPasswordDecrypt(conf.PasswordEncrypted, byteKey) passwordHash := md5.Sum([]byte(password)) diff --git a/server/apiAdmin.go b/server/apiAdmin.go index 37b78ee..a22e7a8 100644 --- a/server/apiAdmin.go +++ b/server/apiAdmin.go @@ -30,16 +30,16 @@ import ( var json = jsoniter.ConfigCompatibleWithStandardLibrary -//WebInput 网页输入channel +// WebInput 网页输入channel var WebInput = make(chan string, 1) //长度1,用于阻塞 -//Console 控制台channel +// Console 控制台channel var Console = make(chan os.Signal, 1) -//Restart 重启信号监听channel +// Restart 重启信号监听channel var Restart = make(chan struct{}, 1) -//JSONConfig go-cqhttp配置 +// JSONConfig go-cqhttp配置 var JSONConfig *global.JSONConfig type webServer struct { @@ -50,10 +50,10 @@ type webServer struct { Console *bufio.Reader } -//WebServer Admin子站的Server +// WebServer Admin子站的Server var WebServer = &webServer{} -//APIAdminRoutingTable Admin子站的路由映射 +// APIAdminRoutingTable Admin子站的路由映射 var APIAdminRoutingTable = map[string]func(s *webServer, c *gin.Context){ "do_restart": AdminDoRestart, //热重启 "do_process_restart": AdminProcessRestart, //进程重启 @@ -68,7 +68,7 @@ var APIAdminRoutingTable = map[string]func(s *webServer, c *gin.Context){ "get_config_json": AdminGetConfigJSON, //拉取 当前的config.json配置 } -//Failed 构建失败返回MSG +// Failed 构建失败返回MSG func Failed(code int, msg string) coolq.MSG { return coolq.MSG{"data": nil, "retcode": code, "status": "failed", "msg": msg} } @@ -82,11 +82,11 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot { s.engine.Use(AuthMiddleWare()) - //通用路由 + // 通用路由 s.engine.Any("/admin/:action", s.admin) go func() { - //开启端口监听 + // 开启端口监听 if s.Conf.WebUI != nil && s.Conf.WebUI.Enabled { if Debug { pprof.Register(s.engine) @@ -104,7 +104,7 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot { os.Exit(1) } } else { - //关闭端口监听 + // 关闭端口监听 c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) <-c @@ -113,7 +113,7 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot { }() s.Dologin() s.UpServer() - b := s.bot //外部引入 bot对象,用于操作bot + b := s.bot // 外部引入 bot对象,用于操作bot return b } @@ -334,7 +334,7 @@ func (s *webServer) admin(c *gin.Context) { } } -//GetConf 获取当前配置文件信息 +// GetConf 获取当前配置文件信息 func GetConf() *global.JSONConfig { if JSONConfig != nil { return JSONConfig @@ -343,11 +343,11 @@ func GetConf() *global.JSONConfig { return conf } -//AuthMiddleWare Admin控制器登录验证 +// AuthMiddleWare Admin控制器登录验证 func AuthMiddleWare() gin.HandlerFunc { return func(c *gin.Context) { conf := GetConf() - //处理跨域问题 + // 处理跨域问题 c.Header("Access-Control-Allow-Origin", "*") c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token") c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, PATCH, DELETE") @@ -435,14 +435,15 @@ func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin }) s.Cli = cli s.Dologin() - //关闭之前的 server + // 关闭之前的 server if OldConf.HTTPConfig != nil && OldConf.HTTPConfig.Enabled { cqHTTPServer.ShutDown() } - //if OldConf.WSConfig != nil && OldConf.WSConfig.Enabled { - // server.WsShutdown() - //} - //s.UpServer() + // if OldConf.WSConfig != nil && OldConf.WSConfig.Enabled { + // server.WsShutdown() + // } + // s.UpServer() + s.ReloadServer() s.Conf = conf } @@ -477,7 +478,7 @@ func (s *webServer) ReloadServer() { } } -//AdminDoRestart 热重启 +// AdminDoRestart 热重启 func AdminDoRestart(s *webServer, c *gin.Context) { s.bot.Release() s.bot = nil @@ -486,19 +487,19 @@ func AdminDoRestart(s *webServer, c *gin.Context) { c.JSON(200, coolq.OK(coolq.MSG{})) } -//AdminProcessRestart 进程重启 +// AdminProcessRestart 进程重启 func AdminProcessRestart(s *webServer, c *gin.Context) { Restart <- struct{}{} c.JSON(200, coolq.OK(coolq.MSG{})) } -//AdminDoRestartDocker 冷重启 +// AdminDoRestartDocker 冷重启 func AdminDoRestartDocker(s *webServer, c *gin.Context) { Console <- os.Kill c.JSON(200, coolq.OK(coolq.MSG{})) } -//AdminWebWrite web输入html页面 +// AdminWebWrite web输入html页面 func AdminWebWrite(s *webServer, c *gin.Context) { pic := global.ReadAllText("captcha.jpg") var picbase64 string @@ -515,14 +516,14 @@ func AdminWebWrite(s *webServer, c *gin.Context) { })) } -//AdminDoWebWrite web输入处理 +// AdminDoWebWrite web输入处理 func AdminDoWebWrite(s *webServer, c *gin.Context) { input := c.PostForm("input") WebInput <- input c.JSON(200, coolq.OK(coolq.MSG{})) } -//AdminDoConfigBase 普通配置修改 +// AdminDoConfigBase 普通配置修改 func AdminDoConfigBase(s *webServer, c *gin.Context) { conf := GetConf() conf.Uin, _ = strconv.ParseInt(c.PostForm("uin"), 10, 64) @@ -542,7 +543,7 @@ func AdminDoConfigBase(s *webServer, c *gin.Context) { } } -//AdminDoConfigHTTP HTTP配置修改 +// AdminDoConfigHTTP HTTP配置修改 func AdminDoConfigHTTP(s *webServer, c *gin.Context) { conf := GetConf() p, _ := strconv.ParseUint(c.PostForm("port"), 10, 16) @@ -567,7 +568,7 @@ func AdminDoConfigHTTP(s *webServer, c *gin.Context) { } } -//AdminDoConfigWS ws配置修改 +// AdminDoConfigWS ws配置修改 func AdminDoConfigWS(s *webServer, c *gin.Context) { conf := GetConf() p, _ := strconv.ParseUint(c.PostForm("port"), 10, 16) @@ -587,7 +588,7 @@ func AdminDoConfigWS(s *webServer, c *gin.Context) { } } -//AdminDoConfigReverseWS 反向ws配置修改 +// AdminDoConfigReverseWS 反向ws配置修改 func AdminDoConfigReverseWS(s *webServer, c *gin.Context) { conf := GetConf() conf.ReverseServers[0].ReverseAPIURL = c.PostForm("reverse_api_url") @@ -609,7 +610,7 @@ func AdminDoConfigReverseWS(s *webServer, c *gin.Context) { } } -//AdminDoConfigJSON config.hjson配置修改 +// AdminDoConfigJSON config.hjson配置修改 func AdminDoConfigJSON(s *webServer, c *gin.Context) { conf := GetConf() JSON := c.PostForm("json") @@ -628,7 +629,7 @@ func AdminDoConfigJSON(s *webServer, c *gin.Context) { } } -//AdminGetConfigJSON 拉取config.hjson配置 +// AdminGetConfigJSON 拉取config.hjson配置 func AdminGetConfigJSON(s *webServer, c *gin.Context) { conf := GetConf() c.JSON(200, coolq.OK(coolq.MSG{"config": conf})) diff --git a/server/doc.go b/server/doc.go index 75e6fab..946b80f 100644 --- a/server/doc.go +++ b/server/doc.go @@ -1,2 +1,2 @@ -//Package server 包含Admin子站,HTTP,WebSocket,反向WebSocket请求处理的相关函数与结构体 +// Package server 包含Admin子站,HTTP,WebSocket,反向WebSocket请求处理的相关函数与结构体 package server diff --git a/server/http.go b/server/http.go index 8bd30d8..ea8ede5 100644 --- a/server/http.go +++ b/server/http.go @@ -36,7 +36,7 @@ type httpClient struct { var cqHTTPServer = &httpServer{} -//Debug 是否启用Debug模式 +// Debug 是否启用Debug模式 var Debug = false func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) { diff --git a/server/websocket.go b/server/websocket.go index 1447fd7..378e6d3 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -25,7 +25,7 @@ type webSocketServer struct { handshake string } -//WebSocketClient WebSocket客户端实例 +// WebSocketClient WebSocket客户端实例 type WebSocketClient struct { conf *global.GoCQReverseWebSocketConfig token string @@ -40,7 +40,7 @@ type webSocketConn struct { sync.Mutex } -//WebSocketServer 初始化一个WebSocketServer实例 +// WebSocketServer 初始化一个WebSocketServer实例 var WebSocketServer = &webSocketServer{} var upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { @@ -63,12 +63,12 @@ func (s *webSocketServer) Run(addr, authToken string, b *coolq.CQBot) { }() } -//NewWebSocketClient 初始化一个NWebSocket客户端 +// NewWebSocketClient 初始化一个NWebSocket客户端 func NewWebSocketClient(conf *global.GoCQReverseWebSocketConfig, authToken string, b *coolq.CQBot) *WebSocketClient { return &WebSocketClient{conf: conf, token: authToken, bot: b} } -//Run 运行实例 +// Run 运行实例 func (c *WebSocketClient) Run() { if !c.conf.Enabled { return