mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-07-01 21:07:23 +00:00
Compare commits
1 Commits
refactor-g
...
bump-tgbot
Author | SHA1 | Date | |
---|---|---|---|
6f8ec737b4
|
@ -25,9 +25,12 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt-hotspot'
|
distribution: 'adopt-hotspot'
|
||||||
- name: Set up Gradle
|
cache: 'gradle'
|
||||||
uses: gradle/actions/setup-gradle@v4
|
- uses: gradle/wrapper-validation-action@v1
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x gradlew
|
run: chmod +x gradlew
|
||||||
- name: Build and run binary compatibility verification
|
- name: Build and run binary compatibility verification
|
||||||
run: ./gradlew apiCheck
|
uses: gradle/gradle-build-action@v2.11.0
|
||||||
|
with:
|
||||||
|
gradle-version: 'wrapper'
|
||||||
|
arguments: apiCheck
|
||||||
|
9
.github/workflows/build-and-test.yml
vendored
9
.github/workflows/build-and-test.yml
vendored
@ -24,9 +24,12 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt-hotspot'
|
distribution: 'adopt-hotspot'
|
||||||
- name: Set up Gradle
|
cache: 'gradle'
|
||||||
uses: gradle/actions/setup-gradle@v4
|
- uses: gradle/wrapper-validation-action@v1
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x gradlew
|
run: chmod +x gradlew
|
||||||
- name: Build and test
|
- name: Build and test
|
||||||
run: ./gradlew clean test
|
uses: gradle/gradle-build-action@v2.11.0
|
||||||
|
with:
|
||||||
|
gradle-version: 'wrapper'
|
||||||
|
arguments: test
|
||||||
|
12
.github/workflows/create-release.yml
vendored
12
.github/workflows/create-release.yml
vendored
@ -44,17 +44,19 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt-hotspot'
|
distribution: 'adopt-hotspot'
|
||||||
- name: Set up Gradle
|
cache: 'gradle'
|
||||||
uses: gradle/actions/setup-gradle@v4
|
- uses: gradle/wrapper-validation-action@v1
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x gradlew
|
run: chmod +x gradlew
|
||||||
- name: Build and test
|
- name: Build and test
|
||||||
uses: gradle/gradle-build-action@v3.1.0
|
uses: gradle/gradle-build-action@v2.11.0
|
||||||
run: ./gradlew clean test assembleDist
|
with:
|
||||||
|
gradle-version: 'wrapper'
|
||||||
|
arguments: clean test assembleDist
|
||||||
|
|
||||||
# 创建新的发行版本
|
# 创建新的发行版本
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
draft: true
|
draft: true
|
||||||
body_path: ${{ github.workspace }}/CURRENT_CHANGELOG.md
|
body_path: ${{ github.workspace }}/CURRENT_CHANGELOG.md
|
||||||
|
9
.github/workflows/publish-artifacts.yml
vendored
9
.github/workflows/publish-artifacts.yml
vendored
@ -20,12 +20,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt-hotspot'
|
distribution: 'adopt-hotspot'
|
||||||
- name: Set up Gradle
|
cache: 'gradle'
|
||||||
uses: gradle/actions/setup-gradle@v4
|
- uses: gradle/wrapper-validation-action@v1
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x gradlew
|
run: chmod +x gradlew
|
||||||
- name: Build and test
|
- name: Build and test
|
||||||
run: ./gradlew clean test installDist
|
uses: gradle/gradle-build-action@v2.11.0
|
||||||
|
with:
|
||||||
|
gradle-version: 'wrapper'
|
||||||
|
arguments: clean test installDist
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
- name: Set up Docker BuildX
|
- name: Set up Docker BuildX
|
||||||
|
@ -20,12 +20,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt-hotspot'
|
distribution: 'adopt-hotspot'
|
||||||
- name: Set up Gradle
|
cache: 'gradle'
|
||||||
uses: gradle/actions/setup-gradle@v4
|
- uses: gradle/wrapper-validation-action@v1
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x gradlew
|
run: chmod +x gradlew
|
||||||
- name: Build project and install Distribution package
|
- name: Build project and install Distribution package
|
||||||
run: ./gradlew clean test installDist
|
uses: gradle/gradle-build-action@v2.11.0
|
||||||
|
with:
|
||||||
|
gradle-version: 'wrapper'
|
||||||
|
arguments: installDist
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
- name: Set up Docker BuildX
|
- name: Set up Docker BuildX
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM eclipse-temurin:21-jdk-alpine
|
FROM openjdk:18
|
||||||
|
|
||||||
ENV BOT_DATA_PATH /scalabot/data/
|
ENV BOT_DATA_PATH /scalabot/data/
|
||||||
WORKDIR /scalabot/run/
|
WORKDIR /scalabot/run/
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.9.23" apply false
|
kotlin("jvm") version "1.9.10" apply false
|
||||||
id("org.jetbrains.kotlinx.kover") version "0.7.5" apply false
|
id("org.jetbrains.kotlinx.kover") version "0.7.4" apply false
|
||||||
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.14.0" apply false
|
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2" apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
@ -13,5 +13,5 @@ allprojects {
|
|||||||
|
|
||||||
}
|
}
|
||||||
group = "net.lamgc"
|
group = "net.lamgc"
|
||||||
version = "0.7.0"
|
version = "0.6.1"
|
||||||
}
|
}
|
@ -10,9 +10,9 @@ dependencies {
|
|||||||
implementation(project(":scalabot-meta"))
|
implementation(project(":scalabot-meta"))
|
||||||
implementation(project(":scalabot-extension"))
|
implementation(project(":scalabot-extension"))
|
||||||
|
|
||||||
implementation("org.slf4j:slf4j-api:2.0.11")
|
implementation("org.slf4j:slf4j-api:2.0.9")
|
||||||
implementation("io.github.microutils:kotlin-logging:3.0.5")
|
implementation("io.github.microutils:kotlin-logging:3.0.5")
|
||||||
implementation("ch.qos.logback:logback-classic:1.4.14")
|
implementation("ch.qos.logback:logback-classic:1.4.11")
|
||||||
|
|
||||||
val aetherVersion = "1.1.0"
|
val aetherVersion = "1.1.0"
|
||||||
implementation("org.eclipse.aether:aether-api:$aetherVersion")
|
implementation("org.eclipse.aether:aether-api:$aetherVersion")
|
||||||
@ -24,19 +24,19 @@ dependencies {
|
|||||||
implementation("org.apache.maven:maven-aether-provider:3.3.9")
|
implementation("org.apache.maven:maven-aether-provider:3.3.9")
|
||||||
|
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
|
||||||
implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.23")
|
implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.21")
|
||||||
implementation("com.google.code.gson:gson:2.10.1")
|
implementation("com.google.code.gson:gson:2.10.1")
|
||||||
|
|
||||||
implementation("org.jdom:jdom2:2.0.6.1")
|
implementation("org.jdom:jdom2:2.0.6.1")
|
||||||
|
|
||||||
implementation("org.telegram:telegrambots-abilities:6.9.7.1")
|
implementation("org.telegram:telegrambots-abilities:6.8.0")
|
||||||
implementation("org.telegram:telegrambots:6.9.7.1")
|
implementation("org.telegram:telegrambots:6.8.0")
|
||||||
|
|
||||||
implementation("io.prometheus:simpleclient:0.16.0")
|
implementation("io.prometheus:simpleclient:0.16.0")
|
||||||
implementation("io.prometheus:simpleclient_httpserver:0.16.0")
|
implementation("io.prometheus:simpleclient_httpserver:0.16.0")
|
||||||
|
|
||||||
testImplementation(kotlin("test"))
|
testImplementation(kotlin("test"))
|
||||||
testImplementation("io.mockk:mockk:1.13.9")
|
testImplementation("io.mockk:mockk:1.13.8")
|
||||||
testImplementation("com.github.stefanbirkner:system-lambda:1.2.1")
|
testImplementation("com.github.stefanbirkner:system-lambda:1.2.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,6 @@ import net.lamgc.scalabot.util.registerShutdownHook
|
|||||||
import org.eclipse.aether.repository.LocalRepository
|
import org.eclipse.aether.repository.LocalRepository
|
||||||
import org.telegram.telegrambots.bots.DefaultBotOptions
|
import org.telegram.telegrambots.bots.DefaultBotOptions
|
||||||
import org.telegram.telegrambots.meta.TelegramBotsApi
|
import org.telegram.telegrambots.meta.TelegramBotsApi
|
||||||
import org.telegram.telegrambots.meta.api.methods.GetMe
|
|
||||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException
|
|
||||||
import org.telegram.telegrambots.meta.generics.BotSession
|
import org.telegram.telegrambots.meta.generics.BotSession
|
||||||
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession
|
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -137,11 +135,7 @@ internal class Launcher(
|
|||||||
launchBot(botConfig)
|
launchBot(botConfig)
|
||||||
launchedCounts++
|
launchedCounts++
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (e is TelegramApiRequestException && e.errorCode == 401) {
|
log.error(e) { "机器人 `${botConfig.account.name}` 启动时发生错误." }
|
||||||
log.error { "机器人 `${botConfig.account.name}` 的 Bot Token 无效, 请检查配置: [${e.errorCode}] ${e.apiResponse}" }
|
|
||||||
} else {
|
|
||||||
log.error(e) { "机器人 `${botConfig.account.name}` 启动时发生错误." }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return if (launchedCounts != 0) {
|
return if (launchedCounts != 0) {
|
||||||
@ -207,10 +201,6 @@ internal class Launcher(
|
|||||||
extensionPackageFinders,
|
extensionPackageFinders,
|
||||||
botConfig
|
botConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
val botUser = bot.execute(GetMe())
|
|
||||||
log.debug { "已验证 Bot Token 有效性, Bot Username: ${botUser.userName}" }
|
|
||||||
|
|
||||||
botSessionMap[bot] = botApi.registerBot(bot)
|
botSessionMap[bot] = botApi.registerBot(bot)
|
||||||
log.info { "机器人 `${bot.botUsername}` 已启动." }
|
log.info { "机器人 `${bot.botUsername}` 已启动." }
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.lamgc.scalabot
|
package net.lamgc.scalabot
|
||||||
|
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import net.lamgc.scalabot.extension.BotExtensionCreateOptions
|
|
||||||
import net.lamgc.scalabot.extension.BotExtensionFactory
|
import net.lamgc.scalabot.extension.BotExtensionFactory
|
||||||
import net.lamgc.scalabot.util.getPriority
|
import net.lamgc.scalabot.util.getPriority
|
||||||
import org.eclipse.aether.artifact.Artifact
|
import org.eclipse.aether.artifact.Artifact
|
||||||
@ -123,12 +122,7 @@ internal class ExtensionLoader(
|
|||||||
for (factory in extClassLoader.serviceLoader) {
|
for (factory in extClassLoader.serviceLoader) {
|
||||||
try {
|
try {
|
||||||
val extension =
|
val extension =
|
||||||
factory.createExtensionInstance(
|
factory.createExtensionInstance(bot, getExtensionDataFolder(extensionArtifact))
|
||||||
bot, getExtensionDataFolder(extensionArtifact),
|
|
||||||
BotExtensionCreateOptions(
|
|
||||||
bot.botConfig.proxy.copy()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if (extension == null) {
|
if (extension == null) {
|
||||||
log.debug { "Factory ${factory::class.java} 创建插件时返回了 null, 已跳过. (BotName: ${bot.botUsername})" }
|
log.debug { "Factory ${factory::class.java} 创建插件时返回了 null, 已跳过. (BotName: ${bot.botUsername})" }
|
||||||
continue
|
continue
|
||||||
|
@ -29,7 +29,7 @@ internal class ScalaBot(
|
|||||||
db: DBContext,
|
db: DBContext,
|
||||||
options: DefaultBotOptions,
|
options: DefaultBotOptions,
|
||||||
extensionFinders: Set<ExtensionPackageFinder>,
|
extensionFinders: Set<ExtensionPackageFinder>,
|
||||||
val botConfig: BotConfig,
|
botConfig: BotConfig,
|
||||||
private val creatorId: Long = botConfig.account.creatorId,
|
private val creatorId: Long = botConfig.account.creatorId,
|
||||||
val accountId: Long = botConfig.account.id,
|
val accountId: Long = botConfig.account.id,
|
||||||
val extensions: Set<Artifact> = botConfig.extensions
|
val extensions: Set<Artifact> = botConfig.extensions
|
||||||
|
@ -5,7 +5,7 @@ plugins {
|
|||||||
dependencies {
|
dependencies {
|
||||||
compileOnly(project(":scalabot-extension"))
|
compileOnly(project(":scalabot-extension"))
|
||||||
|
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1")
|
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
|
||||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
|
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.lamgc.scalabot.simple;
|
package net.lamgc.scalabot.simple;
|
||||||
|
|
||||||
import net.lamgc.scalabot.extension.BotExtensionCreateOptions;
|
|
||||||
import net.lamgc.scalabot.extension.BotExtensionFactory;
|
import net.lamgc.scalabot.extension.BotExtensionFactory;
|
||||||
import org.telegram.abilitybots.api.bot.BaseAbilityBot;
|
import org.telegram.abilitybots.api.bot.BaseAbilityBot;
|
||||||
import org.telegram.abilitybots.api.util.AbilityExtension;
|
import org.telegram.abilitybots.api.util.AbilityExtension;
|
||||||
@ -10,7 +9,7 @@ import java.io.File;
|
|||||||
public class SimpleExtensionFactory implements BotExtensionFactory {
|
public class SimpleExtensionFactory implements BotExtensionFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbilityExtension createExtensionInstance(BaseAbilityBot bot, File shareDataFolder, BotExtensionCreateOptions options) {
|
public AbilityExtension createExtensionInstance(BaseAbilityBot bot, File shareDataFolder) {
|
||||||
return new SayHelloExtension(bot);
|
return new SayHelloExtension(bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,12 +7,11 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("commons-codec:commons-codec:1.16.1")
|
implementation("commons-codec:commons-codec:1.16.0")
|
||||||
api("org.telegram:telegrambots-abilities:6.9.7.1")
|
api("org.telegram:telegrambots-abilities:6.8.0")
|
||||||
api(project(":scalabot-meta"))
|
|
||||||
|
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1")
|
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
|
||||||
testImplementation("org.mockito:mockito-core:5.11.0")
|
testImplementation("org.mockito:mockito-core:5.8.0")
|
||||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
|
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
package net.lamgc.scalabot.extension;
|
|
||||||
|
|
||||||
import net.lamgc.scalabot.config.ProxyConfig;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BotExtension 创建参数.
|
|
||||||
* <p>
|
|
||||||
* 通过该类可向 {@link BotExtensionFactory} 提供更多创建 BotExtension 时可用的参数.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class BotExtensionCreateOptions {
|
|
||||||
|
|
||||||
private final ProxyConfig proxy;
|
|
||||||
|
|
||||||
public BotExtensionCreateOptions(ProxyConfig proxy) {
|
|
||||||
this.proxy = proxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProxyConfig getProxy() {
|
|
||||||
return proxy;
|
|
||||||
}
|
|
||||||
}
|
|
@ -31,34 +31,7 @@ public interface BotExtensionFactory {
|
|||||||
* <b>同一个扩展包的 Factory</b> 接收到的共享数据目录<b>都是一样的</b>,
|
* <b>同一个扩展包的 Factory</b> 接收到的共享数据目录<b>都是一样的</b>,
|
||||||
* 建议将数据存储在数据目录中, 便于数据的存储管理.
|
* 建议将数据存储在数据目录中, 便于数据的存储管理.
|
||||||
* @return 返回为该 Bot 对象创建的扩展对象, 如果不希望为该机器人提供扩展, 可返回 {@code null}.
|
* @return 返回为该 Bot 对象创建的扩展对象, 如果不希望为该机器人提供扩展, 可返回 {@code null}.
|
||||||
* @deprecated 请使用 {@link #createExtensionInstance(BaseAbilityBot, File, BotExtensionCreateOptions)},
|
|
||||||
* 该方法最迟在 1.0.0 正式版中移除.
|
|
||||||
* @since 0.0.1
|
|
||||||
*/
|
*/
|
||||||
@Deprecated(since = "0.7.0", forRemoval = true)
|
AbilityExtension createExtensionInstance(BaseAbilityBot bot, File shareDataFolder);
|
||||||
default AbilityExtension createExtensionInstance(BaseAbilityBot bot, File shareDataFolder) {
|
|
||||||
throw new UnsupportedOperationException("The method has not been implemented.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为给定的 {@link BaseAbilityBot} 对象创建扩展.
|
|
||||||
*
|
|
||||||
* <p> 如扩展无使用 {@link org.telegram.abilitybots.api.db.DBContext} 的话,
|
|
||||||
* 也可以返回扩展单例, 因为 AbilityBot 本身并不禁止多个机器人共用一个扩展对象
|
|
||||||
* (AbilityBot 只是调用了扩展中的方法来创建 Ability 对象).
|
|
||||||
*
|
|
||||||
* @param bot 机器人对象.
|
|
||||||
* @param shareDataFolder ScalaBot App 为扩展提供的共享数据目录.
|
|
||||||
* <p>路径格式为:
|
|
||||||
* <pre> $DATA_ROOT/data/extensions/{GroupId}/{ArtifactId}</pre>
|
|
||||||
* <b>同一个扩展包的 Factory</b> 接收到的共享数据目录<b>都是一样的</b>,
|
|
||||||
* 建议将数据存储在数据目录中, 便于数据的存储管理.
|
|
||||||
* @param options 创建扩展时可用的参数.
|
|
||||||
* @return 返回为该 Bot 对象创建的扩展对象, 如果不希望为该机器人提供扩展, 可返回 {@code null}.
|
|
||||||
* @since 0.7.0
|
|
||||||
*/
|
|
||||||
default AbilityExtension createExtensionInstance(BaseAbilityBot bot, File shareDataFolder, BotExtensionCreateOptions options) {
|
|
||||||
return createExtensionInstance(bot, shareDataFolder);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,13 @@ dependencies {
|
|||||||
api("org.eclipse.aether:aether-api:$aetherVersion")
|
api("org.eclipse.aether:aether-api:$aetherVersion")
|
||||||
implementation("org.eclipse.aether:aether-util:$aetherVersion")
|
implementation("org.eclipse.aether:aether-util:$aetherVersion")
|
||||||
|
|
||||||
implementation("org.telegram:telegrambots-meta:6.9.7.1")
|
implementation("org.telegram:telegrambots-meta:6.8.0")
|
||||||
|
|
||||||
api("com.google.code.gson:gson:2.10.1")
|
api("com.google.code.gson:gson:2.10.1")
|
||||||
|
|
||||||
testImplementation(kotlin("test"))
|
testImplementation(kotlin("test"))
|
||||||
testImplementation("io.mockk:mockk:1.13.9")
|
testImplementation("io.mockk:mockk:1.13.8")
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1")
|
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
|
||||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1")
|
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1")
|
||||||
|
|
||||||
dokkaHtmlPlugin("org.jetbrains.dokka:javadoc-plugin:1.9.10")
|
dokkaHtmlPlugin("org.jetbrains.dokka:javadoc-plugin:1.9.10")
|
||||||
|
Reference in New Issue
Block a user