forked from QuiltMC/cozy-discord
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix logging - Add mass-ping timeout exceptions - Add "ping groups": customizable role-less pingable groups - Fix strange weirdness in SettingsExtension.kt
- Loading branch information
Showing
14 changed files
with
1,082 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/org/quiltmc/community/database/collections/PingGroupCollection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/org/quiltmc/community/database/entities/PingGroup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.