Compare commits
60 commits
refactor/m
...
root
Author | SHA1 | Date | |
---|---|---|---|
fd2eafac95 | |||
95dc9bffdc | |||
fa8dd0ab14 | |||
8b49b19b1a | |||
3b292d6ddd | |||
4d5ba6754a | |||
bf93c329b7 | |||
6fa42168ac | |||
87108407a2 | |||
7f39c0767c | |||
32208e0496 | |||
adb69e1f1f | |||
f67b016014 | |||
27b4234cf7 | |||
7748d1b413 | |||
308df01d54 | |||
b42f65bce2 | |||
9f30a1415f | |||
e5c731c016 | |||
b19242fc8a | |||
881298dd15 | |||
700a2410ef | |||
b2db4cdfc3 | |||
add22d993c | |||
91cf4d2608 | |||
db4096e71a | |||
b601693905 | |||
07cd0f1aed | |||
080234fa0a | |||
35bce0277f | |||
ec202e631b | |||
110a3cffce | |||
b6f0209529 | |||
4ebe867f03 | |||
089f09031e | |||
e2651e17f2 | |||
9f2ed39bb8 | |||
8b6f60c1ea | |||
a003f54e72 | |||
62ccfcd8bf | |||
f162ef0d7e | |||
806cfe8f46 | |||
a1b3587af4 | |||
550912020e | |||
8788c0100d | |||
e8250b2e3a | |||
da4c983d89 | |||
469dbff421 | |||
58275f2262 | |||
c6cf204f44 | |||
836e938dce | |||
b680ce4ef4 | |||
63102a7ba2 | |||
c5ef4b0b56 | |||
8ce36de89a | |||
3a04c4d6ed | |||
7969b988d7 | |||
5dc0c64e0e | |||
7d4d0fda3f | |||
9228529f18 |
20 changed files with 198 additions and 127 deletions
82
.github/workflows/root.yml
vendored
82
.github/workflows/root.yml
vendored
|
@ -1,75 +1,81 @@
|
||||||
name: Build & Publish
|
name: Build & Publish
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- root
|
- root
|
||||||
schedule:
|
|
||||||
- cron: "0 6 * * *"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Disable SSL verify (Temporary Fix)
|
- name: Checkout code
|
||||||
run: git config --global http.sslVerify false
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: https://github.com/docker/setup-qemu-action@v3
|
||||||
|
with:
|
||||||
|
cache-image: false
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: https://github.com/docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Set up Java
|
- name: Set up Java
|
||||||
uses: actions/setup-java@v4
|
uses: https://github.com/actions/setup-java@v4
|
||||||
|
|
||||||
with:
|
with:
|
||||||
java-version: 21
|
java-version: 21
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
|
|
||||||
- name: Get current date
|
- name: "Restore Cache"
|
||||||
id: date
|
id: restore-cache
|
||||||
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
|
uses: https://data.forgejo.org/actions/cache/restore@v4
|
||||||
|
|
||||||
- name: Gradle Cache
|
|
||||||
uses: actions/cache/restore@v4
|
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.gradle/caches
|
~/.gradle/caches
|
||||||
~/.gradle/wrapper
|
~/.gradle/wrapper
|
||||||
key: ${{ runner.os }}-gradle-Feixiao
|
~/.m2/repository
|
||||||
restore-keys: |
|
key: gradle-store
|
||||||
${{ runner.os }}-gradle-
|
|
||||||
|
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x gradlew
|
run: chmod +x gradlew
|
||||||
|
|
||||||
|
with:
|
||||||
|
dependency-graph: generate-and-submit
|
||||||
|
cache-disabled: true
|
||||||
|
|
||||||
|
- name: Get current date
|
||||||
|
id: date
|
||||||
|
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
|
||||||
|
|
||||||
- name: Gradle (Build)
|
- name: Gradle (Build)
|
||||||
run: "./gradlew build"
|
run: "./gradlew build"
|
||||||
|
|
||||||
- name: Gradle Cache
|
- name: Login to DigitalOcean Registry
|
||||||
uses: actions/cache/save@v4
|
uses: https://github.com/docker/login-action@v3
|
||||||
|
|
||||||
|
with:
|
||||||
|
registry: registry.digitalocean.com
|
||||||
|
username: ${{ secrets.DOMAIL }}
|
||||||
|
password: ${{ secrets.DOKEY }}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: https://github.com/docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: registry.digitalocean.com/jansel/feixiao:latest,registry.digitalocean.com/jansel/feixiao:${{ steps.date.outputs.date }}
|
||||||
|
|
||||||
|
- name: "Save Cache"
|
||||||
|
uses: https://data.forgejo.org/actions/cache/save@v4
|
||||||
|
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.gradle/caches
|
~/.gradle/caches
|
||||||
~/.gradle/wrapper
|
~/.gradle/wrapper
|
||||||
key: ${{ runner.os }}-gradle-Feixiao
|
~/.m2/repository
|
||||||
|
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
|
||||||
- name: Login to Gitea Registry
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
|
|
||||||
with:
|
|
||||||
registry: pi5:8125
|
|
||||||
username: ${{ github.repository_owner }}
|
|
||||||
password: ${{ secrets.PW }}
|
|
||||||
|
|
||||||
- name: Build the Docker image
|
|
||||||
run: docker build -t pi5:8125/jansel/feixiao:latest -t pi5:8125/jansel/feixiao:${{ steps.date.outputs.date }} .
|
|
||||||
|
|
||||||
- name: Push the Docker image related to this workflow
|
|
||||||
run: docker push pi5:8125/jansel/feixiao:${{ steps.date.outputs.date }}
|
|
||||||
|
|
||||||
- name: Push the latest Docker image
|
|
||||||
run: docker push pi5:8125/jansel/feixiao:latest
|
|
||||||
|
|
2
.idea/kotlinc.xml
generated
2
.idea/kotlinc.xml
generated
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="KotlinJpsPluginSettings">
|
<component name="KotlinJpsPluginSettings">
|
||||||
<option name="version" value="2.0.21" />
|
<option name="version" value="2.1.21" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -2,17 +2,17 @@ import dev.kordex.gradle.plugins.docker.file.*
|
||||||
import dev.kordex.gradle.plugins.kordex.DataCollection
|
import dev.kordex.gradle.plugins.kordex.DataCollection
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm")
|
distribution
|
||||||
kotlin("plugin.serialization")
|
|
||||||
|
|
||||||
id("com.github.johnrengelman.shadow")
|
alias(libs.plugins.kotlin.jvm)
|
||||||
|
alias(libs.plugins.kotlin.serialization)
|
||||||
|
|
||||||
id("dev.kordex.gradle.docker")
|
alias(libs.plugins.kordex.plugin)
|
||||||
id("dev.kordex.gradle.kordex")
|
alias(libs.plugins.kordex.docker)
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "dev.jansel"
|
group = "dev.jansel"
|
||||||
version = "1.0-SNAPSHOT"
|
version = "1.2-SNAPSHOT"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
|
@ -31,9 +31,26 @@ dependencies {
|
||||||
implementation(libs.logging)
|
implementation(libs.logging)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configure distributions plugin
|
||||||
|
distributions {
|
||||||
|
main {
|
||||||
|
distributionBaseName = project.name
|
||||||
|
|
||||||
|
contents {
|
||||||
|
// Copy the LICENSE file into the distribution
|
||||||
|
from("LICENSE")
|
||||||
|
|
||||||
|
// Exclude src/main/dist/README.md
|
||||||
|
exclude("README.md")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
kordEx {
|
kordEx {
|
||||||
kordExVersion = "2.3.1-SNAPSHOT"
|
kordExVersion = "2.3.1-SNAPSHOT"
|
||||||
jvmTarget = 21
|
jvmTarget = 21
|
||||||
|
ignoreIncompatibleKotlinVersion = true
|
||||||
|
|
||||||
bot {
|
bot {
|
||||||
// See https://docs.kordex.dev/data-collection.html
|
// See https://docs.kordex.dev/data-collection.html
|
||||||
|
@ -58,37 +75,51 @@ docker {
|
||||||
// Each function (aside from comment/emptyLine) corresponds to a Dockerfile instruction.
|
// Each function (aside from comment/emptyLine) corresponds to a Dockerfile instruction.
|
||||||
// See: https://docs.docker.com/reference/dockerfile/
|
// See: https://docs.docker.com/reference/dockerfile/
|
||||||
|
|
||||||
from("azul/zulu-openjdk-alpine:21-jre-headless-latest")
|
from("openjdk:21-jdk-slim")
|
||||||
|
|
||||||
emptyLine()
|
emptyLine()
|
||||||
|
|
||||||
|
comment("Create required directories")
|
||||||
runShell("mkdir -p /bot/plugins")
|
runShell("mkdir -p /bot/plugins")
|
||||||
runShell("mkdir -p /bot/data")
|
runShell("mkdir -p /bot/data")
|
||||||
|
runShell("mkdir -p /dist/out")
|
||||||
emptyLine()
|
|
||||||
|
|
||||||
copy("build/libs/$name-*-all.jar", "/bot/bot.jar")
|
|
||||||
|
|
||||||
emptyLine()
|
emptyLine()
|
||||||
|
|
||||||
// Add volumes for locations that you need to persist. This is important!
|
// Add volumes for locations that you need to persist. This is important!
|
||||||
|
comment("Declare required volumes")
|
||||||
volume("/bot/data") // Storage for data files
|
volume("/bot/data") // Storage for data files
|
||||||
volume("/bot/plugins") // Plugin ZIP/JAR location
|
volume("/bot/plugins") // Plugin ZIP/JAR location
|
||||||
|
|
||||||
emptyLine()
|
emptyLine()
|
||||||
|
|
||||||
|
comment("Copy the distribution files into the container")
|
||||||
|
copy("build/distributions/${project.name}-${project.version}.tar", "/dist")
|
||||||
|
|
||||||
|
emptyLine()
|
||||||
|
|
||||||
|
comment("Extract the distribution files, and prepare them for use")
|
||||||
|
runShell("tar -xf /dist/${project.name}-${project.version}.tar -C /dist/out")
|
||||||
|
|
||||||
|
if (file("src/main/dist/plugins").isDirectory) {
|
||||||
|
runShell("mv /dist/out/${project.name}-${project.version}/plugins/* /bot/plugins")
|
||||||
|
}
|
||||||
|
|
||||||
|
runShell("chmod +x /dist/out/${project.name}-${project.version}/bin/$name")
|
||||||
|
|
||||||
|
emptyLine()
|
||||||
|
|
||||||
|
comment("Clean up unnecessary files")
|
||||||
|
runShell("rm /dist/${project.name}-${project.version}.tar")
|
||||||
|
|
||||||
|
emptyLine()
|
||||||
|
|
||||||
|
comment("Set the correct working directory")
|
||||||
workdir("/bot")
|
workdir("/bot")
|
||||||
|
|
||||||
emptyLine()
|
emptyLine()
|
||||||
|
|
||||||
entryPointExec(
|
comment("Run the distribution start script")
|
||||||
"java", "-Xms2G", "-Xmx2G",
|
entryPointExec("/dist/out/${project.name}-${project.version}/bin/$name")
|
||||||
"-jar", "/bot/bot.jar"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.wrapper {
|
|
||||||
gradleVersion = "8.11.1"
|
|
||||||
distributionType = Wrapper.DistributionType.BIN
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
[versions]
|
[versions]
|
||||||
kotlin = "2.0.21" # Note: Plugin versions must be updated in the settings.gradle.kts too
|
kotlin = "2.1.21" # Note: Plugin versions must be updated in the settings.gradle.kts too
|
||||||
|
|
||||||
groovy = "3.0.23"
|
groovy = "3.0.25"
|
||||||
jansi = "2.4.1"
|
jansi = "2.4.2"
|
||||||
kx-ser = "1.7.3"
|
kx-ser = "1.8.1"
|
||||||
logback = "1.5.12"
|
logback = "1.5.18"
|
||||||
logback-groovy = "1.14.5"
|
logback-groovy = "1.14.5"
|
||||||
logging = "7.0.3"
|
logging = "7.0.7"
|
||||||
twitch4j = "1.23.0"
|
twitch4j = "1.25.0"
|
||||||
events4j = "0.12.2"
|
events4j = "0.12.2"
|
||||||
kx-coroutines = "1.9.0"
|
kx-coroutines = "1.10.2"
|
||||||
kmongo = "5.1.0"
|
kmongo = "5.2.1"
|
||||||
|
kordex-gradle = "1.7.1"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
groovy = { module = "org.codehaus.groovy:groovy", version.ref = "groovy" }
|
groovy = { module = "org.codehaus.groovy:groovy", version.ref = "groovy" }
|
||||||
|
@ -24,3 +25,11 @@ logging = { module = "io.github.oshai:kotlin-logging", version.ref = "logging" }
|
||||||
twitch4j = { module = "com.github.twitch4j:twitch4j", version.ref = "twitch4j" }
|
twitch4j = { module = "com.github.twitch4j:twitch4j", version.ref = "twitch4j" }
|
||||||
events4j = { module = "com.github.philippheuer.events4j:events4j-handler-reactor", version.ref = "events4j" }
|
events4j = { module = "com.github.philippheuer.events4j:events4j-handler-reactor", version.ref = "events4j" }
|
||||||
kmongo = { module="org.litote.kmongo:kmongo-coroutine-serialization", version.ref = "kmongo" }
|
kmongo = { module="org.litote.kmongo:kmongo-coroutine-serialization", version.ref = "kmongo" }
|
||||||
|
|
||||||
|
|
||||||
|
[plugins]
|
||||||
|
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||||
|
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
|
||||||
|
|
||||||
|
kordex-docker = { id = "dev.kordex.gradle.docker", version.ref = "kordex-gradle" }
|
||||||
|
kordex-plugin = { id = "dev.kordex.gradle.kordex", version.ref = "kordex-gradle" }
|
||||||
|
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,6 +1,6 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|
9
gradlew
vendored
9
gradlew
vendored
|
@ -86,8 +86,7 @@ done
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
' "$PWD" ) || exit
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
|
@ -115,7 +114,7 @@ case "$( uname )" in #(
|
||||||
NONSTOP* ) nonstop=true ;;
|
NONSTOP* ) nonstop=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH="\\\"\\\""
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
|
@ -206,7 +205,7 @@ fi
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Collect all arguments for the java command:
|
# Collect all arguments for the java command:
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
# and any embedded shellness will be escaped.
|
# and any embedded shellness will be escaped.
|
||||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
# treated as '${Hostname}' itself on the command line.
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
@ -214,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
-classpath "$CLASSPATH" \
|
-classpath "$CLASSPATH" \
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
# Stop when "xargs" is not available.
|
||||||
|
|
4
gradlew.bat
vendored
4
gradlew.bat
vendored
|
@ -70,11 +70,11 @@ goto fail
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
|
15
renovate.json
Normal file
15
renovate.json
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"config:recommended"
|
||||||
|
],
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"matchUpdateTypes": [
|
||||||
|
"minor",
|
||||||
|
"patch"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"prHourlyLimit": 0
|
||||||
|
}
|
|
@ -1,14 +1,4 @@
|
||||||
pluginManagement {
|
pluginManagement {
|
||||||
plugins {
|
|
||||||
// Update this in libs.version.toml when you change it here.
|
|
||||||
kotlin("jvm") version "2.0.21"
|
|
||||||
kotlin("plugin.serialization") version "2.0.21"
|
|
||||||
|
|
||||||
id("com.github.johnrengelman.shadow") version "8.1.1"
|
|
||||||
|
|
||||||
id("dev.kordex.gradle.docker") version "1.6.0"
|
|
||||||
id("dev.kordex.gradle.kordex") version "1.6.0"
|
|
||||||
}
|
|
||||||
repositories {
|
repositories {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
package dev.jansel.feixiao.database
|
package dev.jansel.feixiao.database
|
||||||
|
|
||||||
|
import com.github.philippheuer.events4j.reactor.ReactorEventHandler
|
||||||
|
import com.github.twitch4j.TwitchClientBuilder
|
||||||
import dev.jansel.feixiao.database.collections.MetaCollection
|
import dev.jansel.feixiao.database.collections.MetaCollection
|
||||||
import dev.jansel.feixiao.database.entities.MetaData
|
import dev.jansel.feixiao.database.entities.MetaData
|
||||||
import dev.jansel.feixiao.database.migrations.v1
|
import dev.jansel.feixiao.database.migrations.v1
|
||||||
|
import dev.jansel.feixiao.database.migrations.v2
|
||||||
|
import dev.jansel.feixiao.twitchClient
|
||||||
|
import dev.jansel.feixiao.utils.twitchcid
|
||||||
|
import dev.jansel.feixiao.utils.twitchcs
|
||||||
import dev.kordex.core.koin.KordExKoinComponent
|
import dev.kordex.core.koin.KordExKoinComponent
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
|
@ -15,6 +21,13 @@ object Migrator : KordExKoinComponent {
|
||||||
|
|
||||||
suspend fun migrate() {
|
suspend fun migrate() {
|
||||||
logger.info { "Starting main database migration" }
|
logger.info { "Starting main database migration" }
|
||||||
|
logger.info { "Initializing Twitch client just in case" }
|
||||||
|
twitchClient = TwitchClientBuilder.builder()
|
||||||
|
.withEnableHelix(true)
|
||||||
|
.withDefaultEventHandler(ReactorEventHandler::class.java)
|
||||||
|
.withClientId(twitchcid)
|
||||||
|
.withClientSecret(twitchcs)
|
||||||
|
.build()
|
||||||
|
|
||||||
var meta = mainMetaCollection.get()
|
var meta = mainMetaCollection.get()
|
||||||
|
|
||||||
|
@ -35,6 +48,7 @@ object Migrator : KordExKoinComponent {
|
||||||
try {
|
try {
|
||||||
when (nextVersion) {
|
when (nextVersion) {
|
||||||
1 -> ::v1
|
1 -> ::v1
|
||||||
|
2 -> ::v2
|
||||||
else -> break
|
else -> break
|
||||||
}(db.mongo)
|
}(db.mongo)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package dev.jansel.feixiao.database.collections
|
||||||
import dev.jansel.feixiao.database.Database
|
import dev.jansel.feixiao.database.Database
|
||||||
import dev.jansel.feixiao.database.entities.Server
|
import dev.jansel.feixiao.database.entities.Server
|
||||||
import dev.jansel.feixiao.database.entities.StreamerData
|
import dev.jansel.feixiao.database.entities.StreamerData
|
||||||
|
import dev.jansel.feixiao.utils.getTwitchIdByName
|
||||||
import dev.kord.common.entity.Snowflake
|
import dev.kord.common.entity.Snowflake
|
||||||
import dev.kordex.core.koin.KordExKoinComponent
|
import dev.kordex.core.koin.KordExKoinComponent
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
|
@ -35,7 +36,7 @@ class StreamerCollection : KordExKoinComponent {
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
collection.insertOne(
|
collection.insertOne(
|
||||||
StreamerData(streamerName, listOf(Server(guildId, channelId, roleId, liveMessage)))
|
StreamerData(streamerName, getTwitchIdByName(streamerName), listOf(Server(guildId, channelId, roleId, liveMessage)))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import kotlinx.serialization.Serializable
|
||||||
@Serializable
|
@Serializable
|
||||||
data class StreamerData(
|
data class StreamerData(
|
||||||
val name: String,
|
val name: String,
|
||||||
|
val id: String?,
|
||||||
val servers: List<Server>
|
val servers: List<Server>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
16
src/main/kotlin/dev/jansel/feixiao/database/migrations/v2.kt
Normal file
16
src/main/kotlin/dev/jansel/feixiao/database/migrations/v2.kt
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package dev.jansel.feixiao.database.migrations
|
||||||
|
|
||||||
|
import dev.jansel.feixiao.database.entities.StreamerData
|
||||||
|
import dev.jansel.feixiao.utils.getTwitchIdByName
|
||||||
|
import org.litote.kmongo.coroutine.CoroutineDatabase
|
||||||
|
import org.litote.kmongo.eq
|
||||||
|
import org.litote.kmongo.setValue
|
||||||
|
|
||||||
|
suspend fun v2(db: CoroutineDatabase) {
|
||||||
|
db.getCollection<StreamerData>("streamerData").findOne(StreamerData::id eq null)?.let {
|
||||||
|
db.getCollection<StreamerData>("streamerData").updateOne(
|
||||||
|
StreamerData::name eq it.name,
|
||||||
|
setValue(StreamerData::id, getTwitchIdByName(it.name))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,8 @@ import dev.jansel.feixiao.database.collections.StreamerCollection
|
||||||
import dev.jansel.feixiao.database.entities.StreamerData
|
import dev.jansel.feixiao.database.entities.StreamerData
|
||||||
import dev.jansel.feixiao.logger
|
import dev.jansel.feixiao.logger
|
||||||
import dev.jansel.feixiao.twitchClient
|
import dev.jansel.feixiao.twitchClient
|
||||||
|
import dev.jansel.feixiao.utils.getTwitchIdByName
|
||||||
|
import dev.jansel.feixiao.utils.getTwitchNameById
|
||||||
import dev.jansel.feixiao.utils.tchannelid
|
import dev.jansel.feixiao.utils.tchannelid
|
||||||
import dev.jansel.feixiao.utils.tserverid
|
import dev.jansel.feixiao.utils.tserverid
|
||||||
import dev.kord.core.behavior.getChannelOf
|
import dev.kord.core.behavior.getChannelOf
|
||||||
|
@ -12,6 +14,7 @@ import dev.kord.core.event.gateway.ReadyEvent
|
||||||
import dev.kordex.core.extensions.Extension
|
import dev.kordex.core.extensions.Extension
|
||||||
import dev.kordex.core.extensions.event
|
import dev.kordex.core.extensions.event
|
||||||
import org.litote.kmongo.eq
|
import org.litote.kmongo.eq
|
||||||
|
import org.litote.kmongo.setValue
|
||||||
|
|
||||||
class EventHooks : Extension() {
|
class EventHooks : Extension() {
|
||||||
override val name = "eventhooks"
|
override val name = "eventhooks"
|
||||||
|
@ -27,8 +30,10 @@ class EventHooks : Extension() {
|
||||||
// check every entry in the database and enable the stream event listener if a server is listening to the streamer
|
// check every entry in the database and enable the stream event listener if a server is listening to the streamer
|
||||||
StreamerCollection().collection.find().toList().forEach {
|
StreamerCollection().collection.find().toList().forEach {
|
||||||
if (it.servers.isNotEmpty()) {
|
if (it.servers.isNotEmpty()) {
|
||||||
twitchClient!!.clientHelper.enableStreamEventListener(it.name)
|
val currentName = getTwitchNameById(it.id!!)
|
||||||
logger.info { "Enabled stream event listener for ${it.name}" }
|
twitchClient!!.clientHelper.enableStreamEventListener(currentName)
|
||||||
|
logger.info { "Enabled stream event listener for $currentName" }
|
||||||
|
StreamerCollection().collection.updateOne(StreamerData::name eq it.name, setValue(StreamerData::name, currentName))
|
||||||
} else {
|
} else {
|
||||||
logger.info { "No servers are listening to ${it.name}, deleting from the database..." }
|
logger.info { "No servers are listening to ${it.name}, deleting from the database..." }
|
||||||
StreamerCollection().collection.deleteMany(StreamerData::name eq it.name)
|
StreamerCollection().collection.deleteMany(StreamerData::name eq it.name)
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package dev.jansel.feixiao.modals
|
|
||||||
|
|
||||||
import dev.jansel.feixiao.i18n.Translations
|
|
||||||
import dev.kordex.core.components.forms.ModalForm
|
|
||||||
import dev.kordex.core.i18n.types.Key
|
|
||||||
|
|
||||||
class EditStreamerModal : ModalForm() {
|
|
||||||
override var title = Translations.Streamer.Modals.Edit.title
|
|
||||||
|
|
||||||
val streamerName = lineText {
|
|
||||||
label = Translations.Streamer.Modals.Edit.Streamername.label
|
|
||||||
placeholder = Translations.Streamer.Modals.Edit.Streamername.placeholder
|
|
||||||
}
|
|
||||||
|
|
||||||
val channel = lineText {
|
|
||||||
label = Translations.Streamer.Modals.Edit.Channel.label
|
|
||||||
placeholder = Translations.Streamer.Modals.Edit.Channel.placeholder
|
|
||||||
}
|
|
||||||
|
|
||||||
val role = lineText {
|
|
||||||
label = Translations.Streamer.Modals.Edit.Role.label
|
|
||||||
placeholder = Translations.Streamer.Modals.Edit.Role.placeholder
|
|
||||||
}
|
|
||||||
|
|
||||||
val message = paragraphText {
|
|
||||||
label = Translations.Streamer.Modals.Edit.Message.label
|
|
||||||
placeholder = Translations.Streamer.Modals.Edit.Message.placeholder
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,6 +3,7 @@ package dev.jansel.feixiao.utils
|
||||||
import dev.jansel.feixiao.database.Database
|
import dev.jansel.feixiao.database.Database
|
||||||
import dev.jansel.feixiao.database.collections.MetaCollection
|
import dev.jansel.feixiao.database.collections.MetaCollection
|
||||||
import dev.jansel.feixiao.database.collections.StreamerCollection
|
import dev.jansel.feixiao.database.collections.StreamerCollection
|
||||||
|
import dev.jansel.feixiao.twitchClient
|
||||||
import dev.kord.common.entity.Snowflake
|
import dev.kord.common.entity.Snowflake
|
||||||
import dev.kordex.core.builders.ExtensibleBotBuilder
|
import dev.kordex.core.builders.ExtensibleBotBuilder
|
||||||
import dev.kordex.core.utils.env
|
import dev.kordex.core.utils.env
|
||||||
|
@ -52,3 +53,23 @@ suspend inline fun ExtensibleBotBuilder.twitch(active: Boolean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getTwitchNameById(id: String): String? {
|
||||||
|
val resultList = twitchClient!!.helix?.getUsers(null, listOf(id), null)?.execute()
|
||||||
|
resultList?.users?.forEach { user ->
|
||||||
|
if (user.id == id) {
|
||||||
|
return user.displayName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getTwitchIdByName(name: String): String? {
|
||||||
|
val resultList = twitchClient!!.helix?.getUsers(null, null, listOf(name))?.execute()
|
||||||
|
resultList?.users?.forEach { user ->
|
||||||
|
if (user.displayName == name) {
|
||||||
|
return user.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
|
@ -33,14 +33,6 @@ streamer.command.arguments.update.role.description=The role to assign to the str
|
||||||
streamer.command.arguments.update.message.name=message
|
streamer.command.arguments.update.message.name=message
|
||||||
streamer.command.arguments.update.message.description=Custom Announce message. Placeholders (in curly braces): url, name, title, category, role (if set)
|
streamer.command.arguments.update.message.description=Custom Announce message. Placeholders (in curly braces): url, name, title, category, role (if set)
|
||||||
|
|
||||||
streamer.modals.edit.title=Edit Streamer
|
|
||||||
streamer.modals.edit.streamername.label=Streamer Name
|
|
||||||
streamer.modals.edit.streamername.placeholder=Streamer Name
|
|
||||||
streamer.modals.edit.channel.label=Channel
|
|
||||||
streamer.modals.edit.channel.placeholder=Channel ID for the live messages. Leave empty for no change.
|
|
||||||
streamer.modals.edit.role.label=Role
|
|
||||||
streamer.modals.edit.role.placeholder=Role ID to assign to the stream pings. Leave empty for no change.
|
|
||||||
streamer.modals.edit.message.label=Message
|
|
||||||
streamer.modals.edit.message.placeholder=Message to send when the streamer goes live. Placeholders: {url}, {name}, {title}, {category}, {role}
|
|
||||||
|
|
||||||
# more to come...
|
# more to come...
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue