package dev.w1zzrd.swearnt import net.dv8tion.jda.api.entities.Message import net.dv8tion.jda.api.requests.RestAction import java.io.File import java.util.concurrent.TimeUnit fun MutableCollection.addAllNoDups(elements: Collection): Boolean = addAll(elements.filterNot(this::contains)) fun RestAction.submitAndDelete( delay: Long = BOT_MESSAGE_CLEANUP_DELAY, timeUnit: TimeUnit = TimeUnit.MILLISECONDS ) = submit().thenAccept { it.delete().submitAfter(delay, timeUnit) } fun T.load(fileName: String): T where T: MutableCollection { val file = File(fileName) if (file.isFile) addAllNoDups(file.readLines()) return this } fun Iterable.save(fileName: String) { val file = File(fileName) if (file.isFile && (!file.delete() || !file.createNewFile())) System.err.println("Failed to save file \"$fileName\"") else file.writeText(reduce { acc, s -> "$acc\n$s" }) }