big bang
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
commit
077da0c43b
16 changed files with 1101 additions and 0 deletions
78
src/main/kotlin/de/limited_dev/lilJudd/Bot.kt
Normal file
78
src/main/kotlin/de/limited_dev/lilJudd/Bot.kt
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* 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.lilJudd
|
||||
|
||||
import com.kotlindiscord.kord.extensions.ExtensibleBot
|
||||
import de.limited_dev.botendo.build.BuildConstants
|
||||
import de.limited_dev.lilJudd.data.CredentialManager
|
||||
import de.limited_dev.lilJudd.data.DB
|
||||
import de.limited_dev.lilJudd.extensions.VersionExtension
|
||||
import de.limited_dev.lilJudd.util.Logger
|
||||
import dev.kord.common.entity.PresenceStatus
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
object Bot {
|
||||
//The kord object gets set at app launch
|
||||
private lateinit var bot: ExtensibleBot
|
||||
suspend fun start() {
|
||||
Logger.out("Starting Bot...")
|
||||
|
||||
//Load config
|
||||
CredentialManager.load()
|
||||
|
||||
//Don't run the bot when there is no bot token in config
|
||||
if (CredentialManager.token == "empty") {
|
||||
Logger.out("The config does not contain a bot token.")
|
||||
exitProcess(3)
|
||||
}
|
||||
|
||||
//Check if the credentials for the Database are existent
|
||||
if (CredentialManager.dbDomain == "empty" || CredentialManager.dbName == "empty" || CredentialManager.dbUser == "empty" || CredentialManager.dbPassword == "empty") {
|
||||
Logger.out("The config does not contain the whole Database credentials.")
|
||||
exitProcess(3)
|
||||
}
|
||||
|
||||
//Connect to the Database
|
||||
DB.connect(
|
||||
CredentialManager.dbDomain,
|
||||
CredentialManager.dbName,
|
||||
CredentialManager.dbUser,
|
||||
CredentialManager.dbPassword
|
||||
)
|
||||
|
||||
//Add Bot token to kord
|
||||
bot = ExtensibleBot(CredentialManager.token) {
|
||||
applicationCommands {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
extensions {
|
||||
add(::VersionExtension)
|
||||
}
|
||||
|
||||
this.presence {
|
||||
this.status = PresenceStatus.DoNotDisturb
|
||||
this.streaming("v" + BuildConstants.version, "https://www.twitch.tv/deutschesplbundesliga")
|
||||
}
|
||||
}
|
||||
|
||||
//Start the bot
|
||||
bot.start()
|
||||
}
|
||||
}
|
34
src/main/kotlin/de/limited_dev/lilJudd/Main.kt
Normal file
34
src/main/kotlin/de/limited_dev/lilJudd/Main.kt
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* 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.lilJudd
|
||||
|
||||
import de.limited_dev.botendo.build.BuildConstants
|
||||
|
||||
suspend fun main() {
|
||||
println(
|
||||
" \n" +
|
||||
" _ _ _ __ _ _ \n" +
|
||||
"| |_| |__| |_ _ _| |_| |\n" +
|
||||
"| | | | | | | | . | . |\n" +
|
||||
"|_|_|_|_____|___|___|___|\n" +
|
||||
" "
|
||||
)
|
||||
println("v" + BuildConstants.version)
|
||||
|
||||
Bot.start()
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* 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.lilJudd.data
|
||||
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
|
||||
object CredentialManager {
|
||||
private const val foldername = "data"
|
||||
private const val filename = "credentials.nils"
|
||||
lateinit var token: String
|
||||
lateinit var dbDomain: String
|
||||
lateinit var dbName: String
|
||||
lateinit var dbUser: String
|
||||
lateinit var dbPassword: String
|
||||
|
||||
///Load the needed credentials, generate a config if there is none
|
||||
fun load() {
|
||||
val folder = File(foldername)
|
||||
if (!folder.exists()) {
|
||||
save()
|
||||
return
|
||||
}
|
||||
val configFile = File(folder, filename)
|
||||
if (!configFile.exists()) {
|
||||
save()
|
||||
return
|
||||
}
|
||||
try {
|
||||
val input: InputStream = FileInputStream(foldername + File.separator + filename)
|
||||
val prop = Properties()
|
||||
prop.load(input)
|
||||
token = prop.getProperty("token")
|
||||
dbDomain = prop.getProperty("dbDomain")
|
||||
dbName = prop.getProperty("dbName")
|
||||
dbUser = prop.getProperty("dbUser")
|
||||
dbPassword = prop.getProperty("dbPassword")
|
||||
input.close()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
///generate a new sample config
|
||||
private fun save() {
|
||||
val folder = File(foldername)
|
||||
if (!folder.exists()) {
|
||||
try {
|
||||
folder.mkdirs()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
val configFile = File(foldername + File.separator + filename)
|
||||
if (!configFile.exists()) {
|
||||
try {
|
||||
configFile.createNewFile()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
try {
|
||||
val output: OutputStream = FileOutputStream(foldername + File.separator + filename)
|
||||
val prop = Properties()
|
||||
prop.setProperty("token", "empty")
|
||||
prop.setProperty("dbDomain", "empty")
|
||||
prop.setProperty("dbName", "empty")
|
||||
prop.setProperty("dbUser", "empty")
|
||||
prop.setProperty("dbPassword", "empty")
|
||||
prop.store(output, null)
|
||||
output.close()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
40
src/main/kotlin/de/limited_dev/lilJudd/data/DB.kt
Normal file
40
src/main/kotlin/de/limited_dev/lilJudd/data/DB.kt
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* 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.lilJudd.data
|
||||
|
||||
import de.limited_dev.lilJudd.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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* 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.lilJudd.extensions
|
||||
|
||||
import com.kotlindiscord.kord.extensions.extensions.Extension
|
||||
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
|
||||
import de.limited_dev.botendo.build.BuildConstants
|
||||
import de.limited_dev.lilJudd.util.MessageUtil
|
||||
|
||||
class VersionExtension : Extension() {
|
||||
override val name = "version"
|
||||
override suspend fun setup() {
|
||||
publicSlashCommand {
|
||||
name = "version"
|
||||
description = "Show infos about the bot"
|
||||
this.action {
|
||||
MessageUtil.sendEmbedForPublicSlashCommand(
|
||||
this, "Lil' Judd",
|
||||
"Lil' Judd ***v." + BuildConstants.version + "***\n" +
|
||||
"Kord-Extensions ***v." + BuildConstants.kordVersion + "***\n" +
|
||||
"Coroutines ***v." + BuildConstants.coroutinesVersion + "***"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
41
src/main/kotlin/de/limited_dev/lilJudd/util/Logger.kt
Normal file
41
src/main/kotlin/de/limited_dev/lilJudd/util/Logger.kt
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* 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.lilJudd.util
|
||||
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
object Logger {
|
||||
private val dtf: DateTimeFormatter = DateTimeFormatter.ofPattern("yy/MM/dd HH:mm:ss")
|
||||
|
||||
fun out(msg: String) {
|
||||
val caller = Thread.currentThread().stackTrace[2]
|
||||
val now: LocalDateTime = LocalDateTime.now()
|
||||
try {
|
||||
println(
|
||||
("[" + Class.forName(caller.className).simpleName + "." +
|
||||
caller.methodName + ":" + caller.lineNumber + "] [" + dtf.format(now)) + "] <" + msg + ">"
|
||||
)
|
||||
} catch (e: ClassNotFoundException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
// Ich kann nicht mehr
|
||||
// [Klasse.Funktion] [T/M HH:MM] <NACHRICHT>
|
||||
}
|
||||
}
|
91
src/main/kotlin/de/limited_dev/lilJudd/util/MessageUtil.kt
Normal file
91
src/main/kotlin/de/limited_dev/lilJudd/util/MessageUtil.kt
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* 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.lilJudd.util
|
||||
|
||||
import com.kotlindiscord.kord.extensions.commands.Arguments
|
||||
import com.kotlindiscord.kord.extensions.commands.application.slash.PublicSlashCommandContext
|
||||
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
|
||||
import com.kotlindiscord.kord.extensions.types.respond
|
||||
import dev.kord.rest.builder.message.EmbedBuilder
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
object MessageUtil {
|
||||
private val dtf: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy @ HH:mm:ss")
|
||||
|
||||
///Send an embedded message as a reply
|
||||
suspend fun sendEmbedForPublicSlashCommand(
|
||||
ctx: PublicSlashCommandContext<Arguments, ModalForm>,
|
||||
title: String,
|
||||
description: String
|
||||
) {
|
||||
ctx.respond {
|
||||
embeds.add(
|
||||
getEmbed(
|
||||
title,
|
||||
description,
|
||||
ctx.user.asUser().username + "#" + ctx.user.asUser().discriminator
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
///Send an embedded message with an image as a reply
|
||||
suspend fun sendEmbedForPublicSlashCommandWithImage(
|
||||
ctx: PublicSlashCommandContext<Arguments, ModalForm>,
|
||||
title: String,
|
||||
description: String,
|
||||
thumbnailUrl: String
|
||||
) {
|
||||
ctx.respond {
|
||||
embeds.add(
|
||||
getEmbedWithImage(
|
||||
title,
|
||||
description,
|
||||
ctx.user.asUser().username + "#" + ctx.user.asUser().discriminator,
|
||||
thumbnailUrl
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
///Get an embedded msg with title, description and a src
|
||||
fun getEmbed(title: String, description: String, source: String): EmbedBuilder {
|
||||
val now: LocalDateTime = LocalDateTime.now()
|
||||
val ebb = EmbedBuilder()
|
||||
ebb.title = title
|
||||
ebb.description = description
|
||||
ebb.footer = EmbedBuilder.Footer()
|
||||
ebb.footer!!.text = ">" + dtf.format(now) + " - $source"
|
||||
return ebb
|
||||
}
|
||||
|
||||
///Get an embedded msg with image, title, description and a src
|
||||
fun getEmbedWithImage(
|
||||
title: String,
|
||||
description: String,
|
||||
source: String,
|
||||
thumbnailUrl: String
|
||||
): EmbedBuilder {
|
||||
val ebb = getEmbed(title, description, source)
|
||||
ebb.thumbnail = EmbedBuilder.Thumbnail()
|
||||
ebb.thumbnail!!.url = thumbnailUrl
|
||||
return ebb
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* 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.build
|
||||
|
||||
internal object BuildConstants {
|
||||
const val version = "${version}"
|
||||
const val ownerID = "${ownerID}"
|
||||
const val kordVersion = "${kordversion}"
|
||||
const val coroutinesVersion = "${coroutinesversion}"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue