Skip to content

Commit

Permalink
Merge pull request #1 from simple-robot/dev/main
Browse files Browse the repository at this point in the history
Release: v0.0.1-dev1
  • Loading branch information
ForteScarlet authored Apr 11, 2024
2 parents c595586 + c43ff11 commit d6ac695
Show file tree
Hide file tree
Showing 67 changed files with 2,481 additions and 267 deletions.
73 changes: 73 additions & 0 deletions .changelog/v0.0.1-dev1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
> 对应核心版本: [**v4.0.0-beta3**](https://github.com/simple-robot/simpler-robot/releases/tag/v4.0.0-beta3)

> [!warning]
> **目前版本处于 `dev` 阶段,代表此版本是一个开发预览版,可能不稳定、可能随时发生更改、且不保证可用性。**

我们欢迎并期望着您的的[反馈](https://github.com/simple-robot/simbot-component-telegram/issues)[协助](https://github.com/simple-robot/simbot-component-telegram/pulls)
感谢您的贡献与支持!

也欢迎您为我们献上一颗 `star`,这是对我们最大的鼓励与认可!

此版本在使用 `stdlib` 模块时,可以监听到所有的事件(因为Telegram所有的事件都在一个 `Update` 类型中,这还挺方便的):

```Kotlin
val bot = BotFactory.create(TOKEN) {
coroutineContext = Dispatchers.IO

// 可选地配置 engine,比如配置一个代理
apiClientEngine = CIO.create {
proxy = ProxyBuilder.http("http://127.0.0.1:7790")
}

// 配置 longPolling 的值即代表启用主动拉取事件的形式,*类似于*其他组件中那种 ws 接收事件的方式。
// 不配置、配置为 `null` 则代表不启用。
longPolling = LongPolling(
limit = 100,
timeout = 10.minutes.inWholeSeconds.toInt(),
allowedUpdates = setOf(UpdateValues.MESSAGE_NAME)
)
}

// 使用 `subscribe` 订阅所有事件、根据类型(以及名称)订阅事件
bot.subscribe { event ->
println("Event: $event")
}

// 使用 onXxx 根据某个具体事件的扩展来订阅事件,等同于订阅一个对应类型、名称的事件。
// 比如此处,订阅事件类型为 `Message` 且事件名为 `"message"` 的事件。
bot.onMessage { event, message ->
println("event: ${event}")
println("message: ${message}")
}

// 启动并挂起bot
bot.start()
bot.join()
```

> [!note]
> 如果不配置 `longPolling`,也就是只使用 Telegram 的 webhook 的形式接收事件,
> 那么你需要自行启动一个 HTTP 服务,并将接收到的请求体的 JSON 字符串(或解析后的 `Update` 实体)提供给 bot。
> ```Kotlin
```

核心组件模块(`core`模块)目前支持的事件:

- `TelegramEvent`
- `TelegramMessageRelatedEvent`
- `TelegramMessageEvent`
- `TelegramChatGroupMessageEvent`
- `TelegramSuperGroupMessageEvent`
- `TelegramChannelMessageEvent`
- `TelegramPrivateMessageEvent`
- `TelegramUnsupportedEvent` (一个兜底用的事件类型,可以借助此类型来监听到所有 `stdlib` 模块中的所有尚未提供专属类型的事件类型。)

目前:
- 发送/回复文本消息、直接借助API发送消息、直接转发消息 (`send/reply(MessageContent`)。
- 接收消息内的纯文本内容 (`MessageContent.plainText`)
- **暂不支持**解析为 `Messages` (`MessageContent.messages`)

2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 4
ij_continuation_indent_size = 8
ij_continuation_indent_size = 4
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish Release
on:
push:
tags:
- v*.**.**
- v**

env:
IS_CI: true
Expand Down
43 changes: 38 additions & 5 deletions .github/workflows/test-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- 'gradle/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: '${{ github.workflow }}-${{ github.ref }}'
cancel-in-progress: true

env:
Expand Down Expand Up @@ -45,14 +45,47 @@ jobs:
allTests
--info
--warning-mode all
# --build-cache
# -Porg.gradle.daemon=false
# -Porg.gradle.jvmargs="-Xmx4g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8"
# --build-cache
# -Porg.gradle.daemon=false
# -Porg.gradle.jvmargs="-Xmx4g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8"

- name: Upload test reports
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: test-reports-${{ matrix.os }}
name: test-reports-${{ runner.os }}
path: '**/build/reports/tests'
retention-days: 7

detekt-check:
name: Detekt check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
cache: 'gradle'

- name: Run All Tests
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: 8.5
arguments: detekt
- name: Upload detekt reports
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: detekt-reports
path: 'build/reports/detekt'
retention-days: 7

# https://detekt.dev/docs/introduction/reporting/#integration-with-github-code-scanning
# Make sure we always run this upload task,
# because the previous step may fail if there are findings.
- name: Upload SARIF to GitHub using the upload-sarif action
uses: github/codeql-action/upload-sarif@v2
if: ${{ always() }}
with:
sarif_file: 'build/reports/detekt/detekt.sarif'
24 changes: 24 additions & 0 deletions .run/runConfigurations/simbot-component-telegram [detekt].run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="simbot-component-telegram [detekt]" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="detekt" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Serialization and network requests are based on [Kotlin serialization](https://g
Provides definitions for most types in Telegram and supports serialization based on
[Kotlin Serialization](https://github.com/Kotlin/kotlinx.serialization).

👉 [Go to Modules](simbot-component-telegram-type) to learn more.
👉 [Go to the module](simbot-component-telegram-type) to learn more.

### ⭐ API module

Expand All @@ -71,7 +71,7 @@ is a simple, efficient and lightweight API implementation module.
This module provides very little extra implementation.
The goal is to preserve the feel of the original API as much as possible without overwrapping it.

👉 [Go to Modules](simbot-component-telegram-api) to learn more.
👉 [Go to the module](simbot-component-telegram-api) to learn more.

### ⭐ Stdlib module

Expand All @@ -83,7 +83,7 @@ including the ability to subscribe to events.

Again, the goal is to provide as much of the feel of the original API as possible without overwrapping it.

👉 [Go to Modules](simbot-component-telegram-stdlib) to learn more.
👉 [Go to the module](simbot-component-telegram-stdlib) to learn more.

### ⭐ Core Component module

Expand Down
50 changes: 50 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
*/


import io.gitlab.arturbosch.detekt.Detekt
import love.forte.gradle.common.core.project.setup
import love.forte.gradle.common.core.repository.Repositories
import util.isCi

plugins {
idea
`simbot-telegram-changelog-generator`
`simbot-telegram-dokka-multi-module`
`simbot-telegram-nexus-publish`
alias(libs.plugins.detekt)
}

setup(P.ComponentTelegram)
Expand Down Expand Up @@ -62,3 +65,50 @@ idea {
}
}
}


dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:${libs.versions.detekt.get()}")
}

detekt {
source.setFrom(
subprojects
// internal 处理器不管
// .filter { "internal-processors" !in it.path }
.map { it.projectDir.absoluteFile }
)

config.setFrom(rootDir.resolve("config/detekt/detekt.yml"))
baseline = file("$projectDir/config/detekt/baseline.xml")
buildUponDefaultConfig = true
parallel = true
reportsDir = rootProject.layout.buildDirectory.dir("reports/detekt").get().asFile
if (!isCi) {
autoCorrect = true
}
basePath = projectDir.absolutePath
}

// https://detekt.dev/blog/2019/03/03/configure-detekt-on-root-project/
tasks.withType<Detekt>().configureEach {
include("**/src/*Main/kotlin/**/*.kt")
include("**/src/*Main/kotlin/**/*.java")
include("**/src/*Main/java/**/*.kt")
include("**/src/*Main/java/**/*.java")
include("**/src/main/kotlin/**/*.kt")
include("**/src/main/kotlin/**/*.java")
include("**/src/main/java/**/*.kt")
include("**/src/main/java/**/*.java")

// internal 处理器不管
exclude("**/internal-processors/")
exclude("**/src/*/resources/")
exclude("**/build/")
exclude("**/*Test/kotlin/")
exclude("**/*Test/java/")
exclude("**/test/kotlin/")
exclude("**/test/java/")
exclude("**.kts")
}

9 changes: 8 additions & 1 deletion buildSrc/src/main/kotlin/R.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@
* If not, see <https://www.gnu.org/licenses/>.
*/

import love.forte.gradle.common.core.property.systemProp
import love.forte.gradle.common.core.repository.Repositories
import love.forte.gradle.common.core.repository.SimpleCredentials
import love.forte.gradle.common.publication.SonatypeContact
import org.slf4j.LoggerFactory

val logger = LoggerFactory.getLogger("Sonatype Userinfo")

private val sonatypeUserInfo by lazy {
val userInfo = love.forte.gradle.common.publication.sonatypeUserInfoOrNull


val username = systemProp(SonatypeContact.SONATYPE_USERNAME) ?: return@lazy null
val password = systemProp(SonatypeContact.SONATYPE_PASSWORD) ?: return@lazy null
logger.info("sonatype.username: {}", username)
logger.info("sonatype.password: {}", password)

if (userInfo == null) {
logger.warn("sonatype.username or sonatype.password is null, cannot config nexus publishing.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,30 @@ plugins {
`maven-publish`
}


setup(P.ComponentTelegram)

val p = project
multiplatformConfigPublishing {
project = P.ComponentTelegram
isSnapshot = project.version.toString().contains("SNAPSHOT", true)

// publishing {
// publications.withType<MavenPublication> {
// val dokkaJar = p.tasks.register("${name}DokkaJar", Jar::class) {
// group = JavaBasePlugin.DOCUMENTATION_GROUP
// description = "Assembles Kotlin docs with Dokka into a Javadoc jar"
// archiveClassifier.set("javadoc")
// from(tasks.named("dokkaHtml"))
//
// // Each archive name should be distinct, to avoid implicit dependency issues.
// // We use the same format as the sources Jar tasks.
// // https://youtrack.jetbrains.com/issue/KT-46466
// archiveBaseName.set("${archiveBaseName.get()}-${name}")
// }
// artifact(dokkaJar)
// }
// }

val jarJavadoc by tasks.registering(Jar::class) {
group = "documentation"
archiveClassifier.set("javadoc")
Expand All @@ -42,6 +58,19 @@ multiplatformConfigPublishing {
}
}


// val dokkaJar = p.tasks.register("${publication.name}DokkaJar", Jar::class) {
// group = JavaBasePlugin.DOCUMENTATION_GROUP
// description = "Assembles Kotlin docs with Dokka into a Javadoc jar"
// archiveClassifier.set("javadoc")
// from(tasks.named("dokkaHtml"))
//
// // Each archive name should be distinct, to avoid implicit dependency issues.
// // We use the same format as the sources Jar tasks.
// // https://youtrack.jetbrains.com/issue/KT-46466
// archiveBaseName.set("${archiveBaseName.get()}-${publication.name}")
// }

artifact(jarJavadoc)
releasesRepository = ReleaseRepository
snapshotRepository = SnapshotRepository
Expand All @@ -60,11 +89,29 @@ val signingTasks: TaskCollection<Sign> = tasks.withType<Sign>()
tasks.withType<PublishToMavenRepository>().configureEach {
mustRunAfter(signingTasks)
}
// TODO see https://github.com/gradle/gradle/issues/26132
// Resolves issues with .asc task output of the sign task of native targets.
// See: https://github.com/gradle/gradle/issues/26132
// And: https://youtrack.jetbrains.com/issue/KT-46466
tasks.withType<Sign>().configureEach {
val pubName = name.removePrefix("sign").removeSuffix("Publication")

// These tasks only exist for native targets, hence findByName() to avoid trying to find them for other targets

// Task ':linkDebugTest<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
tasks.findByName("linkDebugTest$pubName")?.let {
mustRunAfter(it)
}
// Task ':compileTestKotlin<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
tasks.findByName("compileTestKotlin$pubName")?.let {
mustRunAfter(it)
}
}

show()

fun show() {
//// show project info
// // show project info
logger.info(
"""
|=======================================================
Expand All @@ -74,8 +121,12 @@ fun show() {
|= project.description: {}
|= os.name: {}
|=======================================================
""".trimIndent(),
group, name, version, description, systemProp("os.name")
""".trimIndent(),
group,
name,
version,
description,
systemProp("os.name")
)
}

Expand Down
Loading

0 comments on commit d6ac695

Please sign in to comment.