QGBot

一个 QQ频道Bot 的 simbot组件实现接口, 是一个具有功能的 QQ频道组件Bot。

AppID 与 用户ID

QGBotid 是用于连接服务器的 appId 而并非系统用户ID。 如果希望获取bot的 用户ID, 至少执行过一次 QGBot.start 后通过 userId 获取, 或者通过 me 实时查询。

Note: QGBot仅由内部实现,对外不稳定

Author

ForteScarlet

Properties

Link copied to clipboard
abstract val avatar: String

bot的头像

Link copied to clipboard
abstract override val component: QQGuildComponent

QQ频道的 组件 对象实例。

Link copied to clipboard
open override val contactRelation: ContactRelation?

QQ好友、单聊相关内容没有能支持获取它们的API, 始终得到 null

Link copied to clipboard
abstract override val groupRelation: QGGroupRelation

QQ群相关内容的操作。

Link copied to clipboard
abstract override val guildRelation: QGGuildRelation

对频道服务器、以及频道、分组等相关内容的操作。

Link copied to clipboard
open override val id: ID

当前bot的 appId

Link copied to clipboard
abstract override val name: String

bot的用户名

Link copied to clipboard
abstract val source: Bot

在QQ频道标准库中的原始Bot类型。

Link copied to clipboard
abstract val userId: ID

得到当前bot的用户ID。

Inherited properties

Link copied to clipboard
Link copied to clipboard
abstract val isActive: Boolean
Link copied to clipboard
abstract val isCompleted: Boolean
Link copied to clipboard
abstract val isStarted: Boolean

Functions

Link copied to clipboard
open suspend fun emitEvent(payload: String): EmitResult
open suspend fun emitEvent(payload: String, options: EmitEventOptions? = null): EmitResult

主动推送一个事件原文。 可用于在 webhook 模式下推送事件。

Link copied to clipboard

执行(请求) api 并得到原始的响应 HttpResponse.

Link copied to clipboard
open suspend fun <R : Any> executeData(api: QQGuildApi<R>): R

执行(请求) api 并得到响应体 R.

Link copied to clipboard
open suspend fun executeText(api: QQGuildApi<*>): String

执行(请求) api 并得到响应体字符串.

Link copied to clipboard
abstract infix override fun isMe(id: ID): Boolean

QQ机器人有两个可能的唯一标识:作为bot的 app id 以及在系统中作为用户的 user id.

Link copied to clipboard
open override fun isMention(event: Event): Boolean

如果事件类型为

Link copied to clipboard
open suspend fun me(): User

通过API实时查询当前bot对应的用户信息。

abstract suspend fun me(withCache: Boolean): User

获取当前bot对应的用户信息。

Link copied to clipboard
open suspend override fun messageFromId(id: ID): QGMessageContent

无法仅根据消息id查询引用,将始终抛出 UnsupportedOperationException。 考虑使用 messageFromReference 或可提供 channelId 信息的 messageFromId

open suspend fun messageFromId(channelId: ID, messageId: ID): QGMessageContent

根据子频道ID和消息ID查询指定的文字子频道消息内容。

Link copied to clipboard

根据引用信息 reference 查询指定的文字子频道消息正文。 reference 必须是 QGReference 类型,并且不能缺失 QGReference.channelId, 因为查询消息内容除了 messageId 以外还需要 channelId 信息。

Link copied to clipboard
abstract suspend fun sendDmsTo(id: ID, text: String): QGMessageReceipt
abstract suspend fun sendDmsTo(id: ID, message: Message): QGMessageReceipt
abstract suspend fun sendDmsTo(id: ID, message: MessageContent): QGMessageReceipt

直接向目标DMS(频道私聊会话)发送消息。

Link copied to clipboard
abstract suspend fun sendTo(channelId: ID, text: String): QGMessageReceipt
abstract suspend fun sendTo(channelId: ID, message: Message): QGMessageReceipt
abstract suspend fun sendTo(channelId: ID, message: MessageContent): QGMessageReceipt

直接向目标子频道发送消息。

Link copied to clipboard
abstract suspend override fun start()

启动当前bot, 并且初始化此bot的信息。

Link copied to clipboard
abstract suspend fun uploadGroupMedia(target: ID, url: String, type: Int): QGMedia

上传一个资源为用于向QQ群发送的 QGMedia, 可用于后续的发送。

Link copied to clipboard
abstract suspend fun uploadUserMedia(target: ID, url: String, type: Int): QGMedia

上传一个资源为用于向QQ单聊发送的 QGMedia, 可用于后续的发送。

Inherited functions

Link copied to clipboard
open fun cancel()
abstract fun cancel(reason: Throwable?)
Link copied to clipboard
inline suspend fun QGBot.emitEvent(payload: String, block: EmitEventOptions.() -> Unit): EmitResult

使用 QGBot.emitEvent 推送一个外部事件,并且在 block 中配置 EmitEventOptions

Link copied to clipboard
abstract suspend fun join()
Link copied to clipboard
abstract fun onCompletion(handle: OnCompletion)
Link copied to clipboard
inline suspend fun QGBot.sendGroupMessage(openid: String, messageContent: MessageContent, crossinline onEachPre: GroupAndC2CSendBody.() -> Unit = {}, onEachPost: GroupAndC2CSendBody.() -> Unit = {}): QGMessageReceipt
Link copied to clipboard
inline suspend fun QGBot.sendMessage(channelId: String, text: String, onEachPre: MessageSendApi.Body.Builder.() -> Unit = {}, onEachPost: MessageSendApi.Body.Builder.() -> Unit = {}): QGMessageReceipt

使用当前 QGBotchannelId 通过 MessageSendApi 发送一个消息, 消息内容为通过 ContentTextEncoder.encode 转义后的无特殊含义 text 文本。

inline suspend fun QGBot.sendMessage(channelId: String, message: Message, crossinline onEachPre: MessageSendApi.Body.Builder.() -> Unit = {}, onEachPost: MessageSendApi.Body.Builder.() -> Unit = {}): QGMessageReceipt

使用当前 QGBotchannelId 通过 MessageSendApi 发送一个消息, 消息内容为 message 的解析结果。

inline suspend fun QGBot.sendMessage(channelId: String, messageContent: MessageContent, crossinline onEachPre: MessageSendApi.Body.Builder.() -> Unit = {}, onEachPost: MessageSendApi.Body.Builder.() -> Unit = {}): QGMessageReceipt

使用当前 QGBotchannelId 通过 MessageSendApi 发送一个消息, 消息内容为 messageContent 的解析结果。

Link copied to clipboard
inline suspend fun QGBot.sendUserMessage(openid: String, messageContent: MessageContent, crossinline onEachPre: GroupAndC2CSendBody.() -> Unit = {}, onEachPost: GroupAndC2CSendBody.() -> Unit = {}): QGMessageReceipt