chore: moved package and group from de.limited-dev to net.moonleay, fixed group in build.gradle.kts

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-05-18 17:27:31 +02:00
parent 4e4da2422f
commit fed4bd7fe1
13 changed files with 28 additions and 28 deletions

View file

@ -0,0 +1,80 @@
/*
* 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 net.moonleay.lilJudd
import com.kotlindiscord.kord.extensions.ExtensibleBot
import dev.kord.common.entity.PresenceStatus
import net.moonleay.botendo.build.BuildConstants
import net.moonleay.lilJudd.data.CredentialManager
import net.moonleay.lilJudd.data.DB
import net.moonleay.lilJudd.extensions.FeatureManageExtension
import net.moonleay.lilJudd.extensions.VersionExtension
import net.moonleay.lilJudd.util.Logger
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)
add(::FeatureManageExtension)
}
this.presence {
this.status = PresenceStatus.DoNotDisturb
this.playing("v." + BuildConstants.version)
}
}
//Start the bot
bot.start()
}
}

View 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 net.moonleay.lilJudd
import net.moonleay.botendo.build.BuildConstants
suspend fun main() {
println(
" \n" +
" _ _ _ __ _ _ \n" +
"| |_| |__| |_ _ _| |_| |\n" +
"| | | | | | | | . | . |\n" +
"|_|_|_|_____|___|___|___|\n" +
" "
)
println("v" + BuildConstants.version)
Bot.start()
}

View file

@ -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 net.moonleay.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()
}
}
}

View 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 net.moonleay.lilJudd.data
import org.jetbrains.exposed.sql.Database
object DB {
//Connect to the provided DB; trows errors, if the DB is not avalible.
fun connect(dbDomain: String, dbName: String, dbUser: String, dbPasswd: String) {
Database.connect(
"jdbc:postgresql://$dbDomain/$dbName",
driver = "org.postgresql.Driver",
user = dbUser,
password = dbPasswd
)
}
}

View file

@ -0,0 +1,27 @@
/*
* 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 net.moonleay.lilJudd.data.tables
import org.jetbrains.exposed.dao.id.IntIdTable
object TimePlanningChannels : IntIdTable() {
//val aid = integer("id").autoIncrement()
var serverid = varchar("serverid", 50)
val channelid = varchar("channelid", 50)
}

View file

@ -0,0 +1,188 @@
/*
* 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 net.moonleay.lilJudd.extensions
import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.application.slash.converters.impl.enumChoice
import com.kotlindiscord.kord.extensions.commands.converters.impl.channel
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.hasPermission
import dev.kord.common.Color
import dev.kord.common.entity.Permission
import net.moonleay.lilJudd.data.tables.TimePlanningChannels
import net.moonleay.lilJudd.data.tables.TimePlanningChannels.channelid
import net.moonleay.lilJudd.data.tables.TimePlanningChannels.serverid
import net.moonleay.lilJudd.extensions.component.EnableOrDisable
import net.moonleay.lilJudd.extensions.component.Feature
import net.moonleay.lilJudd.util.MessageUtil
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
class FeatureManageExtension : Extension() {
override val name = "feature"
override suspend fun setup() {
publicSlashCommand(::FeatureManagerArgs) {
name = "feature"
description = "Manage features"
this.action {
val u = this.user
if (!u.asMember(this.guild!!.id).hasPermission(Permission.Administrator)) {
this.respond {
embeds.add(
MessageUtil.getEmbed(
Color(0xE0311A),
"403: Forbidden",
"You cannot edit features, as you don't have the Administratior permission.",
u.asUser().username + "#" + u.asUser().discriminator
)
)
}
return@action
}
if (this.arguments.setStatus == EnableOrDisable.ENABLE) {
when (this.arguments.feature) {
Feature.TIMEPLANNINGFEATURE -> {
val gID = this.guild!!.id.toString()
val cID = this.arguments.channel.id.toString()
val args = this.arguments
var alreadyExists: Boolean = false
transaction {
val entryExists = TimePlanningChannels.select {
(serverid eq gID) and
(channelid eq cID)
}.count() > 0
alreadyExists = entryExists
}
if (!alreadyExists) {
transaction {
TimePlanningChannels.insert {
it[serverid] = gID
it[channelid] = cID
} get TimePlanningChannels.id
}
this.respond {
embeds.add(
MessageUtil.getEmbed(
Color(0x52E01A),
"200: Success",
"The feature was enabled in channel ${args.channel.data.name}",
u.asUser().username + "#" + u.asUser().discriminator
)
)
}
return@action
}
this.respond {
embeds.add(
MessageUtil.getEmbed(
Color(0xE0311A),
"403: Forbidden",
"The feature is already enabled in this channel.",
u.asUser().username + "#" + u.asUser().discriminator
)
)
}
}
}
return@action
}
//Disable
when (this.arguments.feature) {
Feature.TIMEPLANNINGFEATURE -> {
val gID = this.guild!!.id.toString()
val cID = this.arguments.channel.id.toString()
var alreadyExists = false
transaction {
val entryExists = TimePlanningChannels.select {
(serverid eq gID) and
(channelid eq cID)
}.count() > 0
alreadyExists = entryExists
}
if (alreadyExists) {
transaction {
val matchingEntries = TimePlanningChannels.select {
(serverid eq gID) and
(channelid eq cID)
}.toList()
matchingEntries.forEach { entry ->
TimePlanningChannels.deleteWhere { id eq entry[id] }
}
}
this.respond {
embeds.add(
MessageUtil.getEmbed(
Color(0x52E019),
"200: Success",
"The feature was disabled.",
u.asUser().username + "#" + u.asUser().discriminator
)
)
}
return@action
}
this.respond {
embeds.add(
MessageUtil.getEmbed(
Color(0xE0311A),
"403: Forbidden",
"The feature is already disabled in this channel.",
u.asUser().username + "#" + u.asUser().discriminator
)
)
}
}
}
}
}
}
inner class FeatureManagerArgs : Arguments() {
val feature by enumChoice<Feature> {
this.name = "feature"
this.description = "The targeted feature"
this.typeName = "en_US"
}
val setStatus by enumChoice<EnableOrDisable> {
this.name = "set"
this.description = "Set enabled or disabled"
this.typeName = "en_US"
}
val channel by channel {
this.name = "channel"
this.description = "Target Channel"
}
}
}

View file

@ -0,0 +1,45 @@
/*
* 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 net.moonleay.lilJudd.extensions
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import dev.kord.common.Color
import net.moonleay.botendo.build.BuildConstants
import net.moonleay.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,
Color(0x52E01A),
"Lil' Judd",
"Lil' Judd ***v." + BuildConstants.version + "***\n" +
"Kord-Extensions ***v." + BuildConstants.kordVersion + "***\n" +
"Coroutines ***v." + BuildConstants.coroutinesVersion + "***"
)
}
}
}
}

View file

@ -0,0 +1,27 @@
/*
* 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 net.moonleay.lilJudd.extensions.component
import com.kotlindiscord.kord.extensions.commands.application.slash.converters.ChoiceEnum
enum class EnableOrDisable(override val readableName: String) : ChoiceEnum {
ENABLE("Enable"),
DISABLE("Disable");
}

View file

@ -0,0 +1,25 @@
/*
* 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 net.moonleay.lilJudd.extensions.component
import com.kotlindiscord.kord.extensions.commands.application.slash.converters.ChoiceEnum
enum class Feature(override val readableName: String) : ChoiceEnum {
TIMEPLANNINGFEATURE("Time Planning Feature");
}

View 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 net.moonleay.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>
}
}

View file

@ -0,0 +1,103 @@
/*
* 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 net.moonleay.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.common.Color
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>,
color: Color,
title: String,
description: String
) {
ctx.respond {
embeds.add(
getEmbed(
color,
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>,
color: Color,
title: String,
description: String,
thumbnailUrl: String
) {
ctx.respond {
embeds.add(
getEmbedWithImage(
color,
title,
description,
ctx.user.asUser().username + "#" + ctx.user.asUser().discriminator,
thumbnailUrl
)
)
}
}
///Get an embedded msg with title, description and a src
fun getEmbed(
color: Color,
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"
ebb.color = color
return ebb
}
///Get an embedded msg with image, title, description and a src
fun getEmbedWithImage(
color: Color,
title: String,
description: String,
source: String,
thumbnailUrl: String
): EmbedBuilder {
val ebb = getEmbed(color, title, description, source)
ebb.thumbnail = EmbedBuilder.Thumbnail()
ebb.thumbnail!!.url = thumbnailUrl
return ebb
}
}