-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from simple-robot/dev/support-qq-group
API模块中支持群聊和c2c相关事件的intents与事件监听;支持并迁移到新的 access_token 的鉴权方式。
- Loading branch information
Showing
19 changed files
with
1,310 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
611 changes: 598 additions & 13 deletions
611
simbot-component-qq-guild-api/api/simbot-component-qq-guild-api.api
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...-guild-api/src/commonMain/kotlin/love/forte/simbot/qguild/api/app/GetAppAccessTokenApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) 2024. ForteScarlet. | ||
* | ||
* This file is part of simbot-component-qq-guild. | ||
* | ||
* simbot-component-qq-guild is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Lesser General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* simbot-component-qq-guild is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-qq-guild. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package love.forte.simbot.qguild.api.app | ||
|
||
import io.ktor.http.* | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import love.forte.simbot.qguild.ApiModel | ||
import love.forte.simbot.qguild.api.PostQQGuildApi | ||
import kotlin.jvm.JvmField | ||
import kotlin.jvm.JvmStatic | ||
|
||
|
||
/** | ||
* [获取调用凭证](https://bot.q.qq.com/wiki/develop/api-v2/dev-prepare/interface-framework/api-use.html#获取调用凭证) | ||
* | ||
* 这个API似乎是一个特殊的API,它有自己的HTTP URL: `https://bots.qq.com/app/getAppAccessToken`, | ||
* 使用时需要专门处理。 | ||
* | ||
* @author ForteScarlet | ||
*/ | ||
public class GetAppAccessTokenApi private constructor( | ||
override val body: Body | ||
) : PostQQGuildApi<AppAccessToken>() { | ||
public companion object Factory { | ||
public const val HTTP_URL_STRING: String = "https://bots.qq.com" | ||
|
||
@JvmField | ||
public val httpUrl: Url = Url(HTTP_URL_STRING) | ||
|
||
private val PATH = arrayOf("app", "getAppAccessToken") | ||
|
||
/** | ||
* Create [GetAppAccessTokenApi]. | ||
*/ | ||
@JvmStatic | ||
public fun create( | ||
appId: String, | ||
clientSecret: String | ||
): GetAppAccessTokenApi = GetAppAccessTokenApi(Body(appId, clientSecret)) | ||
} | ||
|
||
|
||
override val resultDeserializationStrategy: DeserializationStrategy<AppAccessToken> | ||
get() = AppAccessToken.serializer() | ||
|
||
override val path: Array<String> | ||
get() = PATH | ||
|
||
override fun createBody(): Any = body | ||
|
||
override val url: Url = URLBuilder(httpUrl).apply { | ||
appendEncodedPathSegments(components = PATH) | ||
}.build() | ||
|
||
@Serializable | ||
public data class Body( | ||
val appId: String, | ||
val clientSecret: String | ||
) | ||
} | ||
|
||
/** | ||
* Result of [GetAppAccessTokenApi] | ||
* @property accessToken 获取到的凭证。 | ||
* @property expiresIn 凭证有效时间,单位:秒。目前是7200秒之内的值。 | ||
*/ | ||
@ApiModel | ||
@Serializable | ||
public data class AppAccessToken( | ||
@SerialName("access_token") | ||
val accessToken: String, | ||
@SerialName("expires_in") | ||
val expiresIn: Int, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...onent-qq-guild-api/src/commonMain/kotlin/love/forte/simbot/qguild/event/c2cManagements.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2024. ForteScarlet. | ||
* | ||
* This file is part of simbot-component-qq-guild. | ||
* | ||
* simbot-component-qq-guild is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Lesser General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* simbot-component-qq-guild is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-qq-guild. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package love.forte.simbot.qguild.event | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
|
||
/** | ||
* @property timestamp 添加时间戳 | ||
* @property openid 用户openid | ||
*/ | ||
@Serializable | ||
public data class C2CManagementData( | ||
val timestamp: Int, | ||
val openid: String, | ||
) | ||
|
||
/** | ||
* 用户模块-用户管理相关事件。 | ||
* [data] 类型为 [C2CManagementData] | ||
*/ | ||
public sealed class C2CManagementDispatch : Signal.Dispatch() { | ||
abstract override val data: C2CManagementData | ||
} | ||
|
||
/** | ||
* [用户添加机器人](https://bot.q.qq.com/wiki/develop/api-v2/server-inter/user/manage/event.html#用户添加机器人) | ||
* | ||
* 触发场景 用户添加机器人'好友'到消息列表 | ||
*/ | ||
@Serializable | ||
@SerialName(EventIntents.GroupAndC2CEvent.FRIEND_ADD_TYPE) | ||
public data class FriendAdd( | ||
override val s: Long, | ||
@SerialName("d") | ||
override val data: C2CManagementData | ||
) : C2CManagementDispatch() | ||
|
||
/** | ||
* [用户删除机器人](https://bot.q.qq.com/wiki/develop/api-v2/server-inter/user/manage/event.html#用户删除机器人) | ||
* | ||
* 触发场景 用户删除机器人'好友' | ||
*/ | ||
@Serializable | ||
@SerialName(EventIntents.GroupAndC2CEvent.FRIEND_DEL_TYPE) | ||
public data class FriendDel( | ||
override val s: Long, | ||
@SerialName("d") | ||
override val data: C2CManagementData | ||
) : C2CManagementDispatch() | ||
|
||
/** | ||
* [拒绝机器人主动消息](https://bot.q.qq.com/wiki/develop/api-v2/server-inter/user/manage/event.html#拒绝机器人主动消息) | ||
* | ||
* 触发场景 用户在机器人资料卡手动关闭"主动消息"推送 | ||
*/ | ||
@Serializable | ||
@SerialName(EventIntents.GroupAndC2CEvent.C2C_MSG_REJECT_TYPE) | ||
public data class C2CMsgReject( | ||
override val s: Long, | ||
@SerialName("d") | ||
override val data: C2CManagementData | ||
) : C2CManagementDispatch() | ||
|
||
/** | ||
* [允许机器人主动消息](https://bot.q.qq.com/wiki/develop/api-v2/server-inter/user/manage/event.html#允许机器人主动消息) | ||
* | ||
* 触发场景 用户在机器人资料卡手动开启"主动消息"推送开关 | ||
*/ | ||
@Serializable | ||
@SerialName(EventIntents.GroupAndC2CEvent.C2C_MSG_RECEIVE_TYPE) | ||
public data class C2CMsgReceive( | ||
override val s: Long, | ||
@SerialName("d") | ||
override val data: C2CManagementData | ||
) : C2CManagementDispatch() |
Oops, something went wrong.