package nl.voidcorp.dbot import com.google.gson.Gson import com.google.gson.GsonBuilder import nl.voidcorp.dbot.commands.UnityCommand import javax.script.ScriptEngineManager import kotlin.random.Random val gson: Gson = GsonBuilder().setPrettyPrinting().create() fun MutableList.addAll(vararg e: E) = this.addAll(listOf(*e)) fun List.random(): E = this[Random.nextInt(this.size)] fun List.catMap(): Map> { val m = mutableMapOf>() for (c in this) { val cname = c.category.name if (!m.containsKey(cname)) { m[cname] = mutableListOf() } m[cname]!! += c } return m } fun String.emptyOr(other: String): String = if (this.isEmpty()) other else this val sem = ScriptEngineManager() fun run(st: String, ret: String = "x", scriptEngine: String = "luaj"): Any { val se = sem.getEngineByName(scriptEngine) se.eval(st) return se.get(ret) }