Skip to content

Commit

Permalink
added a lot of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
FireBall1725 committed Feb 21, 2024
1 parent 280fb69 commit 7bae9a2
Show file tree
Hide file tree
Showing 18 changed files with 690 additions and 20 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ on:
pull_request:
branches: [ "main" ]

jobs:

build:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

- name: Login to the container registry
uses: docker/login-action

- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
7 changes: 7 additions & 0 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ dependencies {
implementation("com.fasterxml.jackson.module", "jackson-module-kotlin", "2.16.+")
implementation("com.fasterxml.jackson.dataformat", "jackson-dataformat-yaml", "2.16.+")

implementation("org.postgresql:postgresql:42.7.1")

testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation(libs.junit.jupiter.engine)
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
Expand Down
5 changes: 5 additions & 0 deletions app/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@
| Help | [Command] | Display a help menu. |
| info | | Bot info for app |

## profile
| Commands | Arguments | Description |
|----------------|-----------|-------------------|
| devEditProfile | | Edit your profile |

5 changes: 5 additions & 0 deletions app/config/BotConfig-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
"backup_download": {
"enabled": false
},
"database_configuration": {
"jdbc_url": "jdbc:postgresql://localhost:5432/lostcrafters_db",
"database_username": "Username",
"database_password": "P@ssword!"
},
"is_dev_env": true
}
52 changes: 44 additions & 8 deletions app/src/main/kotlin/ca/fireball1725/lcs/discordbot/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ package ca.fireball1725.lcs.discordbot

import ca.fireball1725.lcs.discordbot.data.Configuration
import ca.fireball1725.lcs.discordbot.data.config.BotConfig
import ca.fireball1725.lcs.discordbot.helpers.Database
import ca.fireball1725.lcs.discordbot.mcserver.Pterodactyl
import ca.fireball1725.lcs.discordbot.mcserver.Server
import ca.fireball1725.lcs.discordbot.services.BotPermissions
import ca.fireball1725.lcs.discordbot.tasks.JsonStatsProcessor
import ca.fireball1725.lcs.discordbot.tasks.MembersProcessor
import com.google.gson.Gson
import dev.kord.common.annotation.KordPreview
import dev.kord.core.entity.Guild
import dev.kord.gateway.Intents
import dev.kord.gateway.PrivilegedIntent
import dev.kord.x.emoji.Emojis
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking
import me.jakejmattson.discordkt.dsl.CommandException
import me.jakejmattson.discordkt.dsl.ListenerException
import me.jakejmattson.discordkt.dsl.bot
Expand All @@ -25,6 +31,8 @@ import java.io.Reader
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path
import java.util.Timer
import kotlin.concurrent.scheduleAtFixedRate

