Skip to content

Commit

Permalink
Rearrange project, move embedded branch into master.
Browse files Browse the repository at this point in the history
  • Loading branch information
yyuueexxiinngg committed Nov 17, 2020
1 parent deae311 commit 4c2931d
Show file tree
Hide file tree
Showing 38 changed files with 459 additions and 257 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/gradle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ jobs:
- name: Upload articact
uses: actions/upload-artifact@v2
with:
path: build/libs
name: onebot-mirai
path: onebot-mirai/build/libs/onebot-mirai-*-all.jar

- name: Upload articact
uses: actions/upload-artifact@v2
with:
name: onebot-kotlin
path: onebot-kotlin/build/libs/onebot-kotlin-*-all.jar
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,31 @@

__[OneBot Standard](https://github.com/howmanybots/onebot) implementation for mirai__

### 自0.2.0起添加临时[Embedded分支版本](https://github.com/yyuueexxiinngg/cqhttp-mirai/tree/embedded), 与主分支单插件版并行, 支持发送语音, 请看[此说明中第一部分](https://github.com/yyuueexxiinngg/cqhttp-mirai/tree/embedded)进行配置

## 开始使用
### 开始使用
0. 请首先运行[mirai-console](https://github.com/mamoe/mirai-console)相关客户端生成plugins文件夹
1.`onebot-mirai`生成的`jar包文件`放入`plugins`文件夹中
2. 运行`mirai-console`, 将在`config/OneBot`文件夹中自动生成样本配置文件`settings.yml`
3. 编辑`config/OneBot/settings.yml`配置文件, 按照以下配置给出的注释修改保存
4. 再次启动[mirai-console](https://github.com/mamoe/mirai-console)相关客户端

# OneBot Kotlin - CQHTTP Mirai Embedded

### 开始使用
1. 运行Jar包: `java -jar onebot-kotlin-**.jar`
2. 编辑`config/OneBot/settings.yml`配置文件, 将以下配置给出的注释修改保存
3. 重新运行

### 接收的参数

- `--account 123456789` 要自动登录的账号
- `--password *******` 要自动登录账号的密码
- `--args -- --xx`传入参数至`mirai-console`, 如`--args -- --help``--help`传入获取`mirai-console`提供的帮助信息

#### 读取的环境变量

- `onebot.account``--account`参数, 但优先级低, 会被参数覆盖
- `onebot.password``--password`参数, 但优先级低, 会被参数覆盖

## 配置相关

```yaml
Expand Down Expand Up @@ -104,14 +120,12 @@ bots:
reconnectInterval: 3000
```
## 计划
#### 实现
- [x] 反向Websocket客户端
- [x] HTTP上报服务
- [x] Websocket服务端
- [x] HTTP API
#### 实现
<details>
<summary>已实现CQ码</summary>
Expand Down
142 changes: 10 additions & 132 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,143 +1,21 @@
plugins {
java
kotlin("jvm") version "1.4.0"
kotlin("plugin.serialization") version "1.4.0"
kotlin("kapt") version "1.4.0"
java
id("com.github.johnrengelman.shadow") version "6.0.0"
id("com.github.gmazzo.buildconfig") version "2.0.2"
}

val projectVersion = "0.3.0"
version = projectVersion
group = "yyuueexxiinngg"

repositories {
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
gradlePluginPortal()
jcenter()
mavenCentral()
}

val miraiCoreVersion = "1.3.3"
val miraiConsoleVersion = "1.0-RC-1"
val ktorVersion = "1.4.1"
val kotlinVersion = "1.4.0"
val kotlinSerializationVersion = "1.0.1"
val autoService = "1.0-rc7"

fun ktor(id: String, version: String = this@Build_gradle.ktorVersion) = "io.ktor:ktor-$id:$version"
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
fun String.runCommand(workingDir: File): String? {
return try {
val parts = this.split("\\s".toRegex())
val proc = ProcessBuilder(*parts.toTypedArray())
.directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()

proc.waitFor(60, TimeUnit.MINUTES)
proc.inputStream.bufferedReader().readText().trim()
} catch (e: java.io.IOException) {
e.printStackTrace()
null
}
}

dependencies {
kapt("com.google.auto.service", "auto-service", autoService)

compileOnly(kotlin("stdlib-jdk8"))
compileOnly("net.mamoe:mirai-core:$miraiCoreVersion")
compileOnly("net.mamoe:mirai-console:$miraiConsoleVersion")
compileOnly("net.mamoe:mirai-console-terminal:$miraiConsoleVersion")
compileOnly(kotlin("serialization", kotlinVersion))
compileOnly("com.google.auto.service", "auto-service-annotations", autoService)

implementation(kotlinx("serialization-cbor", kotlinSerializationVersion))
implementation(kotlinx("serialization-json", kotlinSerializationVersion))
implementation("ch.qos.logback:logback-classic:1.2.3")
implementation("com.google.code.gson:gson:2.8.6")

api(ktor("server-cio"))
api(ktor("client-okhttp"))
api(ktor("websockets"))
api(ktor("client-websockets"))
api(kotlin("reflect", kotlinVersion))

testImplementation(kotlin("stdlib-jdk8"))
testImplementation("net.mamoe:mirai-core:$miraiCoreVersion")
testImplementation("net.mamoe:mirai-core-qqandroid:$miraiCoreVersion")
testImplementation("net.mamoe:mirai-console:$miraiConsoleVersion")
testImplementation("net.mamoe:mirai-console-terminal:$miraiConsoleVersion")
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs = listOf("-Xjvm-default=all")
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs = listOf("-Xjvm-default=all")
}

buildConfig {
val commitHash = "git rev-parse --short HEAD".runCommand(projectDir)
buildConfigField("String", "VERSION", "\"$projectVersion\"")
if (commitHash != null) { buildConfigField("String", "COMMIT_HASH", "\"$commitHash\"") }
}

shadowJar {
dependsOn(generateBuildConfig)
}

val runMiraiConsole by creating(JavaExec::class.java) {
group = "mirai"
main = "mirai.RunMirai"
dependsOn(shadowJar)
dependsOn(testClasses)

val testConsoleDir = "test"

doFirst {
fun removeOldVersions() {
File("$testConsoleDir/plugins/").walk()
.filter { it.name.matches(Regex("""${project.name}-.*-all.jar""")) }
.forEach {
it.delete()
println("deleting old files: ${it.name}")
}
}

fun copyBuildOutput() {
File("build/libs/").walk()
.filter { it.name.contains("-all") }
.maxBy { it.lastModified() }
?.let {
println("Coping ${it.name}")
it.inputStream()
.transferTo(File("$testConsoleDir/plugins/${it.name}").apply { createNewFile() }
.outputStream())
println("Copied ${it.name}")
}
}

workingDir = File(testConsoleDir)
workingDir.mkdir()
File(workingDir, "plugins").mkdir()
removeOldVersions()
copyBuildOutput()
allprojects {
group = "com.github.yyuueexxiinngg"
version = Versions.projectVersion

classpath = sourceSets["test"].runtimeClasspath
standardInput = System.`in`
args(miraiCoreVersion, miraiConsoleVersion)
}
repositories {
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
gradlePluginPortal()
jcenter()
mavenCentral()
}
}
7 changes: 7 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
jcenter()
}
39 changes: 39 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.io.File
import java.util.concurrent.TimeUnit

object Versions {
const val projectVersion = "0.3.0"

const val miraiCoreVersion = "1.3.3"
const val miraiConsoleVersion = "1.0-RC-1"

const val ktorVersion = "1.4.1"
const val kotlinVersion = "1.4.0"
const val kotlinSerializationVersion = "1.0.1"
const val autoService = "1.0-rc7"
const val logback = "1.2.3"
const val gson = "2.8.6"

// OneBot Kotlin
const val clikt = "3.0.1"
}

fun ktor(id: String, version: String = Versions.ktorVersion) = "io.ktor:ktor-$id:$version"
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"

fun String.runCommand(workingDir: File): String? {
return try {
val parts = this.split("\\s".toRegex())
val proc = ProcessBuilder(*parts.toTypedArray())
.directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()

proc.waitFor(60, TimeUnit.MINUTES)
proc.inputStream.bufferedReader().readText().trim()
} catch (e: java.io.IOException) {
e.printStackTrace()
null
}
}
46 changes: 46 additions & 0 deletions onebot-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugins {
java
kotlin("jvm")
id("com.github.johnrengelman.shadow")
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("net.mamoe:mirai-core:${Versions.miraiCoreVersion}")
implementation("net.mamoe:mirai-core-qqandroid:${Versions.miraiCoreVersion}")
implementation("net.mamoe:mirai-console:${Versions.miraiConsoleVersion}")
implementation("net.mamoe:mirai-console-terminal:${Versions.miraiConsoleVersion}")
implementation("com.github.ajalt.clikt:clikt:${Versions.clikt}")

implementation(project(":onebot-mirai"))
}

val jar by tasks.getting(Jar::class) {
manifest {
attributes["Main-Class"] = "com.github.yyuueexxiinngg.onebot.MainKt"
}
}

tasks {
val runEmbedded by creating(JavaExec::class.java) {
group = "onebot-kotlin"
main = "com.github.yyuueexxiinngg.onebot.MainKt"
workingDir = File("../test")
dependsOn(shadowJar)
dependsOn(testClasses)
doFirst {
classpath = sourceSets["test"].runtimeClasspath
standardInput = System.`in`
args("--backend", "mirai")
}
}
}

kotlin.sourceSets.all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
}

kotlin.target.compilations.all {
kotlinOptions.freeCompilerArgs += "-Xjvm-default=enable"
kotlinOptions.jvmTarget = "1.8"
}
Loading

0 comments on commit 4c2931d

Please sign in to comment.