Skip to content

Commit

Permalink
Merge branch 'version/1.20.1' into version/1.19.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	common/src/main/kotlin/module-info.java
#	fabric/gradle.properties
#	fabric/src/main/kotlin/dev/erdragh/astralbot/fabric/BotMod.kt
#	gradle.properties
  • Loading branch information
Erdragh committed Feb 22, 2024
2 parents 2566f50 + f0b6191 commit 1211ca3
Show file tree
Hide file tree
Showing 26 changed files with 653 additions and 122 deletions.
160 changes: 132 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
name: build
on:
push:
branches: [ "main", "develop" ]
branches: [ "main", "develop", "version/*" ]
pull_request:
branches: [ "main", "develop" ]
branches: [ "main", "develop", "version/*" ]
workflow_dispatch:
inputs:
publish:
description: Publish to Modrinth and CurseForge
required: true
default: "false"

permissions:
contents: write
Expand All @@ -17,7 +23,7 @@ jobs:
17, # Current Java LTS & minimum supported by Minecraft
]
# and run on Linux
os: [ubuntu-latest]
os: [ ubuntu-latest ]

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -30,33 +36,131 @@ jobs:
java-version: ${{ matrix.java }}
distribution: 'temurin'

- name: echo ref
run: echo ${{github.ref}}

- name: setup gradle with dependency graph
- name: Build with Gradle and generate dependency Graph
if: ${{github.ref == 'refs/heads/main' && github.event_name != 'pull_request'}}
uses: gradle/gradle-build-action@v2
# with:
# dependency-graph: 'generate-and-submit'
with:
arguments: build
dependency-graph: 'generate-and-submit'

- name: setup gradle
- name: Build with Gradle
if: ${{github.ref != 'refs/heads/main' || github.event_name == 'pull_request'}}
uses: gradle/gradle-build-action@v2
# with:
# dependency-graph: 'generate-and-upload'

- name: gradle clean build
run: ./gradlew clean build

# - name: Capture Fabric Artifacts
# if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
# uses: actions/upload-artifact@v3
# with:
# name: Fabric Artifacts
# path: fabric/build/libs
# - name: Capture Forge Artifacts
# if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
# uses: actions/upload-artifact@v3
# with:
# name: Forge Artifacts
# path: forge/build/libs
with:
arguments: build

- name: Prepare Changelog
run: ./gradlew -q prepareChangelog > prepared_changelog.md

- name: Capture Fabric Artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v4
with:
name: build-fabric
path: fabric/build/libs
- name: Capture Forge Artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v4
with:
name: build-forge
path: forge/build/libs
- name: Capture Changelog
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v4
with:
name: build-changelog
path: prepared_changelog.md
publish:
if: ${{ github.event.inputs.publish }}
needs:
- build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download Fabric artifacts
uses: actions/download-artifact@v4
with:
path: build/fabric
pattern: build-fabric
merge-multiple: true
- name: Download Forge artifacts
uses: actions/download-artifact@v4
with:
path: build/forge
pattern: build-forge
merge-multiple: true
- name: Download Changelog
uses: actions/download-artifact@v4
with:
path: .
pattern: build-changelog

- name: List build artifacts
run: ls -R build
- name: Show Changelog
run: cat build-changelog/prepared_changelog.md

- name: Get Version and Platform
id: properties
uses: christian-draeger/[email protected]
with:
path: "./gradle.properties"
properties: "version enabledPlatforms minecraftVersion"

- name: Upload Forge Releases (Curse/Modrinth/Github)
id: forge_release
if: contains(steps.properties.outputs.enabledPlatforms, 'forge')
uses: Kir-Antipov/[email protected]
with:
curseforge-id: ${{ vars.CURSE_ID }}
curseforge-token: ${{ secrets.CURSE_TOKEN }}

modrinth-id: ${{ vars.MODRINTH_ID }}
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}

files: ./build/forge/!(*-@(dev|sources|dev-shadow)).jar
name: "AstralBot ${{ steps.properties.outputs.version }} Forge ${{ steps.properties.output.minecraftVersion }}"
version: ${{ steps.properties.outputs.version }}
version-type: release
changelog-file: build-changelog/prepared_changelog.md
loaders: forge
game-versions: ${{ steps.properties.outputs.minecraftVersion }}