private val configPath = FileSystems.getDefault().getPath("config", "botConfig.json")
private val botConfig: BotConfig = loadBotConfig(configPath)
Expand All @@ -33,8 +41,16 @@ private val pterodactyl: Pterodactyl = Pterodactyl(botConfig.pterodactylToken, b

private val servers: MutableMap<String, Server> = mutableMapOf()

private val database: Database = Database()

private var guilds: List<Guild>? = null

@OptIn(PrivilegedIntent::class)
@KordPreview
suspend fun main(args: Array<String>) {
// Connect to the database
database.connect()

// todo: Load the servers from database
servers["b1107111"] =
Server(
Expand All @@ -56,11 +72,11 @@ suspend fun main(args: Array<String>) {
"Vault Hunters",
)

servers["e932250f"] =
Server(
"e932250f",
"FTB Arcanum Institution",
)
// servers["e932250f"] =
// Server(
// "e932250f",
// "FTB Arcanum Institution",
// )

val prop = System.getProperties()

Expand Down Expand Up @@ -106,7 +122,7 @@ suspend fun main(args: Array<String>) {
theme = Color(0xFF69B4)

// Configure the Discord Gateway intents for your bot.
intents = Intents.nonPrivileged
intents = Intents.all

// Set the default permission required for slash commands.
defaultPermissions = BotPermissions.EVERYONE
Expand All @@ -130,8 +146,8 @@ suspend fun main(args: Array<String>) {

// This is run once the bot has finished setup and logged in.
onStart {
val guilds = kord.guilds.toList()
println("Guilds: ${guilds.joinToString { it.name }}")
guilds = kord.guilds.toList()
println("Guilds: ${guilds!!.joinToString { it.name }}")
}

// Configure the locale for this bot.
Expand All @@ -140,6 +156,18 @@ suspend fun main(args: Array<String>) {
helpCategory = "Utility"
commandRecommendation = "Recommendation: {0}"
}

// Schedule processing json files
Timer().scheduleAtFixedRate(10000, 1000 * 60 * 15) { // 15 minutes
JsonStatsProcessor().processJsonStats()
}

// Schedule member updates
Timer().scheduleAtFixedRate(10000, 1000 * 60 * 15) {// 15 minutes
runBlocking {
MembersProcessor().updateMembersTable()
}
}
}
}

Expand Down Expand Up @@ -167,3 +195,11 @@ fun getServer(serverId: String): Server? {
null
}
}

fun getDatabase(): Database {
return database
}

fun getGuilds(): List<Guild>? {
return guilds
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Created for the Lost Crafters SMP (https://www.lostcrafterssmp.com)
* Licensed under the GNU Affero General Public License v3.0
* See LICENSE.txt for full license information
*/

package ca.fireball1725.lcs.discordbot.commands

import ca.fireball1725.lcs.discordbot.getDatabase


class EditProfile {
fun getEditProfileLink(discordId:ULong): String {
val member = getDatabase().getMemberFromDiscordId(discordId)

return if (member != null) {
val token = getDatabase().createSessionToken(member.member_id)

val url = "https://www.lostcrafterssmp.com/login/${token}"

var resultString = ""
resultString += "# Edit Profile\n"
resultString += "Click [Here](<$url>) to edit your profile\n"
resultString
} else {
"Error"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ data class BotConfig(
val whitelist: BotConfigConfigWhitelist,
@SerializedName("backup_download")
val backupDownload: BotConfigConfigBackupDownload,
@SerializedName("database_configuration")
val databaseConfiguration: BotDatabaseConfiguration
)

data class BotConfigConfigWhitelist(
Expand All @@ -36,3 +38,12 @@ data class BotConfigConfigBackupDownload(
@SerializedName("enabled")
val enabled: Boolean,
)

data class BotDatabaseConfiguration(
@SerializedName("jdbc_url")
val jdbcUrl: String,
@SerializedName("database_username")
val databaseUsername: String,
@SerializedName("database_password")
val databasePassword: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Created for the Lost Crafters SMP (https://www.lostcrafterssmp.com)
* Licensed under the GNU Affero General Public License v3.0
* See LICENSE.txt for full license information
*/

package ca.fireball1725.lcs.discordbot.data.database

import java.util.UUID

data class Member(
val member_id: UUID,
val display_username: String,
val discord_id: Long,
val pronouns: String?,
val country: String?,
val description: String?,
val show_on_website: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Created for the Lost Crafters SMP (https://www.lostcrafterssmp.com)
* Licensed under the GNU Affero General Public License v3.0
* See LICENSE.txt for full license information
*/

package ca.fireball1725.lcs.discordbot.data.database

import java.util.UUID

data class Server(
val server_id: UUID,
val pterodactyl_id: UUID,
val server_name: String,
val description: String,
val gamemode: String?,
val pack_url: String?,
val live_map_url: String?,
val server_live: Boolean,
val server_started: String?,
val server_finished: String?,
val game_name: String?,
val game_url: String?,
val game_icon: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Created for the Lost Crafters SMP (https://www.lostcrafterssmp.com)
* Licensed under the GNU Affero General Public License v3.0
* See LICENSE.txt for full license information
*/

package ca.fireball1725.lcs.discordbot.data.pterodactyl

import com.google.gson.annotations.SerializedName

data class GetDirectoryList (
@SerializedName("object")
var obj: String? = null,

@SerializedName("data")
var data: ArrayList<GetDirectoryListData> = arrayListOf(),
)

data class GetDirectoryListData (
@SerializedName("object")
var obj: String? = null,

@SerializedName("attributes")
var attributes: GetWorldBackupDataAttributes? = GetWorldBackupDataAttributes()
)

data class GetDirectoryListAttributes (
@SerializedName("name")
var name: String? = null,

@SerializedName("mode")
var mode: String? = null,

@SerializedName("size")
var size: Long? = null,

@SerializedName("is_file")
var isFile: Boolean? = null,

@SerializedName("is_symlink")
var isSymLink: Boolean? = null,

@SerializedName("is_editable")
var isEditable: Boolean? = null,

@SerializedName("mimetype")
var mimetype: String? = null,

@SerializedName("created_at")
var createdAt: String? = null,

@SerializedName("modified_at")
var modifiedAt: String? = null,
)
Loading

0 comments on commit 7bae9a2

Please sign in to comment.