Skip to content

Commit

Permalink
Merge pull request #58 from the-obsidian/command-forwarding
Browse files Browse the repository at this point in the history
Command forwarding
  • Loading branch information
DiamondIceNS authored Dec 15, 2017
2 parents 135623f + ad69465 commit a976a29
Show file tree
Hide file tree
Showing 11 changed files with 396 additions and 148 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.apache.tools.ant.filters.ReplaceTokens

buildscript {
ext.kotlin_version = '1.1.51'
ext.kotlin_version = '1.2.0'

repositories {
mavenCentral()
Expand All @@ -22,7 +22,7 @@ plugins {
apply plugin: 'kotlin'

group = 'gg.obsidian'
version = '3.0.1'
version = '3.1.0'
description = """Bridge chat between Minecraft and Discord"""
ext.url = 'https://github.com/the-obsidian/DiscordBridge'

Expand Down
26 changes: 13 additions & 13 deletions src/main/kotlin/gg/obsidian/discordbridge/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Plugin : JavaPlugin() {
/**
* Saves all default configs where configs do not exist and reloads data from file into memory
*/
fun updateConfig(version: String) {
private fun updateConfig(version: String) {
this.saveDefaultConfig()
config.options().copyDefaults(true)
config.set("version", version)
Expand Down Expand Up @@ -182,7 +182,7 @@ class Plugin : JavaPlugin() {
val users = Connection.listUsers()
val found: Member = users.find { it.user.name + "#" + it.user.discriminator == discriminator } ?: return null

val ua: UserAlias = UserAlias(player.uniqueId, found.user.id)
val ua = UserAlias(player.uniqueId, found.user.id)
requests.add(ua)
val msg = "Minecraft user '${server.getOfflinePlayer(ua.mcUuid).name}' has requested to become associated with your Discord" +
" account. If this is you, respond '${Connection.JDA.selfUser.asMention} confirm'. If this is not" +
Expand All @@ -203,8 +203,8 @@ class Plugin : JavaPlugin() {

var response = "${CC.YELLOW}Discord users:"
for (user in users) {
if (user.user.isBot) response += "\n${CC.GOLD}- ${user.effectiveName} (Bot) | ${user.user.name}#${user.user.discriminator}${CC.RESET}"
else response += "\n${CC.YELLOW}- ${user.effectiveName} | ${user.user.name}#${user.user.discriminator}${CC.RESET}"
response += if (user.user.isBot) "\n${CC.GOLD}- ${user.effectiveName} (Bot) | ${user.user.name}#${user.user.discriminator}${CC.RESET}"
else "\n${CC.YELLOW}- ${user.effectiveName} | ${user.user.name}#${user.user.discriminator}${CC.RESET}"
}
return response.trim()
}
Expand All @@ -218,25 +218,25 @@ class Plugin : JavaPlugin() {
return "${CC.YELLOW}No Discord members could be found. Either server is empty or an error has occurred."

var response = ""
if (onlineUsers.filter { it.onlineStatus == OnlineStatus.ONLINE }.isNotEmpty()) {
if (onlineUsers.any { it.onlineStatus == OnlineStatus.ONLINE }) {
response += "\n${CC.DARK_GREEN}Online:${CC.RESET}"
for (user in onlineUsers.filter { it.onlineStatus == OnlineStatus.ONLINE }) {
if (user.user.isBot) response += "\n${CC.DARK_GREEN}- ${user.effectiveName} (Bot)${CC.RESET}"
else response += "\n${CC.DARK_GREEN}- ${user.effectiveName}${CC.RESET}"
response += if (user.user.isBot) "\n${CC.DARK_GREEN}- ${user.effectiveName} (Bot)${CC.RESET}"
else "\n${CC.DARK_GREEN}- ${user.effectiveName}${CC.RESET}"
}
}
if (onlineUsers.filter { it.onlineStatus == OnlineStatus.IDLE }.isNotEmpty()) {
if (onlineUsers.any { it.onlineStatus == OnlineStatus.IDLE }) {
response += "\n${CC.YELLOW}Idle:${CC.RESET}"
for (user in onlineUsers.filter { it.onlineStatus == OnlineStatus.IDLE }) {
if (user.user.isBot) response += "\n${CC.YELLOW}- ${user.effectiveName} (Bot)${CC.RESET}"
else response += "\n${CC.YELLOW}- ${user.effectiveName}${CC.RESET}"
response += if (user.user.isBot) "\n${CC.YELLOW}- ${user.effectiveName} (Bot)${CC.RESET}"
else "\n${CC.YELLOW}- ${user.effectiveName}${CC.RESET}"
}
}
if (onlineUsers.filter { it.onlineStatus == OnlineStatus.DO_NOT_DISTURB }.isNotEmpty()) {
if (onlineUsers.any { it.onlineStatus == OnlineStatus.DO_NOT_DISTURB }) {
response += "\n${CC.RED}Do Not Disturb:${CC.RESET}"
for (user in onlineUsers.filter { it.onlineStatus == OnlineStatus.DO_NOT_DISTURB }) {
if (user.user.isBot) response += "\n${CC.RED}- ${user.effectiveName} (Bot)${CC.RESET}"
else response += "\n${CC.RED}- ${user.effectiveName}${CC.RESET}"
response += if (user.user.isBot) "\n${CC.RED}- ${user.effectiveName} (Bot)${CC.RESET}"
else "\n${CC.RED}- ${user.effectiveName}${CC.RESET}"
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/gg/obsidian/discordbridge/UserAliasConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object UserAliasConfig {
*/
fun load(plugin: Plugin) {
val list = plugin.users.data.getList("aliases")
if (list != null) aliases = list.checkItemsAre<UserAlias>() ?:
if (list != null) aliases = list.checkItemsAre() ?:
throw IllegalStateException("usernames.yml could not be read - list items are not properly formatted")
else mutableListOf<UserAlias>()
}
Expand Down Expand Up @@ -42,5 +42,5 @@ object UserAliasConfig {
* A function to assert that all the items in a given list are of a specific type
*/
@Suppress("UNCHECKED_CAST")
inline fun <reified T : Any> List<*>.checkItemsAre() = if (all { it is T }) this as List<T> else null
private inline fun <reified T : Any> List<*>.checkItemsAre() = if (all { it is T }) this as List<T> else null
}
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 a976a29

Please sign in to comment.