curseforge-dependencies: |
sqlite-jdbc(optional)
kotlin-for-forge(required)
modrinth-dependencies: |
sqlite-jdbc(optional)
kotlin-for-forge(required)
- name: Upload Fabric Releases (Curse/Modrinth/Github)
id: fabric_release
if: contains(steps.properties.outputs.enabledPlatforms, 'fabric')
uses: Kir-Antipov/[email protected]
with:
curseforge-id: ${{ vars.CURSE_ID }}
curseforge-token: ${{ secrets.CURSE_TOKEN }}

modrinth-id: ${{ vars.MODRINTH_ID }}
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}

files: ./build/fabric/!(*-@(dev|sources|dev-shadow)).jar
name: "AstralBot ${{ steps.properties.outputs.version }} Fabric ${{ steps.properties.output.minecraftVersion }}"
version: ${{ steps.properties.outputs.version }}
version-type: release
changelog-file: build-changelog/prepared_changelog.md
loaders: fabric
game-versions: ${{ steps.properties.outputs.minecraftVersion }}

curseforge-dependencies: |
fabric-api(required)
fabric-language-kotlin(required)
sqlite-jdbc(optional)
ledger(optional)
modrinth-dependencies: |
fabric-api(required)
fabric-language-kotlin(required)
sqlite-jdbc(optional)
ledger(optional)
30 changes: 30 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 1.2.0
- Unlink other Discord users with permissions
- Customizable text for basically anything
- `/headpat` command
- More graceful shutdown
- `/link` as a Minecraft command for people who want to be linked but are already whitelisted by another way
- Exception handling for commands server side, resulting in less commands that don't get a response

# 1.1.0
- Management Commands:
- `/tps`
- `/usage`
- `/stop`
- `/uptime`
- Stop Minecraft usernames being formatted as Markdown on Discord
- Rework enabled commands config

