package nl.voidcorp.dbot.commands import com.jagrosh.jdautilities.command.Command import com.jagrosh.jdautilities.command.CommandEvent import net.dv8tion.jda.core.entities.ChannelType import net.dv8tion.jda.core.entities.TextChannel open class UnityCategory(name: String, val channels: List = listOf("bot"), val roles: List = listOf(), val errorMessage: (TextChannel) -> String = { "This command can only be used in ${it.asMention}." }, val check: (CommandEvent) -> Boolean = { true }) : Command.Category(name) { override fun test(ce: CommandEvent): Boolean { /*if (ce.member.hasPermission(Permission.ADMINISTRATOR)) return true*/ if (ce.member.roles.firstOrNull { it.name.equals("admin", true) } != null) return true if (channels.all { ce.guild.getTextChannelsByName(it, true).firstOrNull() == null }) return true if (channels.isEmpty()) return true lateinit var ch: TextChannel for (channel in channels.map { ce.guild.getTextChannelsByName(it, true).firstOrNull() }) { if (channel != null) { ch = channel } } return if (ce.channelType == ChannelType.PRIVATE) { true } else { if (ce.textChannel != ch) { ce.reply(errorMessage(ch)) false } else { if (roles.isNotEmpty()) { val rnames = ce.member.roles.map { it.name } if (roles.intersect(rnames).isEmpty()) { ce.reply("You need one of these roles to execute this command: ${roles.joinToString { "`$it`" }}") return false } } check(ce) } } /* val test = ce.textChannel.name.contains("bot") if (!test) { ce.reply("Non music commands can only be used in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} channel") } return test and check(ce)*/ } } object GeneralCategory : UnityCategory("general") /*val MusicCategory = Command.Category("Music Commands") { ce -> if (ce.member.roles.firstOrNull { it.name.equals("admin", true) } != null) return@Category true val botExists = ce.guild.getTextChannelsByName("bot", true).firstOrNull() != null val musicExists = ce.guild.getTextChannelsByName("music", true).firstOrNull() != null val musicBotExists = ce.guild.getTextChannelsByName("music-bot", true).firstOrNull() != null when { musicBotExists -> { val res = ce.textChannel.name == "music-bot" if (!res) ce.reply("Music commands are only supported in the ${ce.guild.getTextChannelsByName("music-bot", true).first().asMention} channel!") res } musicExists -> { val res = ce.textChannel.name == "music" if (!res) ce.reply("Music commands are only supported in the ${ce.guild.getTextChannelsByName("music", true).first().asMention} channel!") res } botExists -> { val res = ce.textChannel.name == "bot" if (!res) ce.reply("Music commands are only supported in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} channel!") res } else -> true } }*/ object MusicCategory : UnityCategory("Music Commands", listOf("bot", "music", "music-bot"), errorMessage = { "Music commands can only be used in ${it.asMention}!" }) object MusicCategoryPrivate : UnityCategory("Music Commands", listOf("bot", "music", "music-bot"), listOf("admin"), { "Music commands can only be used in ${it.asMention}!" }) /* val GeneralCategory = Command.Category("General commands") { ce -> if (ce.member.roles.firstOrNull { it.name.equals("admin", true) } != null) return@Category true if (ce.guild.getTextChannelsByName("bot", true).firstOrNull() == null) return@Category true val test = ce.textChannel.name.contains("bot") if (!test) { ce.reply("Non music commands can only be used in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} channel") } test }*/ /*val FunCategory = Command.Category("Fun Commands") { ce -> if (ce.member.roles.firstOrNull { it.name.equals("admin", true) } != null) return@Category true if (ce.guild.getTextChannelsByName("bot", true).firstOrNull() == null) return@Category true val test = ce.textChannel.name.contains("bot") if (!test) { ce.reply("Non music commands can only be used in the ${ce.guild.getTextChannelsByName("bot", true).first().asMention} channel") } test }*/ object FunCategory : UnityCategory("Fun commands")