Add better howto's to commands

This commit is contained in:
Julius de Jeu 2018-10-25 13:47:54 +02:00
parent 984a39cafa
commit ff29659882
4 changed files with 15 additions and 9 deletions

View file

@ -119,6 +119,7 @@ fun main(args: Array<String>) {
.appendDescription(cmd.help) .appendDescription(cmd.help)
.setColor(event.selfMember.color).setFooter("Requested by ${event.member.effectiveName}", event.author.effectiveAvatarUrl).setTimestamp(LocalDateTime.now()) .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`" }, false) if (cmd.aliases.isNotEmpty()) eb.addField("Aliases", cmd.aliases.joinToString { "`$it`" }, false)
eb.addField("Usage", "`!${cmd.howTo.emptyOr(cmd.name)}`", false)
} }
event.args == "help" -> { event.args == "help" -> {

View file

@ -16,12 +16,14 @@ fun <E> List<E>.random(): E = this[random.nextInt(this.size)]
fun List<Command>.catMap(): Map<String, List<Command>> { fun List<Command>.catMap(): Map<String, List<Command>> {
val m = mutableMapOf<String, MutableList<Command>>() val m = mutableMapOf<String, MutableList<Command>>()
for (c in this) { for (c in this) {
val cname = if (c.category==null) "Unknown" else c.category.name val cname = if (c.category == null) "Unknown" else c.category.name
if (!m.containsKey(cname)) { if (!m.containsKey(cname)) {
m[cname] = mutableListOf() m[cname] = mutableListOf()
} }
m[cname]!!+=c m[cname]!! += c
} }
return m return m
} }
fun String.emptyOr(other: String): String = if (this.isEmpty()) other else this

View file

@ -22,7 +22,7 @@ fun initMusic() {
AudioSourceManagers.registerRemoteSources(playerManager) AudioSourceManagers.registerRemoteSources(playerManager)
val queueCommand = UnityMusicCommand("queue", aliases = *arrayOf("q"), help = "Use this command to queue a song, if you don't add a link it will search on youtube with the specified arguments\n\nExecute with no arguments to view the current queue!") { event, scheduler -> val queueCommand = UnityMusicCommand("queue", aliases = *arrayOf("q"), help = "Use this command to queue a song, if you don't add a link it will search on youtube with the specified arguments\n\nExecute with no arguments to view the current queue!", howTo = "q [link]") { event, scheduler ->
if (event.args.isEmpty()) { if (event.args.isEmpty()) {
if (!guildMusicMap.containsKey(event.guild.idLong) || (guildMusicMap[event.guild.idLong]!!.player.playingTrack == null)) if (!guildMusicMap.containsKey(event.guild.idLong) || (guildMusicMap[event.guild.idLong]!!.player.playingTrack == null))
@ -58,7 +58,7 @@ fun initMusic() {
}) })
} }
val ytCommand = UnityMusicCommand("youtube", aliases = *arrayOf("yt"), help = "Search YouTube for a song!") { event, scheduler -> val ytCommand = UnityMusicCommand("youtube", aliases = *arrayOf("yt"), help = "Search YouTube for a song!", howTo = "youtube <search term or link>") { event, scheduler ->
if (event.args.isEmpty()) { if (event.args.isEmpty()) {
event.reply("Please supply a song name or URL!") event.reply("Please supply a song name or URL!")
return@UnityMusicCommand return@UnityMusicCommand
@ -87,7 +87,7 @@ fun initMusic() {
}) })
} }
val soundcloudCommand = UnityMusicCommand("soundcloud", help = "Play a song via SoundCloud!", aliases = *arrayOf("sc")) { event, scheduler -> val soundcloudCommand = UnityMusicCommand("soundcloud", help = "Play a song via SoundCloud!", aliases = *arrayOf("sc"), howTo = "sc <link or search term>") { event, scheduler ->
if (event.args.isEmpty()) { if (event.args.isEmpty()) {
event.reply("Please supply a song name or URL!") event.reply("Please supply a song name or URL!")
return@UnityMusicCommand return@UnityMusicCommand
@ -117,7 +117,7 @@ fun initMusic() {
}) })
} }
val playCommand = UnityMusicCommand("play", "Force this song to be the next!", aliases = *arrayOf("p")) { event, scheduler -> val playCommand = UnityMusicCommand("play", "Force this song to be the next!", aliases = *arrayOf("p"), howTo = "play <url>") { event, scheduler ->
if (event.args.isEmpty()) { if (event.args.isEmpty()) {
event.reply("Please supply a song name or URL!") event.reply("Please supply a song name or URL!")
return@UnityMusicCommand return@UnityMusicCommand

View file

@ -44,7 +44,8 @@ val generalCategory = Command.Category("General commands") {
open class UnityCommand(name: String, help: String = "", open class UnityCommand(name: String, help: String = "",
category: Category = generalCategory, category: Category = generalCategory,
arguments: String = "", vararg aliases: String = arrayOf(), val exec: (event: CommandEvent) -> Unit) : Command() { arguments: String = "", vararg aliases: String = arrayOf(), val howTo: String = "",
val exec: (event: CommandEvent) -> Unit) : Command() {
init { init {
super.name = name super.name = name
super.help = help super.help = help
@ -58,7 +59,9 @@ open class UnityCommand(name: String, help: String = "",
class UnityMusicCommand(name: String, help: String = "", class UnityMusicCommand(name: String, help: String = "",
category: Category = musicCategory, category: Category = musicCategory,
arguments: String = "", vararg aliases: String = arrayOf(name.first().toString()), val mExec: (event: CommandEvent, scheduler: TrackScheduler) -> Unit) : UnityCommand(name, help, category, arguments, *aliases, exec = {}) { arguments: String = "", vararg aliases: String = arrayOf(name.first().toString()),
howTo: String = "",
val mExec: (event: CommandEvent, scheduler: TrackScheduler) -> Unit) : UnityCommand(name, help, category, arguments, *aliases, howTo = howTo, exec = {}) {
override fun execute(event: CommandEvent) { override fun execute(event: CommandEvent) {
val scheduler = if (guildMusicMap.containsKey(event.guild.idLong)) guildMusicMap[event.guild.idLong]!! else { val scheduler = if (guildMusicMap.containsKey(event.guild.idLong)) guildMusicMap[event.guild.idLong]!! else {
val channel = event.guild.voiceChannels.firstOrNull { it.members.contains(event.member) } val channel = event.guild.voiceChannels.firstOrNull { it.members.contains(event.member) }