Skip to content

Commit

Permalink
基础bot接口设计,部分重构,去掉了guild这个东西
Browse files Browse the repository at this point in the history
  • Loading branch information
kyokukong committed Sep 19, 2024
1 parent 0445eca commit 3069afa
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 21 deletions.
96 changes: 96 additions & 0 deletions adapter/bot.go
Original file line number Diff line number Diff line change
@@ -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 // 删除群组文件夹
}
5 changes: 0 additions & 5 deletions adapter/client.go

This file was deleted.

15 changes: 8 additions & 7 deletions adapter/lagrange/lagrange_handler.go
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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: "",
Expand All @@ -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)
})
}
1 change: 0 additions & 1 deletion adapter/lagrange/tools.go
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
package lagrange

6 changes: 3 additions & 3 deletions ice/uni_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 // 事件的目标用户
}
6 changes: 3 additions & 3 deletions resource/guild.go → resource/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions resource/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3069afa

Please sign in to comment.