Add better howto's to commands
This commit is contained in:
parent
984a39cafa
commit
ff29659882
|
@ -119,6 +119,7 @@ fun main(args: Array<String>) {
|
|||
.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`" }, false)
|
||||
eb.addField("Usage", "`!${cmd.howTo.emptyOr(cmd.name)}`", false)
|
||||
|
||||
}
|
||||
event.args == "help" -> {
|
||||
|
|
|
@ -16,12 +16,14 @@ 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
|
||||
val cname = if (c.category == null) "Unknown" else c.category.name
|
||||
if (!m.containsKey(cname)) {
|
||||
m[cname] = mutableListOf()
|
||||
}
|
||||
|
||||
m[cname]!!+=c
|
||||
m[cname]!! += c
|
||||
}
|
||||
return m
|
||||
}
|
||||
}
|
||||
|
||||
fun String.emptyOr(other: String): String = if (this.isEmpty()) other else this
|
|
@ -22,7 +22,7 @@ fun initMusic() {
|
|||
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 (!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()) {
|
||||
event.reply("Please supply a song name or URL!")
|
||||
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()) {
|
||||
event.reply("Please supply a song name or URL!")
|
||||
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()) {
|
||||
event.reply("Please supply a song name or URL!")
|
||||
return@UnityMusicCommand
|
||||
|
|
|
@ -44,7 +44,8 @@ val generalCategory = Command.Category("General commands") {
|
|||
|
||||
open class UnityCommand(name: String, help: String = "",
|
||||
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 {
|
||||
super.name = name
|
||||
super.help = help
|
||||
|
@ -58,7 +59,9 @@ open class UnityCommand(name: String, help: String = "",
|
|||
|
||||
class UnityMusicCommand(name: String, help: String = "",
|
||||
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) {
|
||||
val scheduler = if (guildMusicMap.containsKey(event.guild.idLong)) guildMusicMap[event.guild.idLong]!! else {
|
||||
val channel = event.guild.voiceChannels.firstOrNull { it.members.contains(event.member) }
|
||||
|
|
Loading…
Reference in a new issue