package nl.voidcorp.dbot.commands import net.dv8tion.jda.core.EmbedBuilder import net.dv8tion.jda.core.MessageBuilder import net.dv8tion.jda.core.entities.MessageEmbed import nl.voidcorp.dbot.catMap import nl.voidcorp.dbot.commands import nl.voidcorp.dbot.emptyOr import nl.voidcorp.dbot.random import java.time.LocalDateTime import java.time.temporal.ChronoUnit val helloCommand = UnityCommand("hello", "Say hello to Andy!", aliases = *arrayOf()) { it.reply(MessageBuilder("Hello, ").append(it.author).append("!").build()) } val pingCommand = UnityCommand("ping", help = "Check the bot's ping", aliases = *arrayOf("pong")) { event -> event.reply("Ping: ...") { m -> val ping = event.message.creationTime.until(m.creationTime, ChronoUnit.MILLIS) m.editMessage("Ping: " + ping + "ms | Websocket: " + event.jda.ping + "ms").queue() } } val replies = listOf("Hello %%", "Why hello there %%!", "Hello there %%", "General %%. You are a bold one", "A wild %% appeared!") val helpCommand = UnityCommand("help", "Guess what?"/*, category = UnityCategory("Yeet", channels = listOf())*/) { event -> val greeting = replies.random().replace("%%", event.member.effectiveName) val eb = EmbedBuilder() when { event.args.isEmpty() -> { eb.setTitle(greeting) .appendDescription("My name is ${event.selfMember.effectiveName}, and I am definitely the best Discord bot around!\n\nUse `!help command` for a chance that I have more info about a command!") .setColor(event.selfMember.color).setFooter("Requested by ${event.member.effectiveName}", event.author.effectiveAvatarUrl).setTimestamp(LocalDateTime.now()) val m = commands.catMap() for (e in m.entries) { val f = MessageEmbed.Field(e.key, e.value.asSequence().filter { it.name != "help" }.joinToString(separator = "\n", postfix = "\n") { "`!${it.name}`" }, true) eb.addField(f) } eb.setThumbnail(event.selfUser.effectiveAvatarUrl) } event.args == "help" -> { eb.setTitle("Ha Ha") .appendDescription("Ha ha, very funny ${event.member.effectiveName}") .setColor(event.selfMember.color).setFooter("Requested by ${event.member.effectiveName}", event.author.effectiveAvatarUrl).setTimestamp(LocalDateTime.now()) } commands.any { it.name == event.args } -> { val cmd = commands.first { it.name == event.args } eb.setTitle("**!${cmd.name}**") .appendDescription(cmd.help) .setColor(event.selfMember.color).setFooter("Requested by ${event.member.effectiveName}", event.author.effectiveAvatarUrl).setTimestamp(LocalDateTime.now()) if (cmd.aliases.isNotEmpty()) eb.addField("Aliases", cmd.aliases.joinToString { "`$it`" }, true) eb.addField("Usage", "`!${cmd.howTo.emptyOr(cmd.name)}`", true) val cat = cmd.category if (cat is UnityCategory) { if (cat.roles.isNotEmpty()) eb.addField("Roles", cat.roles.joinToString { "`$it`" }, true) } } else -> { eb.setTitle(greeting) .appendDescription("I honestly have no idea what the command `${event.args}` does...") .setColor(event.selfMember.color).setFooter("Requested by ${event.member.effectiveName}", event.author.effectiveAvatarUrl).setTimestamp(LocalDateTime.now()) } } event.reply(eb.build()) }