Skip to content

Commit

Permalink
Fix + add features
Browse files Browse the repository at this point in the history
 - Fix logging
 - Add mass-ping timeout exceptions
 - Add "ping groups": customizable role-less pingable groups
 - Fix strange weirdness in SettingsExtension.kt
  • Loading branch information
sschr15 committed Sep 18, 2023
1 parent cecd859 commit c1bb64d
Show file tree
Hide file tree
Showing 14 changed files with 1,082 additions and 245 deletions.
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ val versions = versionFileContents
.filter { it.isNotBlank() }
.map { it.trim() }
.map { it.split("=") }
.filter { it.size == 2 }
.associate { (k, v) -> k.trim() to v.substringAfter('"').substringBefore('"') }

repositories {
Expand Down
1 change: 0 additions & 1 deletion buildSrc/src/main/kotlin/cozy-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ tasks {
withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}
}

Expand Down
8 changes: 4 additions & 4 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
detekt = "1.23.1"
kotlin = "1.9.0"
kotlin = "1.9.10"
graphql = "6.5.3"

autolink = "0.11.0"
Expand All @@ -20,11 +20,11 @@ kaml = "0.55.0"
kmongo = "4.10.0"
kordex = "1.5.9-SNAPSHOT"
kotlintest = "3.4.2"
ksp = "1.9.0-1.0.13"
ksp = "1.9.10-1.0.13"
ktor = "2.3.3"
kx-ser = "1.6.0"
logback = "1.4.5"
logback-groovy = "1.14.0"
logback = "1.4.11"
logback-groovy = "1.14.5"
logging = "3.0.5"
moshi = "1.15.0"
rgxgen = "1.4"
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/org/quiltmc/community/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.kotlindiscord.kord.extensions.utils.getKoin
import dev.kord.core.entity.Guild
import dev.kord.core.event.interaction.ChatInputCommandInteractionCreateEvent
import dev.kord.core.event.interaction.GuildChatInputCommandInteractionCreateEvent
import dev.kord.gateway.ALL
import dev.kord.gateway.Intents
import dev.kord.gateway.PrivilegedIntent
import dev.kord.rest.builder.message.create.embed
Expand Down Expand Up @@ -66,7 +67,7 @@ suspend fun setupLadysnake() = ExtensibleBot(DISCORD_TOKEN) {
}

intents {
+Intents.all
+Intents.ALL
}

members {
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/org/quiltmc/community/_Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ suspend fun ExtensibleBotBuilder.database(migrate: Boolean = false) {
single { TagsCollection() } bind TagsCollection::class
single { WelcomeChannelCollection() } bind WelcomeChannelCollection::class
single { QuoteCollection() } bind QuoteCollection::class
single { PingGroupCollection() } bind PingGroupCollection::class
}

if (migrate) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.quiltmc.community.database.collections

import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent
import dev.kord.common.entity.Snowflake
import org.koin.core.component.inject
import org.litote.kmongo.and
import org.litote.kmongo.contains
import org.litote.kmongo.eq
import org.quiltmc.community.database.Collection
import org.quiltmc.community.database.Database
import org.quiltmc.community.database.entities.PingGroup

class PingGroupCollection : KordExKoinComponent {
private val database: Database by inject()
private val col = database.mongo.getCollection<PingGroup>(name)

suspend fun get(id: String) =
col.findOne(PingGroup::_id eq id)

suspend fun set(pingGroup: PingGroup) =
col.save(pingGroup)

suspend fun getAll(guild: Snowflake, allowAny: Boolean): List<PingGroup> {
val guildEquals = PingGroup::guildId eq guild
if (allowAny) return col.find(guildEquals).toList()
return col.find(and(guildEquals, PingGroup::canSelfSubscribe eq true)).toList()
}

suspend fun getByUser(guild: Snowflake, user: Snowflake): List<PingGroup> {
val guildEquals = PingGroup::guildId eq guild
return col.find(and(guildEquals, PingGroup::users contains user)).toList()
}

suspend fun delete(id: String) =
col.deleteOne(PingGroup::_id eq id)

companion object : Collection("ping-groups")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

@file:Suppress("DataClassShouldBeImmutable") // Well, yes, but actually no.

package org.quiltmc.community.database.entities

import dev.kord.common.entity.Snowflake
import kotlinx.serialization.Serializable
import org.quiltmc.community.database.Entity

@Serializable
data class PingGroup(
override val _id: String,
val name: String,
val guildId: Snowflake,
var canSelfSubscribe: Boolean = false,
val emoji: String? = null,
val desc: String? = null,
val users: MutableSet<Snowflake> = mutableSetOf(),
) : Entity<String>
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ data class ServerSettings(
var leaveServer: Boolean = false,
val threadOnlyChannels: MutableSet<Snowflake> = mutableSetOf(),
var defaultThreadLength: ArchiveDuration? = null,

val pingTimeoutBlacklist: MutableSet<Snowflake> = mutableSetOf(),
) : Entity<Snowflake> {
suspend fun save() {
val collection = getKoin().get<ServerSettingsCollection>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,13 @@ object AllMigrations {
}
}
}

suspend fun v26(db: CoroutineDatabase) {
db.getCollection<ServerSettings>(ServerSettingsCollection.name).updateMany(
ServerSettings::pingTimeoutBlacklist exists false,
setValue(ServerSettings::pingTimeoutBlacklist, mutableSetOf())
)

db.createCollection(PingGroupCollection.name)
}
}
Loading

0 comments on commit c1bb64d

Please sign in to comment.