75 lines
3.1 KiB
Kotlin
75 lines
3.1 KiB
Kotlin
package nl.voidcorp.dbot.commands
|
|
|
|
import com.jagrosh.jdautilities.command.Command
|
|
import com.jagrosh.jdautilities.command.CommandEvent
|
|
import nl.voidcorp.dbot.music.TrackScheduler
|
|
import nl.voidcorp.dbot.playerManager
|
|
|
|
val musicCategory = Command.Category("Music Commands") {
|
|
val botExists = it.guild.getTextChannelsByName("bot", true).firstOrNull() != null
|
|
val musicExists = it.guild.getTextChannelsByName("music", true).firstOrNull() != null
|
|
val musicBotExists = it.guild.getTextChannelsByName("music-bot", true).firstOrNull() != null
|
|
when {
|
|
musicBotExists -> {
|
|
val res = it.textChannel.name == "music-bot"
|
|
|
|
if (!res) it.reply("Music commands are only supported in the ${it.guild.getTextChannelsByName("music-bot", true).first().asMention} channel!")
|
|
res
|
|
}
|
|
musicExists -> {
|
|
val res = it.textChannel.name == "music"
|
|
if (!res) it.reply("Music commands are only supported in the ${it.guild.getTextChannelsByName("music", true).first().asMention} channel!")
|
|
res
|
|
}
|
|
botExists -> {
|
|
val res = it.textChannel.name == "bot"
|
|
if (!res) it.reply("Music commands are only supported in the ${it.guild.getTextChannelsByName("bot", true).first().asMention} channel!")
|
|
res
|
|
}
|
|
else -> true
|
|
}
|
|
|
|
}
|
|
|
|
val generalCategory = Command.Category("General commands") {
|
|
if (it.guild.getTextChannelsByName("bot", true).firstOrNull() == null) return@Category true
|
|
val test = it.textChannel.name.contains("bot")
|
|
if (!test) {
|
|
it.reply("Non music commands can only be used in the ${it.guild.getTextChannelsByName("bot", true).first().asMention} channel")
|
|
}
|
|
|
|
test
|
|
|
|
}
|
|
|
|
open class UnityCommand(name: String, help: String = "",
|
|
category: Category = generalCategory,
|
|
arguments: String = "", vararg aliases: String = arrayOf(), val exec: (event: CommandEvent) -> Unit) : Command() {
|
|
init {
|
|
super.name = name
|
|
super.help = help
|
|
super.category = category
|
|
super.arguments = arguments
|
|
super.aliases = aliases
|
|
}
|
|
|
|
override fun execute(event: CommandEvent) = exec(event)
|
|
}
|
|
|
|
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 = {}) {
|
|
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) }
|
|
if (channel == null) {
|
|
event.reply("Join a voice Channel please!")
|
|
return
|
|
}
|
|
val s = TrackScheduler(playerManager.createPlayer(), event.guild, channel)
|
|
guildMusicMap[event.guild.idLong] = s
|
|
s
|
|
}
|
|
mExec(event, scheduler)
|
|
}
|
|
} |