OttoBot/src/main/kotlin/nl/voidcorp/dbot/storage/GuildSettings.kt

37 lines
1.0 KiB
Kotlin

package nl.voidcorp.dbot.storage
import net.dv8tion.jda.core.entities.Guild
import net.dv8tion.jda.core.entities.Role
import nl.voidcorp.dbot.commands.GSM
import java.time.LocalDateTime
data class GuildSettings(
val prefixes: MutableList<String> = mutableListOf(),
val muted: MutableMap<LocalDateTime, MutableList<MuteInfo>> = mutableMapOf(),
val roleMap: MutableMap<String, Long> = mutableMapOf()
) {
fun getPrefixes(): MutableCollection<String> {
return prefixes
}
val primaryPrefix: String
get() = prefixes.firstOrNull() ?: "!"
}
fun Guild.settings(): GuildSettings {
return GSM.getSettings(this)
}
data class MuteInfo(val member: Long, val roles: List<Role>)
fun <A> Map<LocalDateTime, A>.getBefore(test: LocalDateTime = LocalDateTime.now()): List<A> =
this.filter { it.key.isBefore(test) }.map { it.value }
fun <A> MutableMap<LocalDateTime, MutableList<A>>.put(a: LocalDateTime, b: A) {
if (this[a] == null) {
this[a] = mutableListOf()
}
this[a]!! += b
}