Skip to content

Commit a976a29

Browse files
authored
Merge pull request #58 from the-obsidian/command-forwarding
Command forwarding
2 parents 135623f + ad69465 commit a976a29

File tree

11 files changed

+396
-148
lines changed

11 files changed

+396
-148
lines changed

Diff for: build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.apache.tools.ant.filters.ReplaceTokens
22

33
buildscript {
4-
ext.kotlin_version = '1.1.51'
4+
ext.kotlin_version = '1.2.0'
55

66
repositories {
77
mavenCentral()
@@ -22,7 +22,7 @@ plugins {
2222
apply plugin: 'kotlin'
2323

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

Diff for: src/main/kotlin/gg/obsidian/discordbridge/Plugin.kt

+13-13
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class Plugin : JavaPlugin() {
136136
/**
137137
* Saves all default configs where configs do not exist and reloads data from file into memory
138138
*/
139-
fun updateConfig(version: String) {
139+
private fun updateConfig(version: String) {
140140
this.saveDefaultConfig()
141141
config.options().copyDefaults(true)
142142
config.set("version", version)
@@ -182,7 +182,7 @@ class Plugin : JavaPlugin() {
182182
val users = Connection.listUsers()
183183
val found: Member = users.find { it.user.name + "#" + it.user.discriminator == discriminator } ?: return null
184184

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

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

220220
var response = ""
221-
if (onlineUsers.filter { it.onlineStatus == OnlineStatus.ONLINE }.isNotEmpty()) {
221+
if (onlineUsers.any { it.onlineStatus == OnlineStatus.ONLINE }) {
222222
response += "\n${CC.DARK_GREEN}Online:${CC.RESET}"
223223
for (user in onlineUsers.filter { it.onlineStatus == OnlineStatus.ONLINE }) {
224-
if (user.user.isBot) response += "\n${CC.DARK_GREEN}- ${user.effectiveName} (Bot)${CC.RESET}"
225-
else response += "\n${CC.DARK_GREEN}- ${user.effectiveName}${CC.RESET}"
224+
response += if (user.user.isBot) "\n${CC.DARK_GREEN}- ${user.effectiveName} (Bot)${CC.RESET}"
225+
else "\n${CC.DARK_GREEN}- ${user.effectiveName}${CC.RESET}"
226226
}
227227
}
228-
if (onlineUsers.filter { it.onlineStatus == OnlineStatus.IDLE }.isNotEmpty()) {
228+
if (onlineUsers.any { it.onlineStatus == OnlineStatus.IDLE }) {
229229
response += "\n${CC.YELLOW}Idle:${CC.RESET}"
230230
for (user in onlineUsers.filter { it.onlineStatus == OnlineStatus.IDLE }) {
231-
if (user.user.isBot) response += "\n${CC.YELLOW}- ${user.effectiveName} (Bot)${CC.RESET}"
232-
else response += "\n${CC.YELLOW}- ${user.effectiveName}${CC.RESET}"
231+
response += if (user.user.isBot) "\n${CC.YELLOW}- ${user.effectiveName} (Bot)${CC.RESET}"
232+
else "\n${CC.YELLOW}- ${user.effectiveName}${CC.RESET}"
233233
}
234234
}
235-
if (onlineUsers.filter { it.onlineStatus == OnlineStatus.DO_NOT_DISTURB }.isNotEmpty()) {
235+
if (onlineUsers.any { it.onlineStatus == OnlineStatus.DO_NOT_DISTURB }) {
236236
response += "\n${CC.RED}Do Not Disturb:${CC.RESET}"
237237
for (user in onlineUsers.filter { it.onlineStatus == OnlineStatus.DO_NOT_DISTURB }) {
238-
if (user.user.isBot) response += "\n${CC.RED}- ${user.effectiveName} (Bot)${CC.RESET}"
239-
else response += "\n${CC.RED}- ${user.effectiveName}${CC.RESET}"
238+
response += if (user.user.isBot) "\n${CC.RED}- ${user.effectiveName} (Bot)${CC.RESET}"
239+
else "\n${CC.RED}- ${user.effectiveName}${CC.RESET}"
240240
}
241241
}
242242

Diff for: src/main/kotlin/gg/obsidian/discordbridge/UserAliasConfig.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object UserAliasConfig {
1313
*/
1414
fun load(plugin: Plugin) {
1515
val list = plugin.users.data.getList("aliases")
16-
if (list != null) aliases = list.checkItemsAre<UserAlias>() ?:
16+
if (list != null) aliases = list.checkItemsAre() ?:
1717
throw IllegalStateException("usernames.yml could not be read - list items are not properly formatted")
1818
else mutableListOf<UserAlias>()
1919
}
@@ -42,5 +42,5 @@ object UserAliasConfig {
4242
* A function to assert that all the items in a given list are of a specific type
4343
*/
4444
@Suppress("UNCHECKED_CAST")
45-
inline fun <reified T : Any> List<*>.checkItemsAre() = if (all { it is T }) this as List<T> else null
45+
private inline fun <reified T : Any> List<*>.checkItemsAre() = if (all { it is T }) this as List<T> else null
4646
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package gg.obsidian.discordbridge.commands
2+
3+
import net.dv8tion.jda.core.entities.MessageChannel
4+
import org.bukkit.Bukkit
5+
import org.bukkit.Server
6+
import org.bukkit.command.CommandSender
7+
import org.bukkit.command.ConsoleCommandSender
8+
import org.bukkit.command.RemoteConsoleCommandSender
9+
import org.bukkit.permissions.Permission
10+
import org.bukkit.permissions.PermissionAttachment
11+
import org.bukkit.permissions.PermissionAttachmentInfo
12+
import org.bukkit.plugin.Plugin
13+
14+
class DiscordCommandSender(val channel: MessageChannel) : RemoteConsoleCommandSender {
15+
16+
private val sender:ConsoleCommandSender = Bukkit.getServer().consoleSender
17+
18+
init {
19+
20+
}
21+
22+
override fun sendMessage(message: String?) {
23+
channel.sendMessage(message).queue()
24+
}
25+
26+
override fun sendMessage(messages: Array<out String>?) {
27+
if (messages != null)
28+
for (m in messages) channel.sendMessage(m)
29+
}
30+
31+
override fun spigot(): CommandSender.Spigot {
32+
return sender.spigot()
33+
}
34+
35+
override fun addAttachment(plugin: Plugin?): PermissionAttachment {
36+
return sender.addAttachment(plugin)
37+
}
38+
39+
override fun addAttachment(plugin: Plugin?, ticks: Int): PermissionAttachment {
40+
return sender.addAttachment(plugin, ticks)
41+
}
42+
43+
override fun addAttachment(plugin: Plugin?, name: String?, value: Boolean): PermissionAttachment {
44+
return sender.addAttachment(plugin, name, value)
45+
}
46+
47+
override fun addAttachment(plugin: Plugin?, name: String?, value: Boolean, ticks: Int): PermissionAttachment {
48+
return sender.addAttachment(plugin, name, value, ticks)
49+
}
50+
51+
override fun getEffectivePermissions(): MutableSet<PermissionAttachmentInfo> {
52+
return sender.effectivePermissions
53+
}
54+
55+
override fun getName(): String {
56+
return sender.name
57+
}
58+
59+
override fun getServer(): Server {
60+
return sender.server
61+
}
62+
63+
override fun hasPermission(name: String?): Boolean {
64+
return sender.hasPermission(name)
65+
}
66+
67+
override fun hasPermission(perm: Permission?): Boolean {
68+
return sender.hasPermission(perm)
69+
}
70+
71+
override fun isOp(): Boolean {
72+
return sender.isOp
73+
}
74+
75+
override fun isPermissionSet(name: String?): Boolean {
76+
return sender.isPermissionSet(name)
77+
}
78+
79+
override fun isPermissionSet(perm: Permission?): Boolean {
80+
return sender.isPermissionSet(perm)
81+
}
82+
83+
override fun recalculatePermissions() {
84+
return sender.recalculatePermissions()
85+
}
86+
87+
override fun removeAttachment(attachment: PermissionAttachment?) {
88+
return sender.removeAttachment(attachment)
89+
}
90+
91+
override fun setOp(value: Boolean) {
92+
return sender.setOp(value)
93+
}
94+
95+
96+
}

Diff for: src/main/kotlin/gg/obsidian/discordbridge/commands/annotations/BotCommand.kt

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

0 commit comments

Comments
 (0)