feat: started working on DB connection
chore: upgrade lavalink.kt Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
465101f68a
commit
8ac643bbe8
9 changed files with 100 additions and 39 deletions
|
@ -22,22 +22,25 @@ import org.jetbrains.gradle.ext.TaskTriggersConfig
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.8.0"
|
||||
kotlin("jvm") version "1.8.21"
|
||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.6"
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
//Botendo version 5
|
||||
//Botendo version 6
|
||||
val ownerID = 372703841151614976L
|
||||
group = "de.limited_dev.botendo"
|
||||
version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" }
|
||||
?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" }
|
||||
?: "6.2.0"
|
||||
?: "6.3.0"
|
||||
|
||||
val kordver = "1.5.6"
|
||||
val lavaver = "3.8.0"
|
||||
val lavaver = "4.0.0"
|
||||
val coroutinesver = "1.1.0"
|
||||
val ktor_version = "2.3.0"
|
||||
val exposedver = "0.40.1"
|
||||
val postgresver = "42.3.8"
|
||||
|
||||
val mavenArtifact = "Botendo"
|
||||
project.base.archivesName.set(mavenArtifact)
|
||||
|
@ -77,11 +80,25 @@ val implementation by configurations.getting
|
|||
implementation.extendsFrom(shadow)
|
||||
|
||||
dependencies {
|
||||
//Discord
|
||||
shadow("com.kotlindiscord.kord.extensions:kord-extensions:$kordver")
|
||||
shadow("dev.schlaubi.lavakord:kord:$lavaver")
|
||||
|
||||
//Util
|
||||
shadow("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesver")
|
||||
|
||||
//Logging
|
||||
shadow("org.slf4j:slf4j-api:2.0.3")
|
||||
shadow("org.slf4j:slf4j-simple:2.0.3")
|
||||
|
||||
//Database
|
||||
shadow("io.ktor:ktor-client-core:$ktor_version")
|
||||
shadow("io.ktor:ktor-client-cio:$ktor_version")
|
||||
shadow("org.jetbrains.exposed:exposed-core:$exposedver")
|
||||
shadow("org.jetbrains.exposed:exposed-dao:$exposedver")
|
||||
shadow("org.jetbrains.exposed:exposed-jdbc:$exposedver")
|
||||
|
||||
shadow("org.postgresql:postgresql:$postgresver")
|
||||
}
|
||||
|
||||
|
||||
|
@ -93,7 +110,10 @@ val templateProps = mapOf(
|
|||
"ownerID" to ownerID,
|
||||
"kordversion" to kordver,
|
||||
"lavaversion" to lavaver,
|
||||
"coroutinesversion" to coroutinesver
|
||||
"coroutinesversion" to coroutinesver,
|
||||
"ktorversion" to ktor_version,
|
||||
"exposedversion" to exposedver,
|
||||
"postgresversion" to postgresver
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@ package de.limited_dev.botendo
|
|||
|
||||
import com.kotlindiscord.kord.extensions.ExtensibleBot
|
||||
import de.limited_dev.botendo.buttons.ButtonManager
|
||||
import de.limited_dev.botendo.data.CredentialManager
|
||||
import de.limited_dev.botendo.extensions.music.*
|
||||
import de.limited_dev.botendo.extensions.util.InfoExtension
|
||||
import de.limited_dev.botendo.extensions.util.PotatoExtension
|
||||
import de.limited_dev.botendo.util.CredentialManager
|
||||
import de.limited_dev.botendo.util.Logger
|
||||
import de.limited_dev.botendo.util.MessageUtil
|
||||
import dev.kord.common.Color
|
||||
|
@ -84,24 +84,21 @@ object Bot {
|
|||
val response = inter.deferPublicResponse()
|
||||
val u = inter.user
|
||||
val g = this.interaction.getOriginalInteractionResponse().getGuild()
|
||||
var flag = false
|
||||
for (b in ButtonManager.buttons) {
|
||||
if (b.id != inter.componentId || flag)
|
||||
if (b.id != inter.componentId)
|
||||
continue
|
||||
b.onInteraction(response, g, u)
|
||||
flag = true
|
||||
return@on
|
||||
}
|
||||
if (!flag) {
|
||||
response.respond {
|
||||
this.embeds = mutableListOf(
|
||||
MessageUtil.getEmbed(
|
||||
Color(0xE0311A),
|
||||
"Error",
|
||||
"Could not find button with id \"${inter.componentId}\".\nPlease report this.",
|
||||
u.asUser().username + "#" + u.asUser().discriminator
|
||||
)
|
||||
response.respond {
|
||||
this.embeds = mutableListOf(
|
||||
MessageUtil.getEmbed(
|
||||
Color(0xE0311A),
|
||||
"Error",
|
||||
"Could not find button with id \"${inter.componentId}\".\nPlease report this.",
|
||||
u.asUser().username + "#" + u.asUser().discriminator
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,6 @@ suspend fun main() {
|
|||
"M#########M \n" +
|
||||
" "
|
||||
)
|
||||
println("Bot v.${BuildConstants.version}, Kord Extensions v.${BuildConstants.kordVersion}, LavaKord v.${BuildConstants.lavaVersion}, Coroutines v.${BuildConstants.coroutinesVersion}")
|
||||
println("Bot v.${BuildConstants.version}, Kord Extensions v.${BuildConstants.kordVersion}, LavaKord v.${BuildConstants.lavaVersion}, Coroutines v.${BuildConstants.coroutinesVersion}, Ktor v.${BuildConstants.ktorVersion}, Exposed v.${BuildConstants.exposedVersion}, Postgres v.${BuildConstants.postgresVersion}")
|
||||
Bot.start()
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package de.limited_dev.botendo.util
|
||||
package de.limited_dev.botendo.data
|
||||
|
||||
import java.io.*
|
||||
import java.util.*
|
41
src/main/kotlin/de/limited_dev/botendo/data/DB.kt
Normal file
41
src/main/kotlin/de/limited_dev/botendo/data/DB.kt
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Botendo
|
||||
* Copyright (C) 2023 limited_dev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package de.limited_dev.botendo.data
|
||||
|
||||
import de.limited_dev.botendo.util.Logger
|
||||
import java.sql.Connection
|
||||
import java.sql.DriverManager
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
object DB {
|
||||
private lateinit var connection: Connection
|
||||
fun connect(dbDomain: String, dbName: String, dbUser: String, dbPasswd: String) {
|
||||
val jdbcUrl = "jdbc:postgresql://$dbDomain/$dbName"
|
||||
connection = DriverManager.getConnection(jdbcUrl, dbUser, dbPasswd)
|
||||
|
||||
if (connection.isValid(0)) {
|
||||
Logger.out("DB Connection Success!")
|
||||
} else {
|
||||
Logger.out("Could not connect to the Database!")
|
||||
Logger.out("Check credentials.nils file.")
|
||||
exitProcess(4)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,23 +20,20 @@
|
|||
package de.limited_dev.botendo.extensions.music.components
|
||||
|
||||
import de.limited_dev.botendo.util.Logger
|
||||
import dev.schlaubi.lavakord.audio.TrackEndEvent
|
||||
import dev.schlaubi.lavakord.audio.TrackExceptionEvent
|
||||
import dev.schlaubi.lavakord.audio.TrackStuckEvent
|
||||
import dev.schlaubi.lavakord.audio.on
|
||||
import dev.schlaubi.lavakord.audio.*
|
||||
import dev.schlaubi.lavakord.audio.player.Player
|
||||
import dev.schlaubi.lavakord.rest.TrackResponse
|
||||
import dev.schlaubi.lavakord.rest.models.PartialTrack
|
||||
import java.util.concurrent.BlockingQueue
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
|
||||
class GuildTrackScheduler(val pl: Player) {
|
||||
|
||||
private var queue: BlockingQueue<TrackResponse.PartialTrack> = LinkedBlockingQueue()
|
||||
private var queue: BlockingQueue<PartialTrack> = LinkedBlockingQueue()
|
||||
var repeating = false
|
||||
private var hasRegisteredEvents = false
|
||||
|
||||
///Add a track to queue and start playing, if there is no song currently playing
|
||||
suspend fun queue(track: TrackResponse.PartialTrack) {
|
||||
suspend fun queue(track: PartialTrack) {
|
||||
if (this.pl.playingTrack == null) {
|
||||
play(track)
|
||||
} else {
|
||||
|
@ -51,7 +48,7 @@ class GuildTrackScheduler(val pl: Player) {
|
|||
this.pl.stopTrack()
|
||||
}
|
||||
|
||||
private suspend fun play(tr: TrackResponse.PartialTrack) {
|
||||
private suspend fun play(tr: PartialTrack) {
|
||||
this.pl.playTrack(tr)
|
||||
}
|
||||
|
||||
|
@ -62,15 +59,15 @@ class GuildTrackScheduler(val pl: Player) {
|
|||
|
||||
Logger.out("Adding track events to GuildTrackScheduler...")
|
||||
|
||||
pl.on<TrackEndEvent> {
|
||||
pl.on<Event, TrackEndEvent> {
|
||||
onTrackEnd(this)
|
||||
}
|
||||
|
||||
pl.on<TrackStuckEvent> {
|
||||
pl.on<Event, TrackStuckEvent> {
|
||||
onTrackStuck(this)
|
||||
}
|
||||
|
||||
pl.on<TrackExceptionEvent> {
|
||||
pl.on<Event, TrackExceptionEvent> {
|
||||
onTrackExc(this)
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +75,7 @@ class GuildTrackScheduler(val pl: Player) {
|
|||
private suspend fun onTrackEnd(e: TrackEndEvent) {
|
||||
if (e.reason.mayStartNext) {
|
||||
if (repeating) {
|
||||
this.pl.playTrack(e.track.copy())
|
||||
this.pl.playTrack(e.getTrack().copy())
|
||||
return
|
||||
}
|
||||
Logger.out("Track has ended; Playing next...")
|
||||
|
@ -88,12 +85,12 @@ class GuildTrackScheduler(val pl: Player) {
|
|||
|
||||
private suspend fun onTrackStuck(e: TrackStuckEvent) {
|
||||
Logger.out("Track is stuck, retrying...")
|
||||
this.pl.playTrack(e.track.copy())
|
||||
this.pl.playTrack(e.getTrack().copy())
|
||||
}
|
||||
|
||||
private suspend fun onTrackExc(e: TrackExceptionEvent) {
|
||||
Logger.out("Track had an exception, retrying...")
|
||||
this.pl.playTrack(e.track.copy())
|
||||
this.pl.playTrack(e.getTrack().copy())
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
|
@ -102,11 +99,11 @@ class GuildTrackScheduler(val pl: Player) {
|
|||
queue.clear()
|
||||
}
|
||||
|
||||
fun getQueue(): List<TrackResponse.PartialTrack> {
|
||||
fun getQueue(): List<PartialTrack> {
|
||||
return queue.toList()
|
||||
}
|
||||
|
||||
fun getHead(): TrackResponse.PartialTrack {
|
||||
fun getHead(): PartialTrack {
|
||||
return queue.first()
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ import dev.kord.core.entity.Guild
|
|||
import dev.kord.rest.builder.message.create.actionRow
|
||||
import dev.schlaubi.lavakord.audio.Link
|
||||
import dev.schlaubi.lavakord.audio.player.Player
|
||||
import dev.schlaubi.lavakord.rest.TrackResponse
|
||||
import dev.schlaubi.lavakord.rest.loadItem
|
||||
import dev.schlaubi.lavakord.rest.models.TrackResponse
|
||||
|
||||
object MusicManager {
|
||||
private var musicManagerMap: MutableMap<Snowflake, GuildTrackScheduler> = mutableMapOf()
|
||||
|
|
|
@ -37,7 +37,10 @@ class InfoExtension : Extension() {
|
|||
"Botendo ***v." + BuildConstants.version + "***\n" +
|
||||
"Kord-Extensions ***v." + BuildConstants.kordVersion + "***\n" +
|
||||
"lavalink.kt ***v." + BuildConstants.lavaVersion + "***\n" +
|
||||
"Coroutines ***v." + BuildConstants.coroutinesVersion + "***"
|
||||
"Coroutines ***v." + BuildConstants.coroutinesVersion + "***\n" +
|
||||
"Ktor ***v." + BuildConstants.ktorVersion + "***\n" +
|
||||
"Exposed ***v." + BuildConstants.exposedVersion + "***\n" +
|
||||
"PostgreSQL ***v." + BuildConstants.postgresVersion + "***"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,4 +25,7 @@ internal object BuildConstants {
|
|||
const val kordVersion = "${kordversion}"
|
||||
const val lavaVersion = "${lavaversion}"
|
||||
const val coroutinesVersion = "${coroutinesversion}"
|
||||
const val ktorVersion = "${ktorversion}"
|
||||
const val exposedVersion = "${exposedversion}"
|
||||
const val postgresVersion = "${postgresversion}"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue