Class Bot

java.lang.Object
com.mikuac.shiro.core.Bot

public class Bot extends Object
Created on 2021/7/7.
  • Constructor Details

    • Bot

      public Bot(long selfId, org.springframework.web.socket.WebSocketSession session, ActionHandler actionHandler, List<Class<? extends BotPlugin>> pluginList, org.springframework.util.MultiValueMap<Class<? extends Annotation>,HandlerMethod> annotationHandler, Class<? extends BotMessageEventInterceptor> botMessageEventInterceptor)

      Constructor for Bot.

      Parameters:
      selfId - 机器人账号
      session - WebSocketSession
      actionHandler - ActionHandler
      pluginList - 插件列表
      annotationHandler - 注解 (key) 下的所有方法
      botMessageEventInterceptor - 消息拦截器
  • Method Details

    • sendMsg

      public ActionData<MsgId> sendMsg(AnyMessageEvent event, String msg, boolean autoEscape)
      发送消息
      Parameters:
      event - AnyMessageEvent
      msg - 要发送的内容
      autoEscape - 消息内容是否作为纯文本发送 ( 即不解析 CQ 码 ) , 只在 message 字段是字符串时有效
      Returns:
      result ActionData of MsgId
    • sendPrivateMsg

      public ActionData<MsgId> sendPrivateMsg(long userId, String msg, boolean autoEscape)
      发送私聊消息
      Parameters:
      userId - 对方 QQ 号
      msg - 要发送的内容
      autoEscape - 消息内容是否作为纯文本发送 ( 即不解析 CQ 码 ) , 只在 message 字段是字符串时有效
      Returns:
      result ActionData of MsgId
    • sendPrivateMsg

      public ActionData<MsgId> sendPrivateMsg(long groupId, long userId, String msg, boolean autoEscape)
      临时会话
      Parameters:
      groupId - 主动发起临时会话群号(机器人本身必须是管理员/群主)
      userId - 对方 QQ 号
      msg - 要发送的内容
      autoEscape - 消息内容是否作为纯文本发送 ( 即不解析 CQ 码 ) , 只在 message 字段是字符串时有效
      Returns:
      result ActionData of MsgId
    • sendGroupMsg

      public ActionData<MsgId> sendGroupMsg(long groupId, String msg, boolean autoEscape)
      发送群消息
      Parameters:
      groupId - 群号
      msg - 要发送的内容
      autoEscape - 消息内容是否作为纯文本发送 ( 即不解析 CQ 码 ) , 只在 message 字段是字符串时有效
      Returns:
      result ActionData of MsgId
    • sendGroupMsg

      public ActionData<MsgId> sendGroupMsg(long groupId, long userId, String msg, boolean autoEscape)
      发送群消息
      Parameters:
      groupId - 群号
      userId - 调用者的QQ号 , 在QQ开放平台中用于设定@对象,如果不设置此参数会导致: 在bot返回前如果被不同用户多次调用,只会@最后一次调用的用户
      msg - 要发送的内容
      autoEscape - 消息内容是否作为纯文本发送 ( 即不解析 CQ 码 ) , 只在 message 字段是字符串时有效
      Returns:
      result ActionData of MsgId
    • getGuildMemberList

      public ActionData<GuildMemberListResp> getGuildMemberList(String guildId, String nextToken)
      获取频道成员列表 由于频道人数较多(数万), 请尽量不要全量拉取成员列表, 这将会导致严重的性能问题 尽量使用 getGuildMemberProfile 接口代替全量拉取 nextToken 为空的情况下, 将返回第一页的数据, 并在返回值附带下一页的 token
      Parameters:
      guildId - 频道ID
      nextToken - 翻页Token
      Returns:
      result ActionData of GuildMemberListResp
    • sendGuildMsg

      public ActionData<GuildMsgId> sendGuildMsg(String guildId, String channelId, String msg)
      发送信息到子频道
      Parameters:
      guildId - 频道 ID
      channelId - 子频道 ID
      msg - 要发送的内容
      Returns:
      result ActionData of GuildMsgId
    • getGuildMsg

      public ActionData<GetGuildMsgResp> getGuildMsg(String guildMsgId, boolean noCache)
      获取频道消息
      Parameters:
      guildMsgId - 频道 ID
      noCache - 是否使用缓存
      Returns:
      result ActionData of GetGuildMsgResp
    • getGuildServiceProfile

      public ActionData<GuildServiceProfileResp> getGuildServiceProfile()
      获取频道系统内 BOT 的资料
      Returns:
      result ActionData of GuildServiceProfileResp
    • getGuildList

      public ActionList<GuildListResp> getGuildList()
      获取频道列表
      Returns:
      result ActionList of GuildListResp
    • getGuildMetaByGuest

      public ActionData<GuildMetaByGuestResp> getGuildMetaByGuest(String guildId)
      通过访客获取频道元数据
      Parameters:
      guildId - 频道 ID
      Returns:
      result ActionData of GuildMetaByGuestResp
    • getGuildChannelList

      public ActionList<ChannelInfoResp> getGuildChannelList(String guildId, boolean noCache)
      获取子频道列表
      Parameters:
      guildId - 频道 ID
      noCache - 是否无视缓存
      Returns:
      result ActionList of ChannelInfoResp
    • getGuildMemberProfile

      public ActionData<GuildMemberProfileResp> getGuildMemberProfile(String guildId, String userId)
      单独获取频道成员信息
      Parameters:
      guildId - 频道ID
      userId - 用户ID
      Returns:
      result ActionData of GuildMemberProfileResp
    • getMsg

      public ActionData<GetMsgResp> getMsg(int msgId)
      获取消息
      Parameters:
      msgId - 消息 ID
      Returns:
      result ActionData of GetMsgResp
    • deleteMsg

      public ActionRaw deleteMsg(int msgId)
      撤回消息
      Parameters:
      msgId - 消息 ID
      Returns:
      result ActionRaw
    • setGroupKick

      public ActionRaw setGroupKick(long groupId, long userId, boolean rejectAddRequest)
      群组踢人
      Parameters:
      groupId - 群号
      userId - 要踢的 QQ 号
      rejectAddRequest - 拒绝此人的加群请求 (默认false)
      Returns:
      result ActionRaw
    • setGroupBan

      public ActionRaw setGroupBan(long groupId, long userId, int duration)
      群组单人禁言
      Parameters:
      groupId - 群号
      userId - 要禁言的 QQ 号
      duration - 禁言时长, 单位秒, 0 表示取消禁言 (默认30 * 60)
      Returns:
      result ActionRaw
    • setGroupWholeBan

      public ActionRaw setGroupWholeBan(long groupId, boolean enable)
      全体禁言
      Parameters:
      groupId - 群号
      enable - 是否禁言(默认True,False为取消禁言)
      Returns:
      result ActionRaw
    • setGroupAdmin

      public ActionRaw setGroupAdmin(long groupId, long userId, boolean enable)
      群组设置管理员
      Parameters:
      groupId - 群号
      userId - 要设置管理员的 QQ 号
      enable - true 为设置,false 为取消
      Returns:
      result ActionRaw
    • setGroupAnonymous

      public ActionRaw setGroupAnonymous(long groupId, boolean enable)
      群组匿名
      Parameters:
      groupId - 群号
      enable - 是否允许匿名聊天
      Returns:
      result ActionRaw
    • setGroupCard

      public ActionRaw setGroupCard(long groupId, long userId, String card)
      设置群名片(群备注)
      Parameters:
      groupId - 群号
      userId - 要设置的 QQ 号
      card - 群名片内容,不填或空字符串表示删除群名片
      Returns:
      result ActionRaw
    • setGroupName

      public ActionRaw setGroupName(long groupId, String groupName)
      设置群名
      Parameters:
      groupId - 群号
      groupName - 新群名
      Returns:
      result ActionRaw
    • setGroupLeave

      public ActionRaw setGroupLeave(long groupId, boolean isDismiss)
      退出群组
      Parameters:
      groupId - 群号
      isDismiss - 是否解散, 如果登录号是群主, 则仅在此项为 true 时能够解散
      Returns:
      result ActionRaw
    • setGroupSpecialTitle

      public ActionRaw setGroupSpecialTitle(long groupId, long userId, String specialTitle, int duration)
      设置群组专属头衔
      Parameters:
      groupId - 群号
      userId - 要设置的 QQ 号
      specialTitle - 专属头衔,不填或空字符串表示删除专属头衔
      duration - 专属头衔有效期,单位秒,-1 表示永久,不过此项似乎没有效果,可能是只有某些特殊的时间长度有效,有待测试
      Returns:
      result ActionRaw
    • setFriendAddRequest

      public ActionRaw setFriendAddRequest(String flag, boolean approve, String remark)
      处理加好友请求
      Parameters:
      flag - 加好友请求的 flag(需从上报的数据中获得)
      approve - 是否同意请求(默认为true)
      remark - 添加后的好友备注(仅在同意时有效)
      Returns:
      result ActionRaw
    • setGroupAddRequest

      public ActionRaw setGroupAddRequest(String flag, String subType, boolean approve, String reason)
      处理加群请求/邀请
      Parameters:
      flag - 加群请求的 flag(需从上报的数据中获得)
      subType - add 或 invite,请求类型(需要和上报消息中的 sub_type 字段相符)
      approve - 是否同意请求/邀请
      reason - 拒绝理由(仅在拒绝时有效)
      Returns:
      result ActionRaw
    • getLoginInfo

      public ActionData<LoginInfoResp> getLoginInfo()
      获取登录号信息
      Returns:
      result ActionData of @LoginInfoResp
    • getStrangerInfo

      public ActionData<StrangerInfoResp> getStrangerInfo(long userId, boolean noCache)
      获取陌生人信息
      Parameters:
      userId - QQ 号
      noCache - 是否不使用缓存(使用缓存可能更新不及时,但响应更快)
      Returns:
      result ActionData of StrangerInfoResp
    • getFriendList

      public ActionList<FriendInfoResp> getFriendList()
      获取好友列表
      Returns:
      result ActionList of FriendInfoResp
    • deleteFriend

      public ActionRaw deleteFriend(long friendId)
      删除好友
      Parameters:
      friendId - 好友 QQ 号
      Returns:
      result ActionRaw
    • getGroupInfo

      public ActionData<GroupInfoResp> getGroupInfo(long groupId, boolean noCache)
      获取群信息
      Parameters:
      groupId - 群号
      noCache - 是否不使用缓存(使用缓存可能更新不及时,但响应更快)
      Returns:
      result ActionData of GroupInfoResp
    • getGroupList

      public ActionList<GroupInfoResp> getGroupList()
      获取群列表
      Returns:
      result ActionList of GroupInfoResp
    • getGroupMemberInfo

      public ActionData<GroupMemberInfoResp> getGroupMemberInfo(long groupId, long userId, boolean noCache)
      获取群成员信息
      Parameters:
      groupId - 群号
      userId - QQ 号
      noCache - 是否不使用缓存(使用缓存可能更新不及时,但响应更快)
      Returns:
      result ActionData of GroupMemberInfoResp
    • getGroupMemberList

      public ActionList<GroupMemberInfoResp> getGroupMemberList(long groupId)
      获取群成员列表
      Parameters:
      groupId - 群号
      Returns:
      result ActionList of GroupMemberInfoResp
    • getGroupHonorInfo

      public ActionData<GroupHonorInfoResp> getGroupHonorInfo(long groupId, String type)
      获取群荣誉信息
      Parameters:
      groupId - 群号
      type - 要获取的群荣誉类型, 可传入 talkative performer legend strong_newbie emotion 以分别获取单个类型的群荣誉数据, 或传入 all 获取所有数据
      Returns:
      result ActionData of GroupHonorInfoResp
    • canSendImage

      public ActionData<BooleanResp> canSendImage()
      检查是否可以发送图片
      Returns:
      result ActionData of BooleanResp
    • canSendRecord

      public ActionData<BooleanResp> canSendRecord()
      检查是否可以发送语音
      Returns:
      result ActionData of BooleanResp
    • setGroupPortrait

      public ActionRaw setGroupPortrait(long groupId, String file, int cache)
      设置群头像 目前这个API在登录一段时间后因cookie失效而失效, 请考虑后使用
      Parameters:
      groupId - 群号
      file - 图片文件名(支持绝对路径,网络URL,Base64编码)
      cache - 表示是否使用已缓存的文件 (通过网络URL发送时有效, 1表示使用缓存, 0关闭关闭缓存, 默认为1)
      Returns:
      result ActionRaw
    • checkUrlSafely

      public ActionData<CheckUrlSafelyResp> checkUrlSafely(String url)
      检查链接安全性 安全等级, 1: 安全 2: 未知 3: 危险
      Parameters:
      url - 需要检查的链接
      Returns:
      result ActionData of CheckUrlSafelyResp
    • sendGroupNotice

      public ActionRaw sendGroupNotice(long groupId, String content)
      发送群公告
      Parameters:
      groupId - 群号
      content - 公告内容
      Returns:
      result ActionRaw
    • getGroupAtAllRemain

      public ActionData<GroupAtAllRemainResp> getGroupAtAllRemain(long groupId)
      获取群 @全体成员 剩余次数
      Parameters:
      groupId - 群号
      Returns:
      result ActionData of GroupAtAllRemainResp
    • uploadGroupFile

      public ActionRaw uploadGroupFile(long groupId, String file, String name, String folder)
      上传群文件 在不提供 folder 参数的情况下默认上传到根目录 只能上传本地文件, 需要上传 http 文件的话请先下载到本地
      Parameters:
      groupId - 群号
      file - 本地文件路径
      name - 储存名称
      folder - 父目录ID
      Returns:
      result ActionRaw
    • uploadGroupFile

      public ActionRaw uploadGroupFile(long groupId, String file, String name)
      上传群文件 在不提供 folder 参数的情况下默认上传到根目录 只能上传本地文件, 需要上传 http 文件的话请先下载到本地
      Parameters:
      groupId - 群号
      file - 本地文件路径
      name - 储存名称
      Returns:
      result ActionRaw
    • setGroupAnonymousBan

      public ActionRaw setGroupAnonymousBan(long groupId, Anonymous anonymous, int duration)
      群组匿名用户禁言
      Parameters:
      groupId - 群号
      anonymous - 要禁言的匿名用户对象(群消息上报的 anonymous 字段)
      duration - 禁言时长,单位秒,无法取消匿名用户禁言
      Returns:
      result ActionRaw
    • setGroupAnonymousBan

      public ActionRaw setGroupAnonymousBan(long groupId, String flag, int duration)
      群组匿名用户禁言
      Parameters:
      groupId - 群号
      flag - 要禁言的匿名用户的 flag(需从群消息上报的数据中获得)
      duration - 禁言时长,单位秒,无法取消匿名用户禁言
      Returns:
      result ActionRaw
    • downloadFile

      public ActionData<DownloadFileResp> downloadFile(String url, int threadCount, String headers)
      调用 go cq http 下载文件
      Parameters:
      url - 链接地址
      threadCount - 下载线程数
      headers - 自定义请求头
      Returns:
      result ActionData of DownloadFileResp
    • downloadFile

      public ActionData<DownloadFileResp> downloadFile(String url)
      调用 go cq http 下载文件
      Parameters:
      url - 链接地址
      Returns:
      result ActionData of DownloadFileResp
    • sendGroupForwardMsg

      public ActionData<MsgId> sendGroupForwardMsg(long groupId, List<Map<String,Object>> msg)
      发送合并转发 (群)
      Parameters:
      groupId - 群号
      msg - 自定义转发消息 (可使用 ShiroUtils.generateForwardMsg() 方法创建) 参考文档
      Returns:
      result ActionRaw
    • getGroupRootFiles

      public ActionData<GroupFilesResp> getGroupRootFiles(long groupId)
      获取群根目录文件列表
      Parameters:
      groupId - 群号
      Returns:
      result ActionData of GroupFilesResp
    • getGroupFilesByFolder

      public ActionData<GroupFilesResp> getGroupFilesByFolder(long groupId, String folderId)
      获取群子目录文件列表
      Parameters:
      groupId - 群号
      folderId - 文件夹ID 参考 Folder 对象
      Returns:
      result ActionData of GroupFilesResp
    • customRequest

      public ActionData customRequest(ActionPath action, Map<String,Object> params)
      自定义请求
      Parameters:
      action - 请求路径
      params - 请求参数
      Returns:
      result ActionData
    • getEssenceMsgList

      public ActionList<EssenceMsgResp> getEssenceMsgList(long groupId)
      获取精华消息列表
      Parameters:
      groupId - 群号
      Returns:
      result ActionList of EssenceMsgResp
    • setEssenceMsg

      public ActionRaw setEssenceMsg(int msgId)
      设置精华消息
      Parameters:
      msgId - 消息 ID
      Returns:
      result ActionRaw
    • deleteEssenceMsg

      public ActionRaw deleteEssenceMsg(int msgId)
      移出精华消息
      Parameters:
      msgId - 消息 ID
      Returns:
      result ActionRaw
    • setBotProfile

      public ActionRaw setBotProfile(String nickname, String company, String email, String college, String personalNote)
      设置机器人账号资料
      Parameters:
      nickname - 昵称
      company - 公司
      email - 邮箱
      college - 学校
      personalNote - 个性签名
      Returns:
      result ActionRaw
    • sendPrivateForwardMsg

      public ActionData<MsgId> sendPrivateForwardMsg(long userId, List<Map<String,Object>> msg)
      发送合并转发 (私聊)
      Parameters:
      userId - 目标用户
      msg - 自定义转发消息 (可使用 ShiroUtils.generateForwardMsg() 方法创建) 参考文档
      Returns:
      result ActionRaw
    • sendForwardMsg

      public ActionData<MsgId> sendForwardMsg(AnyMessageEvent event, List<Map<String,Object>> msg)
      发送合并转发
      Parameters:
      event - 事件
      msg - 自定义转发消息 (可使用 ShiroUtils.generateForwardMsg() 方法创建) 参考文档
      Returns:
      result ActionRaw
    • getWordSlices

      public ActionData<WordSlicesResp> getWordSlices(String content)
      获取中文分词
      Parameters:
      content - 内容
      Returns:
      result ActionData of WordSlicesResp
    • getOnlineClients

      public ActionData<ClientsResp> getOnlineClients(boolean noCache)
      获取当前账号在线客户端列表
      Parameters:
      noCache - 是否无视缓存
      Returns:
      result ActionData of ClientsResp
    • ocrImage

      public ActionData<OcrResp> ocrImage(String image)
      图片 OCR
      Parameters:
      image - 图片ID
      Returns:
      result ActionData of OcrResp
    • uploadPrivateFile

      public ActionRaw uploadPrivateFile(long userId, String file, String name)
      私聊发送文件
      Parameters:
      userId - 目标用户
      file - 本地文件路径
      name - 文件名
      Returns:
      result ActionRaw
    • sendGroupSign

      public ActionRaw sendGroupSign(long groupId)
      群打卡
      Parameters:
      groupId - 群号
      Returns:
      result ActionRaw
    • deleteUnidirectionalFriend

      public ActionRaw deleteUnidirectionalFriend(long userId)
      删除单向好友
      Parameters:
      userId - QQ号
      Returns:
      result ActionRaw
    • getUnidirectionalFriendList

      public ActionList<UnidirectionalFriendListResp> getUnidirectionalFriendList()
      获取单向好友列表
      Returns:
      result ActionList of UnidirectionalFriendListResp
    • getGroupFileUrl

      public ActionData<UrlResp> getGroupFileUrl(long groupId, String fileId, int busId)
      获取群文件资源链接
      Parameters:
      groupId - 群号
      fileId - 文件ID
      busId - 文件类型
      Returns:
      result ActionData of UrlResp
    • createGroupFileFolder

      public ActionRaw createGroupFileFolder(long groupId, String folderName)
      创建群文件文件夹
      Parameters:
      groupId - 群号
      folderName - 文件夹名
      Returns:
      result ActionRaw
    • deleteGroupFileFolder

      public ActionRaw deleteGroupFileFolder(long groupId, String folderId)
      删除群文件文件夹
      Parameters:
      groupId - 群号
      folderId - 文件夹ID
      Returns:
      result ActionRaw
    • deleteGroupFile

      public ActionRaw deleteGroupFile(long groupId, String fileId, int busId)
      删除群文件
      Parameters:
      groupId - 群号
      fileId - 文件ID
      busId - 文件类型
      Returns:
      result ActionRaw
    • sendLike

      public ActionRaw sendLike(long userId, int times)
      好友点赞
      Parameters:
      userId - 目标用户
      times - 点赞次数(每个好友每天最多 10 次,机器人为 Super VIP 则提高到 20次)
      Returns:
      result ActionRaw
    • getStatus

      public GetStatusResp getStatus()
      获取状态
      Returns:
      result GetStatusResp
    • getSelfId

      public long getSelfId()
    • setSelfId

      public void setSelfId(long selfId)
    • getSession

      public org.springframework.web.socket.WebSocketSession getSession()
    • setSession

      public void setSession(org.springframework.web.socket.WebSocketSession session)
    • getPluginList

      public List<Class<? extends BotPlugin>> getPluginList()
    • setPluginList

      public void setPluginList(List<Class<? extends BotPlugin>> pluginList)
    • getAnnotationHandler

      public org.springframework.util.MultiValueMap<Class<? extends Annotation>,HandlerMethod> getAnnotationHandler()
    • setAnnotationHandler

      public void setAnnotationHandler(org.springframework.util.MultiValueMap<Class<? extends Annotation>,HandlerMethod> annotationHandler)
    • getBotMessageEventInterceptor

      public Class<? extends BotMessageEventInterceptor> getBotMessageEventInterceptor()
    • setBotMessageEventInterceptor

      public void setBotMessageEventInterceptor(Class<? extends BotMessageEventInterceptor> botMessageEventInterceptor)