Skip to content

Commit

Permalink
Merge pull request #160 from DreamExposure/develop
Browse files Browse the repository at this point in the history
RC 4.2.3
  • Loading branch information
NovaFox161 authored Sep 6, 2023
2 parents a3b5884 + 7c2e689 commit 0994b5a
Show file tree
Hide file tree
Showing 176 changed files with 2,594 additions and 3,019 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'DreamExposure/DisCal-Discord-Bot' }}
strategy:
matrix:
java: [ 16, 17 ]
java: [ 17 ]
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -93,8 +93,8 @@ jobs:

# Have K8S pull latest images for dev pods
- name: Trigger dev deploy
uses: Consensys/kubernetes-action@master
uses: davi020/kubernetes-action@master
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
with:
args: delete -n discal pods -l profile=dev,app=discal
args: delete -n discal pods -l env=dev,app=discal
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# DisCal

[![Discord](https://img.shields.io/discord/375357265198317579?label=DreamExposure&style=flat-square)](https://discord.gg/2TFqyuy)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/DreamExposure/DisCal-Discord-Bot/Java%20CI?label=Build&style=flat-square)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/DreamExposure/DisCal-Discord-Bot/gradle.yml?branch=develop&label=Build&style=flat-square)
[![Website](https://img.shields.io/website?down_color=red&down_message=offline&label=Status&style=flat-square&up_message=online&url=https%3A%2F%2Fwww.discalbot.com)](https://discalbot.com)

DisCal is a discord bot that connects Discord and Google Calendar as seamlessly as possible with a wide feature set for
Expand Down
140 changes: 79 additions & 61 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,113 +1,124 @@
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType.ALL
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
java

//kotlin
kotlin("jvm")
kotlin("plugin.serialization")
kotlin("plugin.spring") apply false
id("org.jetbrains.kotlin.plugin.allopen") apply false
id("org.jetbrains.kotlin.plugin.allopen")

//Other
// Spring
kotlin("plugin.spring")
id("org.springframework.boot") apply false
id("io.spring.dependency-management")

//Tooling
id("com.gorylenko.gradle-git-properties") apply false
id("com.google.cloud.tools.jib") apply false
}

buildscript {
val kotlinPoetVersion: String by properties
dependencies {
classpath("com.squareup:kotlinpoet:1.7.2")
classpath("com.squareup:kotlinpoet:$kotlinPoetVersion")
}
}

allprojects {
//Project props
group = "org.dreamexposure.discal"
version = "4.2.2"
version = "4.2.3"
description = "DisCal"

//Plugins
apply(plugin = "java")
apply(plugin = "kotlin")
apply(plugin = "io.spring.dependency-management")

//Compiler nonsense
java.sourceCompatibility = JavaVersion.VERSION_16
java.targetCompatibility = JavaVersion.VERSION_16

//Versions
// Versions --- found in gradle.properties
val kotlinVersion: String by properties
val kotlinxSerializationVersion: String by properties

// Tool
val kotlinxCoroutinesReactorVersion: String by properties
val reactorKotlinExtensions: String by properties
// Discord
val discord4jVersion: String by properties
val discord4jStoresVersion: String by properties
val discordWebhookVersion: String by properties
// Spring
val springVersion: String by properties

val googleCoreVersion: String by properties
val googleCalendarVersion: String by properties

val r2MysqlVersion: String by properties
val r2PoolVersion: String by properties

val nettyVersion: String by properties
val reactorBomVersion: String by properties

val slfVersion: String by properties
// Database
val flywayVersion: String by properties
val mikuR2dbcMySqlVersion: String by properties
val mySqlConnectorJava: String by properties
// Serialization
val kotlinxSerializationJsonVersion: String by properties
val jacksonVersion: String by properties
val jsonVersion: String by properties
val okHttpVersion: String by properties
val discordWebhookVersion: String by properties
// Google libs
val googleApiClientVersion: String by properties
val googleServicesCalendarVersion: String by properties
val googleOauthClientVersion: String by properties
// Various libs
val okhttpVersion: String by properties
val copyDownVersion: String by properties
val jsoupVersion: String by properties

repositories {
mavenCentral()
mavenLocal()

maven("https://repo.maven.apache.org/maven2/")
maven("https://kotlin.bintray.com/kotlinx")
maven("https://oss.sonatype.org/content/repositories/snapshots")
maven("https://repo.spring.io/milestone")
maven("https://jitpack.io")
}

dependencies {
//Boms
implementation(platform("io.projectreactor:reactor-bom:$reactorBomVersion"))

//Kotlin Deps
// Tools
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")

//Forced stuff
//slf4j-api - Need to force this for logback to work. I dunno
implementation("org.slf4j:slf4j-api:$slfVersion")
//Netty - forced due to stores-redis:lettuce-core giving 4.1.38
implementation("io.netty:netty-all:$nettyVersion")
//Forcing reactor version
implementation("io.projectreactor:reactor-core")

//Google apis
implementation("com.google.api-client:google-api-client:$googleCoreVersion")
implementation("com.google.apis:google-api-services-calendar:$googleCalendarVersion")
implementation("com.google.oauth-client:google-oauth-client-jetty:$googleCoreVersion") {
exclude(group = "org.mortbay.jetty", module = "servlet-api")
}
//r2dbc
implementation("dev.miku:r2dbc-mysql:$r2MysqlVersion") {
exclude("io.netty", "*")
exclude("io.projectreactor", "*")
exclude("io.projectreactor.netty", "*")
}
implementation("io.r2dbc:r2dbc-pool:$r2PoolVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesReactorVersion")
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions:$reactorKotlinExtensions")

// Discord
implementation("com.discord4j:discord4j-core:$discord4jVersion")
implementation("com.discord4j:stores-redis:$discord4jStoresVersion")
implementation("club.minnced:discord-webhooks:$discordWebhookVersion")

implementation("org.json:json:$jsonVersion")
// Spring
implementation("org.springframework.boot:spring-boot-starter-data-jdbc:$springVersion")
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc:$springVersion")
implementation("org.springframework.boot:spring-boot-starter-data-redis:$springVersion")
implementation("org.springframework.boot:spring-boot-starter-webflux:$springVersion")
implementation("org.springframework.boot:spring-boot-starter-cache:$springVersion")

implementation("com.squareup.okhttp3:okhttp:$okHttpVersion")
// Database
implementation("dev.miku:r2dbc-mysql:$mikuR2dbcMySqlVersion")
implementation("mysql:mysql-connector-java:$mySqlConnectorJava")

implementation("club.minnced:discord-webhooks:$discordWebhookVersion")
// Serialization
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationJsonVersion")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
implementation("org.json:json:$jsonVersion")

// Google libs
implementation("com.google.api-client:google-api-client:$googleApiClientVersion")
implementation("com.google.apis:google-api-services-calendar:$googleServicesCalendarVersion")
implementation("com.google.oauth-client:google-oauth-client-jetty:$googleOauthClientVersion") {
exclude(group = "org.mortbay.jetty", module = "servlet-api")
}

// Various Libs
implementation("com.squareup.okhttp3:okhttp:$okhttpVersion")
implementation("io.github.furstenheim:copy_down:$copyDownVersion")
implementation("org.jsoup:jsoup:$jsoupVersion")
}

//Spring
implementation("org.springframework.boot:spring-boot-starter-webflux:$springVersion")
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc:$springVersion")
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlin {
Expand All @@ -127,9 +138,16 @@ subprojects {
withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = targetCompatibility
jvmTarget = java.targetCompatibility.majorVersion
}
}
}
}

tasks {
wrapper {
distributionType = ALL
gradleVersion = "8.2.1"
}
}

28 changes: 11 additions & 17 deletions cam/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
plugins {
// Kotlin
kotlin("plugin.serialization")
id("org.jetbrains.kotlin.plugin.allopen")

// Spring
kotlin("plugin.spring")
id("org.springframework.boot")
id("org.jetbrains.kotlin.plugin.allopen")
id("io.spring.dependency-management")

// Tooling
id("com.google.cloud.tools.jib")
}

val springSessionVersion: String by properties
val springR2Version: String by properties
val jacksonKotlinModVersion: String by properties

dependencies {
api(project(":core"))

//Spring libs
implementation("org.springframework.session:spring-session-data-redis:$springSessionVersion")
implementation("org.springframework:spring-r2dbc:$springR2Version")

//jackson for kotlin
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonKotlinModVersion")
}

kotlin {
Expand All @@ -30,14 +25,13 @@ kotlin {
}

jib {
var imageVersion = version.toString()
if (imageVersion.contains("SNAPSHOT")) imageVersion = "latest"
to {
image = "rg.nl-ams.scw.cloud/dreamexposure/discal-cam"
tags = mutableSetOf("latest", version.toString())
}

to.image = "rg.nl-ams.scw.cloud/dreamexposure/discal-cam:$imageVersion"
val baseImage: String by properties
from.image = baseImage

container.creationTime = "USE_CURRENT_TIMESTAMP"
}

tasks {
Expand Down
25 changes: 4 additions & 21 deletions cam/src/main/kotlin/org/dreamexposure/discal/cam/Cam.kt
Original file line number Diff line number Diff line change
@@ -1,45 +1,28 @@
package org.dreamexposure.discal.cam

import jakarta.annotation.PreDestroy
import org.dreamexposure.discal.Application
import org.dreamexposure.discal.cam.google.GoogleInternalAuthHandler
import org.dreamexposure.discal.core.`object`.BotSettings
import org.dreamexposure.discal.core.database.DatabaseManager
import org.dreamexposure.discal.core.config.Config
import org.dreamexposure.discal.core.logger.LOGGER
import org.dreamexposure.discal.core.utils.GlobalVal
import org.springframework.boot.builder.SpringApplicationBuilder
import org.springframework.stereotype.Component
import java.io.FileReader
import java.util.*
import javax.annotation.PreDestroy
import kotlin.system.exitProcess

@Component
class Cam {

@PreDestroy
fun onShutdown() {
LOGGER.info(GlobalVal.STATUS, "CAM shutting down.")
DatabaseManager.disconnectFromMySQL()
}
fun onShutdown() = LOGGER.info(GlobalVal.STATUS, "CAM shutting down.")

companion object {
@JvmStatic
fun main(args: Array<String>) {
//Get settings
val p = Properties()
p.load(FileReader("settings.properties"))
BotSettings.init(p)

//Handle generating new google auth credentials for discal accounts
if (args.size > 1 && args[0].equals("-forceNewGoogleAuth", true)) {
//This will automatically kill this instance once finished
GoogleInternalAuthHandler.requestCode(args[1].toInt()).subscribe()
}
Config.init()

//Start up spring
try {
SpringApplicationBuilder(Application::class.java)
.profiles(BotSettings.PROFILE.get())
.build()
.run(*args)
LOGGER.info(GlobalVal.STATUS, "CAM is now online")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.dreamexposure.discal.cam.business

import org.dreamexposure.discal.OauthStateCache
import org.dreamexposure.discal.core.crypto.KeyGenerator
import org.springframework.stereotype.Component

@Component
class OauthStateService(
private val stateCache: OauthStateCache,
) {
suspend fun generateState(): String {
val state = KeyGenerator.csRandomAlphaNumericString(64)
stateCache.put(state, state)

return state
}

suspend fun validateState(state: String) = stateCache.getAndRemove(state) != null
}
Loading

0 comments on commit 0994b5a

Please sign in to comment.