27 lines
712 B
Kotlin
27 lines
712 B
Kotlin
package nl.voidcorp.dbot
|
|
|
|
import com.google.gson.Gson
|
|
import com.google.gson.GsonBuilder
|
|
import com.jagrosh.jdautilities.command.Command
|
|
import java.util.*
|
|
|
|
val gson: Gson = GsonBuilder().setPrettyPrinting().create()
|
|
|
|
val random = Random()
|
|
|
|
fun <E> MutableList<E>.addAll(vararg e: E) = this.addAll(listOf(*e))
|
|
|
|
fun <E> List<E>.random(): E = this[random.nextInt(this.size)]
|
|
|
|
fun List<Command>.catMap(): Map<String, List<Command>> {
|
|
val m = mutableMapOf<String, MutableList<Command>>()
|
|
for (c in this) {
|
|
val cname = if (c.category==null) "Unknown" else c.category.name
|
|
if (!m.containsKey(cname)) {
|
|
m[cname] = mutableListOf()
|
|
}
|
|
|
|
m[cname]!!+=c
|
|
}
|
|
return m
|
|
} |