add proper help command
This commit is contained in:
parent
a980ace51e
commit
65195f7303
|
@ -15,6 +15,7 @@ import net.dv8tion.jda.core.JDA
|
|||
import net.dv8tion.jda.core.JDABuilder
|
||||
import net.dv8tion.jda.core.MessageBuilder
|
||||
import net.dv8tion.jda.core.entities.Game
|
||||
import net.dv8tion.jda.core.entities.MessageEmbed
|
||||
import net.dv8tion.jda.webhook.WebhookClient
|
||||
import net.dv8tion.jda.webhook.WebhookClientBuilder
|
||||
import nl.voidcorp.dbot.commands.helloCommand
|
||||
|
@ -24,6 +25,7 @@ import nl.voidcorp.dbot.storage.GitlabWebhook
|
|||
import org.slf4j.LoggerFactory
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
import java.time.LocalDateTime
|
||||
|
||||
val playerManager = DefaultAudioPlayerManager()
|
||||
|
||||
|
@ -99,6 +101,16 @@ fun main(args: Array<String>) {
|
|||
val replies = listOf("Hello %%", "Why hello there %%!", "Hello there %%", "General %%. You are a bold one", "A wild %% appeared!")
|
||||
cb.setHelpConsumer { event ->
|
||||
val greeting = replies.random().replace("%%", event.member.effectiveName)
|
||||
val eb = EmbedBuilder().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.joinToString(separator = "\n") { "!${it.name}" }, true)
|
||||
eb.addField(f)
|
||||
}
|
||||
eb.setThumbnail(event.selfUser.effectiveAvatarUrl)
|
||||
val mb = MessageBuilder("$greeting\n").append {
|
||||
var st = ""
|
||||
for (c in commands) {
|
||||
|
@ -108,7 +120,7 @@ fun main(args: Array<String>) {
|
|||
}
|
||||
|
||||
|
||||
event.reply(mb.build())
|
||||
event.reply(eb.build())
|
||||
}
|
||||
|
||||
initMusic()
|
||||
|
|
|
@ -2,6 +2,7 @@ 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()
|
||||
|
@ -10,4 +11,17 @@ 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 <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
|
||||
}
|
Loading…
Reference in a new issue