diff --git a/adapter/bot.go b/adapter/bot.go new file mode 100644 index 0000000..f4d1b4b --- /dev/null +++ b/adapter/bot.go @@ -0,0 +1,96 @@ +package adapter + +import ( + "github.com/Iceinu-Project/iceinu/elements" + "github.com/Iceinu-Project/iceinu/resource" +) + +// Bot Iceinu的客户端接口API,用于实现iceinu对平台客户端的直接操作 +type Bot interface { + // 首先是基于Satori标准的API + // 这部分可以参考Satori文档的资源部分,但是有一定的不同 + // 比如没有直接支持分页这个东西,方便使用 + // https://satori.js.org/zh-CN/resources/channel.html + + GetChannel(channelId string) *resource.Channel + GetChannelList(groupId string) []*resource.Channel + CreateChannel(groupId string, data *resource.Channel) (*resource.Channel, error) + UpdateChannel(groupId string, data *resource.Channel) error + DeleteChannel(channelId string) error + MuteChannel(channelId string, duration uint32) error + CreateUserChannel(userId string, groupId string) (*resource.Channel, error) + + GetGroup(groupId string) *resource.Group + GetGroupList() []*resource.Group + ApproveGroupInvite(messageId string, approve bool, comment string) error + + GetGroupMember(groupId string, userId string) *resource.GroupMember + GetGroupMemberList(groupId string) []*resource.GroupMember + KickGroupMember(groupId string, userId string, permanent bool) error + MuteGroupMember(groupId string, userId string, duration uint32) error + ApproveGroupRequest(messageId string, approve bool, comment string) error + + SetGroupMemberRole(groupId string, userId string, roleId string) error + UnsetGroupMemberRole(groupId string, userId string, roleId string) error + GetGroupRoleList(groupId string) + CreateGroupRole(groupId string, role *resource.GroupRole) (*resource.GroupRole, error) + UpdateGroupRole(groupId string, roleId string, role *resource.GroupRole) error + DeleteGroupRole(groupId string, roleId string) error + + GetLoginInfo() *resource.Login + + SendContent(channelId string, content string) (*resource.Message, error) + GetMessage(channelId string, messageId string) (*resource.Message, error) + RecallMessage(channelId string, messageId string) error + UpdateMessage(channelId string, messageId string, content string) error + GetMessageList(channelId string, limit uint32, order bool) []*resource.Message + + CreateReaction(channelId string, messageId string, emoji string) error + DeleteReaction(channelId string, messageId string, emoji string, userId string) error + ClearReaction(channelId string, messageId string, emoji string) + GetReactionList(channelId string, messageId string, emoji string) []resource.User + + GetUser(userId string) *resource.User + GetFriendList() []*resource.User + ApproveFriendRequest(messageId string, approve string, comment string) error + + // Iceinu的特有API + // 其中一部分是对各个平台功能的扩展适配,还有一部分是其他功能的快捷方式 + + Send(elements []elements.IceinuMessageElement) (*resource.Message, error) // 直接发送Iceinu通用元素 + SendSatori(satori string) (*resource.Message, error) // 发送Satori XHTML格式的消息字符串,自动解析成通用元素并发送 + SendPoke(userId string) error // 发送戳一戳 + SendGroupPoke(groupId string) error // 发送群组戳一戳 + SendChannelPoke(channelId string) error // 发送频道戳一戳 + + GetSelfUserId() string // 获取自己的用户ID + GetSelfUserName() string // 获取自己的用户名 + GetSelfAvatarUrl() string // 获取自己的头像URL + GetSeldUserNickname() string // 获取自己的昵称 + + RefreshUserListCache() error // 刷新用户列表 + RefreshGroupListCache() error // 刷新群组列表 + RefreshGroupMemberCache(groupId string, userId string) error // 刷新指定群组的指定成员的信息 + RefreshGroupAllMembersCache(groupId string) error // 刷新指定群组所有成员的信息 + RefreshChannelListCache(groupId string) error // 刷新指定群组的频道列表 + + RenameGroup(groupId string, name string) error // 重命名群组 + RenameGroupMember(groupId string, userId string, nickname string) error // 重命名群组成员 + RemarkGroup(groupId string, remark string) error // 设置群组备注 + SetGroupGlobalMute(groupId string, mute bool) error // 设置群组全员禁言 + LeaveGroup(groupId string) error // 退出群组 + SetGroupMemberTitle(groupId string, userId string, title string) error // 给群组成员设置头衔 + + // 这部分功能接口设计主要来自LagrangeGo,但是也可能在其他NTQQ平台上实现 + + UploadChannelFile(channelId string, filePath string) error // 向频道上传文件 + UploadGroupFile(groupId string, filePath string, targetFilePath string) error // 向群组上传文件 + GetGroupFileSystemInfo(groupId string) interface{} // 获取群组文件系统信息(暂未确定) + GetGroupFilesByFolder(groupId string, folderId string) interface{} // 获取群组文件夹内的文件列表(暂未确定) + GetGroupRootFiles(groupId string) interface{} // 获取群组根目录文件列表(暂未确定) + MoveGroupFile(groupId string, fileId string, parentFolder string, targetFolderId string) error // 移动群组文件 + DeleteGroupFile(groupId string, fileId string) error // 删除群组文件 + CreateGroupFolder(groupId string, folderName string, parentFolder string) error // 创建群组文件夹 + RenameGroupFolder(groupId string, folderId string, newFolderName string) error // 重命名群组文件夹 + DeleteGroupFolder(groupId string, folderId string) error // 删除群组文件夹 +} diff --git a/adapter/client.go b/adapter/client.go deleted file mode 100644 index 39ca2b1..0000000 --- a/adapter/client.go +++ /dev/null @@ -1,5 +0,0 @@ -package adapter - -// IceClient Iceinu的客户端接口,用于实现iceinu对平台客户端的直接操作 -type IceClient interface { -} diff --git a/adapter/lagrange/lagrange_handler.go b/adapter/lagrange/lagrange_handler.go index abbc417..0d2abbb 100644 --- a/adapter/lagrange/lagrange_handler.go +++ b/adapter/lagrange/lagrange_handler.go @@ -1,15 +1,16 @@ package lagrange import ( - "github.com/Iceinu-Project/iceinu/logger" - "github.com/Iceinu-Project/iceinu/resource" - "github.com/Iceinu-Project/iceinu/utils" - "github.com/LagrangeDev/LagrangeGo/client" - "github.com/LagrangeDev/LagrangeGo/message" "strconv" "time" + "github.com/LagrangeDev/LagrangeGo/client" + "github.com/LagrangeDev/LagrangeGo/message" + "github.com/Iceinu-Project/iceinu/ice" + "github.com/Iceinu-Project/iceinu/logger" + "github.com/Iceinu-Project/iceinu/resource" + "github.com/Iceinu-Project/iceinu/utils" ) func SetAllHandler() { @@ -56,7 +57,7 @@ func SetAllHandler() { Name: event.GroupName, ParentId: "", }, - Guild: &resource.Guild{ + Group: &resource.Group{ Id: strconv.Itoa(int(event.GroupUin)), Name: event.GroupName, Avatar: "", @@ -74,7 +75,7 @@ func SetAllHandler() { IsBot: false, }, } - logger.Infof("[群聊][来自群%s][%s]%s:%s", e.Guild.Id, e.Operator.Id, e.Operator.Nickname, utils.SatorizeIceElements(e.Message.MessageElements)) + logger.Infof("[群聊][来自群%s][%s]%s:%s", e.Group.Id, e.Operator.Id, e.Operator.Nickname, utils.SatorizeIceElements(e.Message.MessageElements)) ice.Bus.Publish("GroupMessageEvent", &e) }) } diff --git a/adapter/lagrange/tools.go b/adapter/lagrange/tools.go index a6f3af7..e415e26 100644 --- a/adapter/lagrange/tools.go +++ b/adapter/lagrange/tools.go @@ -1,2 +1 @@ package lagrange - diff --git a/ice/uni_events.go b/ice/uni_events.go index 5c73a35..307e158 100644 --- a/ice/uni_events.go +++ b/ice/uni_events.go @@ -18,11 +18,11 @@ type PlatformEvent struct { Argv *resource.Argv // 交互指令 Button *resource.Button // 交互按钮 Channel *resource.Channel // 事件所属的频道 - Guild *resource.Guild // 事件所属的群组 + Group *resource.Group // 事件所属的群组 Login *resource.Login // 事件的登录信息 - Member *resource.GuildMember // 事件的目标成员 + Member *resource.GroupMember // 事件的目标成员 Message *resource.Message // 事件的消息 Operator *resource.User // 事件的操作者 - Role *resource.GuildRole // 事件的目标角色 + Role *resource.GroupRole // 事件的目标角色 User *resource.User // 事件的目标用户 } diff --git a/resource/guild.go b/resource/group.go similarity index 76% rename from resource/guild.go rename to resource/group.go index 707c15d..52af9b5 100644 --- a/resource/guild.go +++ b/resource/group.go @@ -2,20 +2,20 @@ package resource import "time" -type Guild struct { +type Group struct { Id string // 群组ID Name string // 群组名称 Avatar string // 群组头像 } -type GuildMember struct { +type GroupMember struct { User *User Nickname string Avatar string JoinedAt time.Time } -type GuildRole struct { +type GroupRole struct { Id string Name string } diff --git a/resource/message.go b/resource/message.go index 78f7126..0845e74 100644 --- a/resource/message.go +++ b/resource/message.go @@ -9,8 +9,8 @@ type Message struct { Id string Content string Channel *Channel - Guild *Guild - Member *GuildMember + Group *Group + Member *GroupMember User *User CreatedAt time.Time UpdatedAt time.Time