# 1.0.2
- Solve Compatibility issue with [GML](https://modrinth.com/mod/gml) on Forge
- Fix empty whitelist Database handling

# 1.0.1
- Config option to disable `/unlink`
- Async bot startup
- Make `/reload` command remove no longer registered commands
- Update dependencies
- Make SQLite driver an external dependency, allowing compatibility with [Ledger](https://modrinth.com/mod/ledger)

# 1.0.0
Initial Release
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import dev.architectury.plugin.ArchitectPluginExtension
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask
import java.nio.charset.StandardCharsets

plugins {
// This is an Architectury repository, as such the relevant plugins are needed
Expand Down Expand Up @@ -218,4 +219,10 @@ subprojects {

kotlin {
jvmToolchain(17)
}

tasks.create("prepareChangelog") {
var changelog = File("Changelog.md").readText(StandardCharsets.UTF_8)
changelog = changelog.replace(Regex("[^^](#(#|\\n|.)+)|(^#.+)"), "")
println(changelog.trim())
}
18 changes: 15 additions & 3 deletions common/src/main/kotlin/dev/erdragh/astralbot/Bot.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.erdragh.astralbot

import dev.erdragh.astralbot.commands.CommandHandlingListener
import dev.erdragh.astralbot.commands.discord.CommandHandlingListener
import dev.erdragh.astralbot.config.AstralBotConfig
import dev.erdragh.astralbot.handlers.FAQHandler
import dev.erdragh.astralbot.handlers.MinecraftHandler
Expand All @@ -15,7 +15,9 @@ import net.minecraft.server.MinecraftServer
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.File
import java.time.Duration
import java.time.LocalDateTime
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.properties.Delegates

const val MODID = "astralbot"
Expand All @@ -32,6 +34,7 @@ var applicationId by Delegates.notNull<Long>()
var baseDirectory: File? = null

private lateinit var setupJob: Job
var shuttingDown = AtomicBoolean(false)

/**
* @return the time at which the AstralBot was started
Expand Down Expand Up @@ -93,6 +96,8 @@ private fun setupFromJDA(api: JDA) {
}
textChannel = ch
guild = g

ch.sendMessage("Server Started!").queue()
}

@OptIn(DelicateCoroutinesApi::class)
Expand Down Expand Up @@ -139,8 +144,15 @@ fun startAstralbot(server: MinecraftServer) {

fun stopAstralbot() {
LOGGER.info("Shutting down AstralBot")
shuttingDown.set(true)
if (baseDirectory != null) FAQHandler.stop()
jda?.shutdownNow()
jda?.awaitShutdown()
if (jda != null) {
jda!!.shutdown()
// Allow at most 10 seconds for remaining requests to finish
if (!jda!!.awaitShutdown(Duration.ofSeconds(10))) {
jda!!.shutdownNow() // Cancel all remaining requests
jda!!.awaitShutdown() // Wait until shutdown is complete (indefinitely)
}
}
LOGGER.info("Shut down AstralBot")
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package dev.erdragh.astralbot.commands
package dev.erdragh.astralbot.commands.discord

import dev.erdragh.astralbot.LOGGER
import dev.erdragh.astralbot.applicationId
import dev.erdragh.astralbot.config.AstralBotTextConfig
import dev.erdragh.astralbot.guild
import dev.erdragh.astralbot.waitForSetup
import net.dv8tion.jda.api.entities.Guild
Expand Down Expand Up @@ -59,16 +60,19 @@ object CommandHandlingListener : ListenerAdapter() {
* can't return anything because of its asynchronous nature
*/
fun updateCommands(guild: Guild, sendMessage: (msg: String) -> Unit) {
LOGGER.info("Reloading commands.")
guild.retrieveCommands().submit().whenComplete { fetchedCommands, error ->
if (error != null) {
sendMessage("Something went wrong: ${error.localizedMessage}")
sendMessage(AstralBotTextConfig.RELOAD_ERROR.get().replace("{{error}}", error.localizedMessage))
LOGGER.error("Couldn't reload commands", error)
return@whenComplete
}
waitForSetup()
val deletedCommands = fetchedCommands.filter { it.applicationIdLong == applicationId }.map { guild.deleteCommandById(it.id).submit() }
deletedCommands.forEach { it.get() }
guild.updateCommands().addCommands(getEnabledCommands().map { it.command }).queue {
sendMessage("Reloaded commands for guild")
sendMessage(AstralBotTextConfig.RELOAD_SUCCESS.get())
LOGGER.info("Reloaded commands.")
}
}
}
Expand All @@ -82,9 +86,14 @@ object CommandHandlingListener : ListenerAdapter() {
override fun onSlashCommandInteraction(event: SlashCommandInteractionEvent) {
val usedCommand = getEnabledCommands().find { it.command.name == event.name }
if (usedCommand != null) {
usedCommand.handle(event)
try {
usedCommand.handle(event)
} catch (e: Exception) {
LOGGER.error("Failed to execute command: ${event.name}", e)
event.hook.sendMessage(AstralBotTextConfig.GENERIC_ERROR.get()).queue()
}
} else {
event.reply("Something went wrong").queue()
event.reply(AstralBotTextConfig.GENERIC_ERROR.get()).queue()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// This file contains multiple commands which don't warrant separate files

package dev.erdragh.astralbot.commands
package dev.erdragh.astralbot.commands.discord

import dev.erdragh.astralbot.config.AstralBotConfig
import dev.erdragh.astralbot.minecraftHandler
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData
import kotlin.jvm.Throws

/**
* Array containing every single command AstralBot supports
Expand All @@ -28,7 +29,9 @@ val allCommands = arrayOf(
UptimeCommand,
StopCommand,
TPSCommand,
UsageCommand
UsageCommand,
// Fun commands
HeadpatCommand
)

/**
Expand Down Expand Up @@ -59,6 +62,7 @@ interface HandledSlashCommand {
* @param event the event that is connected with the
* issuing of the command
*/
@Throws(Exception::class)
fun handle(event: SlashCommandInteractionEvent)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.erdragh.astralbot.commands
package dev.erdragh.astralbot.commands.discord

import dev.erdragh.astralbot.handlers.FAQHandler
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent
Expand Down
Loading

0 comments on commit 1211ca3

Please sign in to comment.