Skip to content

Commit c939c4a

Browse files
committed
Now commands in discord console can be ignored if command without prefix
1 parent 4234970 commit c939c4a

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

buildnumber.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#Generated
2-
#Fri Feb 21 18:12:39 CET 2025
3-
0.3=47
2+
#Fri Feb 21 18:35:06 CET 2025
3+
0.3=51

src/main/kotlin/top/azimkin/multiMessageBridge/configuration/DiscordReceiverConfig.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ data class BotConfiguration(
1717
var channels: Map<String, ChannelConfiguration> = mapOf(
1818
"messages" to ChannelConfiguration("main_text"),
1919
"console" to ChannelConfiguration("console"),
20-
)
20+
),
21+
@Comment("Should plugin ignore messages in console without prefix in start")
22+
var commandsShouldStartsWithPrefix: Boolean = true,
23+
var commandPrefix: String = "!/"
2124
) : OkaeriConfig()
2225

2326
data class ChannelConfiguration(

src/main/kotlin/top/azimkin/multiMessageBridge/platforms/discord/DiscordReceiver.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class DiscordReceiver(val em: MessagingEventManager) :
117117
}
118118
}
119119

120-
@JvmOverloads
121120
fun sendSimpleEmbed(author: String, message: String, color: Color = Color.BLACK, channel: String = "main_text") =
122121
addAction {
123122
val channel = findChannel(channel)?.id ?: return@addAction
@@ -131,7 +130,6 @@ class DiscordReceiver(val em: MessagingEventManager) :
131130
).queue()
132131
}
133132

134-
@JvmOverloads
135133
fun sendMessageToChannel(message: String, channel: String = "main_text") = addAction {
136134
val channel = findChannel(channel)?.id ?: return@addAction
137135
val textChannel = jda.get().getTextChannelById(channel) ?: return@addAction
@@ -165,7 +163,8 @@ class DiscordReceiver(val em: MessagingEventManager) :
165163

166164
"console" -> {
167165
console.dumpStack()
168-
dispatch(ConsoleMessageContext(event.message.contentRaw))
166+
if (config.bot.commandsShouldStartsWithPrefix && !event.message.contentRaw.startsWith(config.bot.commandPrefix)) return
167+
dispatch(ConsoleMessageContext(event.message.contentRaw.substring(config.bot.commandPrefix.length)))
169168
}
170169
}
171170
}

src/main/kotlin/top/azimkin/multiMessageBridge/platforms/discord/jdaproviders/CommonJdaProvider.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ class CommonJdaProvider(token: String, receiver: DiscordReceiver) : JdaProvider,
1818
.build()
1919
.apply {
2020
awaitReady()
21-
while (initializeHandlers.isNotEmpty()) {
22-
initializeHandlers.removeFirst()(this)
23-
}
21+
runQueue()
2422
}
2523

2624
override fun get(): JDA = jda
@@ -29,6 +27,13 @@ class CommonJdaProvider(token: String, receiver: DiscordReceiver) : JdaProvider,
2927

3028
override fun addInitializeListener(listener: (JDA) -> Unit) {
3129
initializeHandlers.add(listener)
30+
if (isInitialized()) runQueue()
31+
}
32+
33+
private fun runQueue() {
34+
while (initializeHandlers.isNotEmpty()) {
35+
initializeHandlers.removeFirst()(jda)
36+
}
3237
}
3338

3439
override fun shutdown() {

0 commit comments

Comments
 (0)