Skip to content

Commit

Permalink
Fully implement command forwarding
Browse files Browse the repository at this point in the history
Added:
+ Command forwarding is now possible using either prefix or
  @tag syntax
+ Command forwarding works with any command from any plugin
  that can be run from server console
+ Command output is sent back to Discord

Modified:
* Refactored some of the icky duplicate code in dispatchMessage into
  a standalone function
  • Loading branch information
DiamondIceNS committed Dec 13, 2017
1 parent 1ab20a0 commit 68258c2
Show file tree
Hide file tree
Showing 4 changed files with 292 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package gg.obsidian.discordbridge.commands

import net.dv8tion.jda.core.entities.MessageChannel
import org.bukkit.Bukkit
import org.bukkit.Server
import org.bukkit.command.CommandSender
import org.bukkit.command.ConsoleCommandSender
import org.bukkit.command.RemoteConsoleCommandSender
import org.bukkit.permissions.Permission
import org.bukkit.permissions.PermissionAttachment
import org.bukkit.permissions.PermissionAttachmentInfo
import org.bukkit.plugin.Plugin

class DiscordCommandSender(val channel: MessageChannel) : RemoteConsoleCommandSender {

private val sender:ConsoleCommandSender = Bukkit.getServer().consoleSender

init {

}

override fun sendMessage(message: String?) {
channel.sendMessage(message).queue()
}

override fun sendMessage(messages: Array<out String>?) {
if (messages != null)
for (m in messages) channel.sendMessage(m)
}

override fun spigot(): CommandSender.Spigot {
return sender.spigot()
}

override fun addAttachment(plugin: Plugin?): PermissionAttachment {
return sender.addAttachment(plugin)
}

override fun addAttachment(plugin: Plugin?, ticks: Int): PermissionAttachment {
return sender.addAttachment(plugin, ticks)
}

override fun addAttachment(plugin: Plugin?, name: String?, value: Boolean): PermissionAttachment {
return sender.addAttachment(plugin, name, value)
}

override fun addAttachment(plugin: Plugin?, name: String?, value: Boolean, ticks: Int): PermissionAttachment {
return sender.addAttachment(plugin, name, value, ticks)
}

override fun getEffectivePermissions(): MutableSet<PermissionAttachmentInfo> {
return sender.effectivePermissions
}

override fun getName(): String {
return sender.name
}

override fun getServer(): Server {
return sender.server
}

override fun hasPermission(name: String?): Boolean {
return sender.hasPermission(name)
}

override fun hasPermission(perm: Permission?): Boolean {
return sender.hasPermission(perm)
}

override fun isOp(): Boolean {
return sender.isOp
}

override fun isPermissionSet(name: String?): Boolean {
return sender.isPermissionSet(name)
}

override fun isPermissionSet(perm: Permission?): Boolean {
return sender.isPermissionSet(perm)
}

override fun recalculatePermissions() {
return sender.recalculatePermissions()
}

override fun removeAttachment(attachment: PermissionAttachment?) {
return sender.removeAttachment(attachment)
}

override fun setOp(value: Boolean) {
return sender.setOp(value)
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ package gg.obsidian.discordbridge.commands.annotations
* @param description a short string that describes the command's function
* @param name an optional field to override the command's access name if it is not the same as the method name
* @param relayTriggerMessage whether the message used to trigger this command should be relayed
* @param ignoreExcessArguments if false, this command will fail if the invoker provides too many arguments
* @param squishExcessArgs if true, this command will put all extra args passed to it into a single string
*/
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class BotCommand(val usage: String, val description: String, val name: String = "",
val relayTriggerMessage: Boolean = true, val ignoreExcessArguments: Boolean = true)
val relayTriggerMessage: Boolean = true, val squishExcessArgs: Boolean = false)
Loading

0 comments on commit 68258c2

Please sign in to comment.