Skip to content

Commit

Permalink
一些README;一些代码生成优化
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet committed Apr 11, 2024
1 parent c43ff11 commit d01d77b
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 11 deletions.
19 changes: 18 additions & 1 deletion .changelog/v0.0.1-dev1.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,25 @@ bot.join()
> [!note]
> 如果不配置 `longPolling`,也就是只使用 Telegram 的 webhook 的形式接收事件,
> 那么你需要自行启动一个 HTTP 服务,并将接收到的请求体的 JSON 字符串(或解析后的 `Update` 实体)提供给 bot。
> ```Kotlin
```Kotlin
val bot = ...
bot.start()

// 假设你使用 Kror Server
embeddedServer(Netty, port = 80) {
routing {
get ("/YOUR_ROUTE") {
// The `Update` JSON string.
val raw = call.receiveText()

// Push `Update` to bot. Maybe in try-catch? Myabe in launch { ... } ?
bot.pushUpdate(Update.decodeFromRawJson(raw), raw)

// respond a result to Telegram
call.respondText("""{"ok":true}""")
}
}
}.start(wait = true)
```


Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ The goal is to preserve the feel of the original API as much as possible without
Based on [API module](simbot-component-telegram-api),
for the implementation of authentication, subscription events and other related functions in bot.

The `stdlib` module can be thought of as a lightweight SDK implementation library.

This module provides an implementation of event-related functionality based on the API module,
including the ability to subscribe to events.

Expand Down
2 changes: 2 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Kotlin 多平台库,异步高效、Java友好。

基于 [API模块](simbot-component-telegram-api) 针对 bot 的鉴权、事件订阅等功能的实现。

stdlib模块可以被看作是一个轻量级的 SDK 实现库。

同样的,其目标为在提供封装的情况下尽可能地保留原始API的使用手感,不做过多的封装。

👉 [前往模块](simbot-component-telegram-stdlib) 了解更多。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ private class ComponentEventProcessor(private val environment: SymbolProcessorEn
****************************
""".trimIndent()
)
addAnnotation(
AnnotationSpec.builder(Suppress::class)
.addMember("%S, %S", "ALL", "unused")
.build()
)
indent(" ")
}.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ private class IncludeMessageElementsProcessor(val environment: SymbolProcessorEn
****************************
""".trimIndent()
)

addAnnotation(
AnnotationSpec.builder(Suppress::class)
.addMember("%S, %S", "ALL", "unused")
.build()
)
addFunction(function)
indent(" ")
}.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ private class UpdateEventProcessor(private val environment: SymbolProcessorEnvir

val file = FileSpec.builder(BOT_CLASS_PACKAGE, FILE_NAME).apply {
functions.forEach { addFunction(it) }
addAnnotation(
AnnotationSpec.builder(Suppress::class)
.addMember("%S, %S", "ALL", "unused")
.build()
)
indent(" ")
addFileComment(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ private class UpdateEventProcessor(private val environment: SymbolProcessorEnvir
val updateValuesFile = FileSpec.builder(UPDATE_PACKAGE, FILE_NAME)
.jvmMultifileClass()
.jvmName(FILE_JVM_NAME)
.addAnnotation(
AnnotationSpec.builder(Suppress::class)
.addMember("%S, %S", "ALL", "unused")
.build()
)
.addFileComment(
"""
****************************
Expand Down
6 changes: 5 additions & 1 deletion simbot-component-telegram-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ dependencies {
// add("kspCommonMainMetadata", project(":internal-processors:update-events-processor"))
}
kotlin.sourceSets.commonMain {
// kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
// solves all implicit dependency trouble and IDEs source code detection
// see https://github.com/google/ksp/issues/963#issuecomment-1894144639
tasks.withType<KspTaskMetadata> { kotlin.srcDir(destinationDirectory) }
tasks.withType<KspTaskMetadata> {
kotlin.srcDir(destinationDirectory)
}
// 这似乎没有把 `kotlin` 这层目录放进去?
}

// see https://github.com/google/ksp/issues/567#issuecomment-1510477456
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SendMessageApiTests {
with(Telegram.DefaultJson) {
val body = SendMessageApi.builder().apply {
chatId(1)
text = "forte"
text("forte")
replyMarkup(
ForceReply(
forceReply = true,
Expand All @@ -57,7 +57,7 @@ class SendMessageApiTests {
with(Telegram.DefaultJson) {
val body = SendMessageApi.builder().apply {
chatId(1)
text = "forte"
text("forte")
replyMarkup(
ReplyKeyboardMarkup(
keyboard = listOf(listOf(KeyboardButton(text = "button"))),
Expand All @@ -80,7 +80,7 @@ class SendMessageApiTests {
with(Telegram.DefaultJson) {
val body = SendMessageApi.builder().apply {
chatId(1)
text = "forte"
text("forte")
replyMarkup(
ReplyKeyboardRemove(
removeKeyboard = true,
Expand All @@ -99,7 +99,7 @@ class SendMessageApiTests {
with(Telegram.DefaultJson) {
val body = SendMessageApi.builder().apply {
chatId(1)
text = "forte"
text("forte")
replyMarkup(
InlineKeyboardMarkup(
inlineKeyboard = listOf(listOf(
Expand Down
2 changes: 0 additions & 2 deletions simbot-component-telegram-type/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,3 @@ When officials modify/extend a type (such as adding fields), binary compatibilit
(the parameters of the constructor have changed).

This change usually increments the `minor` version number.

(There are also plans to find a version to rewrite them into a more compatible form (such as the common class).)
2 changes: 0 additions & 2 deletions simbot-component-telegram-type/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,3 @@ dependencies {
当官方对API做出修改时(例如增加字段),那么数据类的二进制兼容性可能无法被保证(因为构造函数的字段发生了变化)。

这种变更通常会递增 `minor` 版本号。

(也有计划找个版本将它们改写为兼容性更好的形式(比如普通的`class`)。)

0 comments on commit d01d77b

Please sign in to comment.