Skip to content

Commit

Permalink
Add Gallery of Dreams Discord bot, allow adding fan arts to the galle…
Browse files Browse the repository at this point in the history
…ry via the "/galleryofdreams" command
  • Loading branch information
MrPowerGamerBR committed Oct 15, 2024
1 parent b194b50 commit de7e497
Show file tree
Hide file tree
Showing 45 changed files with 1,956 additions and 11 deletions.
6 changes: 6 additions & 0 deletions backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ dependencies {
implementation("io.ktor:ktor-server-cors:${Versions.KTOR}")
implementation("io.ktor:ktor-server-compression:${Versions.KTOR}")
implementation("io.ktor:ktor-server-caching-headers:${Versions.KTOR}")
implementation("net.perfectdreams.etherealgambi:client:1.0.2")

implementation("ch.qos.logback:logback-classic:1.5.10")
implementation("commons-codec:commons-codec:1.15")

// https://mvnrepository.com/artifact/org.jsoup/jsoup
implementation("org.jsoup:jsoup:1.16.1")

// Discord
implementation("com.github.LorittaBot:DeviousJDA:4235406ee9")
implementation("club.minnced:jda-ktx:0.12.0")

// Databases
implementation("org.jetbrains.exposed:exposed-core:0.55.0")
implementation("org.jetbrains.exposed:exposed-jdbc:0.55.0")
Expand All @@ -43,6 +48,7 @@ dependencies {
implementation("org.yaml:snakeyaml:2.3")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:${Versions.KOTLINX_SERIALIZATION}")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-hocon:${Versions.KOTLINX_SERIALIZATION}")

// https://mvnrepository.com/artifact/club.minnced/discord-webhooks
implementation("club.minnced:discord-webhooks:0.8.4")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import io.ktor.server.routing.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import mu.KotlinLogging
import net.dv8tion.jda.api.JDABuilder
import net.dv8tion.jda.api.entities.Activity
import net.dv8tion.jda.api.requests.GatewayIntent
import net.dv8tion.jda.api.utils.MemberCachePolicy
import net.perfectdreams.etherealgambi.client.EtherealGambiClient
import net.perfectdreams.galleryofdreams.backend.config.GalleryOfDreamsConfig
import net.perfectdreams.galleryofdreams.backend.interactions.vanilla.GalleryOfDreamsCommand
import net.perfectdreams.galleryofdreams.backend.plugins.configureRouting
import net.perfectdreams.galleryofdreams.backend.routes.*
import net.perfectdreams.galleryofdreams.backend.routes.api.GetFanArtArtistByDiscordIdRoute
Expand All @@ -35,6 +42,9 @@ import net.perfectdreams.galleryofdreams.backend.utils.*
import net.perfectdreams.galleryofdreams.backend.utils.exposed.createOrUpdatePostgreSQLEnum
import net.perfectdreams.galleryofdreams.common.FanArtTag
import net.perfectdreams.galleryofdreams.common.data.*
import net.perfectdreams.loritta.morenitta.interactions.InteractionsListener
import net.perfectdreams.loritta.morenitta.interactions.InteractivityManager
import net.perfectdreams.loritta.morenitta.interactions.commands.UnleashedCommandManager
import org.jetbrains.exposed.exceptions.ExposedSQLException
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
Expand All @@ -46,7 +56,10 @@ import java.sql.ResultSet
import java.time.Duration
import kotlin.concurrent.thread

class GalleryOfDreamsBackend(val languageManager: LanguageManager) {
class GalleryOfDreamsBackend(
val config: GalleryOfDreamsConfig,
val languageManager: LanguageManager
) {
companion object {
private val logger = KotlinLogging.logger {}
val webhookLinkRegex = Regex("https?://(?:[A-z]+\\.)?discord\\.com/api/webhooks/([0-9]+)/([A-z0-9-_]+)")
Expand Down Expand Up @@ -107,8 +120,28 @@ class GalleryOfDreamsBackend(val languageManager: LanguageManager) {
.build()
}
val svgIconManager = SVGIconManager(this)
val commandManager = UnleashedCommandManager(this)
val interactivityManager = InteractivityManager()
val etherealGambiClient = EtherealGambiClient(config.etherealGambi.url)

fun start() {
commandManager.register(GalleryOfDreamsCommand(this))

// We only care about specific intents
val jda = JDABuilder.createLight(
config.discord.token,
GatewayIntent.GUILD_MEMBERS,
GatewayIntent.MESSAGE_CONTENT
)
.addEventListeners(
InteractionsListener(this),
)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.setRawEventsEnabled(true)
.setActivity(Activity.customStatus("fanarts.perfectdreams.net"))
.build()
.awaitReady()

runBlocking {
transaction {
createOrUpdatePostgreSQLEnum(FanArtTag.values())
Expand Down Expand Up @@ -304,7 +337,7 @@ class GalleryOfDreamsBackend(val languageManager: LanguageManager) {
fanArt[FanArts.title],
fanArt[FanArts.description],
fanArt[FanArts.createdAt],
fanArt[FanArts.dreamStorageServiceImageId],
0, // unused
fanArt[FanArts.file],
fanArt[FanArts.preferredMediaType],
FanArtTags.select(FanArtTags.tag).where { FanArtTags.fanArt eq fanArt[FanArts.id] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package net.perfectdreams.galleryofdreams.backend

import com.typesafe.config.ConfigFactory
import kotlinx.serialization.hocon.Hocon
import kotlinx.serialization.hocon.decodeFromConfig
import net.perfectdreams.galleryofdreams.backend.config.GalleryOfDreamsConfig
import net.perfectdreams.galleryofdreams.backend.utils.LanguageManager
import java.io.File

object GalleryOfDreamsBackendLauncher {
@JvmStatic
fun main(args: Array<String>) {
val config = Hocon.decodeFromConfig<GalleryOfDreamsConfig>(ConfigFactory.parseString(File("gallery-of-dreams.conf").readText(Charsets.UTF_8)).resolve())

val languageManager = LanguageManager(
GalleryOfDreamsBackend::class,
"en",
"/languages/"
)
languageManager.loadLanguagesAndContexts()

val m = GalleryOfDreamsBackend(languageManager)
val m = GalleryOfDreamsBackend(config, languageManager)
m.start()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.perfectdreams.galleryofdreams.backend.config

import kotlinx.serialization.Serializable

@Serializable
data class GalleryOfDreamsConfig(
val discord: DiscordConfig,
val etherealGambi: EtherealGambiConfig
) {
@Serializable
data class DiscordConfig(
val token: String
)

@Serializable
data class EtherealGambiConfig(
val authorizationToken: String,
val url: String
)
}
Loading

0 comments on commit de7e497

Please sign in to comment.