Skip to content

Commit c55aab5

Browse files
committed
Fix AutoReply self spam and cleanup
1 parent 14403b8 commit c55aab5

File tree

6 files changed

+48
-82
lines changed

6 files changed

+48
-82
lines changed

src/main/kotlin/ChatPlusAutoReply.kt

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
1-
import com.lambda.client.command.CommandManager
1+
import com.lambda.client.event.events.PacketEvent
22
import com.lambda.client.module.Category
33
import com.lambda.client.plugin.api.PluginModule
4-
5-
import com.lambda.client.event.events.PacketEvent
6-
import com.lambda.client.manager.managers.FriendManager
7-
import com.lambda.client.manager.managers.MessageManager
8-
import com.lambda.client.manager.managers.MessageManager.newMessageModifier
9-
import com.lambda.client.mixin.extension.textComponent
104
import com.lambda.client.util.TickTimer
115
import com.lambda.client.util.TimeUnit
126
import com.lambda.client.util.text.MessageDetection
137
import com.lambda.client.util.text.MessageSendHelper
148
import com.lambda.client.util.text.MessageSendHelper.sendServerMessage
15-
import com.lambda.client.util.text.format
16-
import com.lambda.client.util.text.formatValue
17-
import com.lambda.client.util.threads.defaultScope
189
import com.lambda.client.util.threads.safeListener
19-
import com.lambda.commons.utils.SystemUtils
2010
import com.lambda.event.listener.listener
21-
import kotlinx.coroutines.Dispatchers
22-
import kotlinx.coroutines.launch
2311
import net.minecraft.network.play.server.SPacketChat
24-
import net.minecraft.util.text.TextFormatting
2512
import net.minecraftforge.fml.common.gameevent.TickEvent
2613

27-
internal object ChatPlusAutoReply: PluginModule(
14+
internal object ChatPlusAutoReply : PluginModule(
2815
name = "AutoReply",
2916
description = "Automatically reply to direct messages",
3017
category = Category.CHAT,
@@ -34,14 +21,19 @@ internal object ChatPlusAutoReply: PluginModule(
3421
private val customText by setting("Custom Text", "unchanged", { customMessage })
3522

3623
private val timer = TickTimer(TimeUnit.SECONDS)
24+
private const val defaultMessage = "I just automatically replied, thanks to Lambda's AutoReply module!"
3725

3826
init {
3927
listener<PacketEvent.Receive> {
40-
if (it.packet !is SPacketChat || MessageDetection.Direct.RECEIVE detect (it.packet as SPacketChat).chatComponent.unformattedText) return@listener
41-
if (customMessage) {
42-
sendServerMessage("/r $customText")
43-
} else {
44-
sendServerMessage("/r I just automatically replied, thanks to Lambda's AutoReply module!")
28+
if (it.packet is SPacketChat) {
29+
val message = (it.packet as SPacketChat).chatComponent.unformattedText
30+
if (MessageDetection.Direct.RECEIVE detect message) {
31+
if (customMessage) {
32+
if (!message.contains(customText)) sendServerMessage("/r $customText")
33+
} else {
34+
if (!message.contains(defaultMessage)) sendServerMessage("/r $defaultMessage")
35+
}
36+
}
4537
}
4638
}
4739

src/main/kotlin/ChatPlusDiscordNotifs.kt

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,26 @@ import com.google.gson.JsonObject
22
import com.lambda.client.LambdaMod
33
import com.lambda.client.command.CommandManager
44
import com.lambda.client.event.events.ConnectionEvent
5-
import com.lambda.client.module.Category
6-
import com.lambda.client.plugin.api.PluginModule
7-
85
import com.lambda.client.event.events.PacketEvent
9-
import com.lambda.client.manager.managers.FriendManager
10-
import com.lambda.client.manager.managers.MessageManager
11-
import com.lambda.client.manager.managers.MessageManager.newMessageModifier
12-
import com.lambda.client.mixin.extension.textComponent
6+
import com.lambda.client.module.Category
137
import com.lambda.client.module.modules.chat.ChatTimestamp
8+
import com.lambda.client.plugin.api.PluginModule
149
import com.lambda.client.util.TickTimer
1510
import com.lambda.client.util.TimeUnit
1611
import com.lambda.client.util.text.MessageDetection
1712
import com.lambda.client.util.text.MessageSendHelper
18-
import com.lambda.client.util.text.MessageSendHelper.sendServerMessage
19-
import com.lambda.client.util.text.format
2013
import com.lambda.client.util.text.formatValue
2114
import com.lambda.client.util.threads.defaultScope
2215
import com.lambda.client.util.threads.safeListener
2316
import com.lambda.commons.utils.ConnectionUtils
24-
import com.lambda.commons.utils.SystemUtils
2517
import com.lambda.event.listener.listener
2618
import kotlinx.coroutines.Dispatchers
2719
import kotlinx.coroutines.launch
2820
import net.minecraft.network.play.server.SPacketChat
29-
import net.minecraft.util.text.TextFormatting
3021
import net.minecraftforge.fml.common.gameevent.TickEvent
3122
import org.apache.commons.io.IOUtils
3223

33-
internal object ChatPlusDiscordNotifs: PluginModule(
24+
internal object ChatPlusDiscordNotifs : PluginModule(
3425
name = "DiscordNotifs",
3526
category = Category.CHAT,
3627
description = "Sends your chat to a set Discord channel",
@@ -78,14 +69,18 @@ internal object ChatPlusDiscordNotifs: PluginModule(
7869
/* Always on status code */
7970
safeListener<TickEvent.ClientTickEvent> {
8071
if (url.value == "unchanged") {
81-
MessageSendHelper.sendErrorMessage(chatName + " You must first set a webhook url with the " +
82-
formatValue("${CommandManager.prefix}discordnotifs") +
83-
" command")
72+
MessageSendHelper.sendErrorMessage(
73+
chatName + " You must first set a webhook url with the " +
74+
formatValue("${CommandManager.prefix}discordnotifs") +
75+
" command"
76+
)
8477
disable()
8578
} else if (pingID.value == "unchanged" && importantPings) {
86-
MessageSendHelper.sendErrorMessage(chatName + " For Pings to work, you must set a Discord ID with the " +
87-
formatValue("${CommandManager.prefix}discordnotifs") +
88-
" command")
79+
MessageSendHelper.sendErrorMessage(
80+
chatName + " For Pings to work, you must set a Discord ID with the " +
81+
formatValue("${CommandManager.prefix}discordnotifs") +
82+
" command"
83+
)
8984
disable()
9085
}
9186
}
@@ -115,7 +110,8 @@ internal object ChatPlusDiscordNotifs: PluginModule(
115110
|| message == "LambdaMessageType2"
116111
|| direct && MessageDetection.Direct.ANY detect message
117112
|| restart && MessageDetection.Server.RESTART detect message
118-
|| importantPings && MessageDetection.Server.QUEUE_IMPORTANT detect message) formatPingID()
113+
|| importantPings && MessageDetection.Server.QUEUE_IMPORTANT detect message
114+
) formatPingID()
119115
else ""
120116

121117
private fun formatPingID(): String {

src/main/kotlin/ChatPlusEncryption.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import com.lambda.client.module.Category
2-
import com.lambda.client.plugin.api.PluginModule
3-
41
import com.lambda.client.event.events.PacketEvent
52
import com.lambda.client.manager.managers.MessageManager
63
import com.lambda.client.manager.managers.MessageManager.newMessageModifier
74
import com.lambda.client.mixin.extension.textComponent
5+
import com.lambda.client.module.Category
6+
import com.lambda.client.plugin.api.PluginModule
87
import com.lambda.client.util.text.MessageDetection
98
import com.lambda.client.util.text.MessageSendHelper
109
import com.lambda.client.util.text.format
@@ -17,7 +16,7 @@ import kotlinx.coroutines.launch
1716
import net.minecraft.network.play.server.SPacketChat
1817
import net.minecraft.util.text.TextFormatting
1918

20-
internal object ChatPlusEncryption: PluginModule(
19+
internal object ChatPlusEncryption : PluginModule(
2120
name = "ChatEncryption",
2221
description = "Encrypts and decrypts chat messages",
2322
category = Category.CHAT,

src/main/kotlin/ChatPlusPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import com.lambda.client.plugin.api.Plugin
22

3-
internal object ChatPlusPlugin: Plugin() {
3+
internal object ChatPlusPlugin : Plugin() {
44

55
override fun onLoad() {
66
modules.add(ChatPlusEncryption)

src/main/kotlin/ChatPlusRemoteCommand.kt

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
11
import com.lambda.client.command.CommandManager
2-
import com.lambda.client.module.Category
3-
import com.lambda.client.plugin.api.PluginModule
4-
52
import com.lambda.client.event.events.PacketEvent
63
import com.lambda.client.manager.managers.FriendManager
7-
import com.lambda.client.manager.managers.MessageManager
8-
import com.lambda.client.manager.managers.MessageManager.newMessageModifier
9-
import com.lambda.client.mixin.extension.textComponent
4+
import com.lambda.client.module.Category
5+
import com.lambda.client.plugin.api.PluginModule
106
import com.lambda.client.util.text.MessageDetection
117
import com.lambda.client.util.text.MessageSendHelper
128
import com.lambda.client.util.text.MessageSendHelper.sendServerMessage
13-
import com.lambda.client.util.text.format
149
import com.lambda.client.util.text.formatValue
15-
import com.lambda.client.util.threads.defaultScope
16-
import com.lambda.client.util.threads.safeListener
17-
import com.lambda.commons.utils.SystemUtils
1810
import com.lambda.event.listener.listener
19-
import kotlinx.coroutines.Dispatchers
20-
import kotlinx.coroutines.launch
2111
import net.minecraft.network.play.server.SPacketChat
22-
import net.minecraft.util.text.TextFormatting
2312

24-
internal object ChatPlusRemoteCommand: PluginModule(
13+
internal object ChatPlusRemoteCommand : PluginModule(
2514
name = "RemoteCommand",
2615
description = "Allow trusted players to send commands",
2716
category = Category.CHAT,
2817
pluginMain = ChatPlusPlugin
2918
) {
3019
private val allow = setting("Allow", Allow.FRIENDS)
3120
private val repeatAll by setting("Repeat All", false)
32-
private val custom by setting("Custom", "unchanged", { allow.value == Allow.CUSTOM || allow.value == Allow.FRIENDS_AND_CUSTOM })
21+
private val custom by setting(
22+
"Custom",
23+
"unchanged",
24+
{ allow.value == Allow.CUSTOM || allow.value == Allow.FRIENDS_AND_CUSTOM })
3325

3426
init {
3527
allow.listeners.add {
3628
mc.player?.let {
3729
if ((allow.value == Allow.CUSTOM || allow.value == Allow.FRIENDS_AND_CUSTOM) && custom == "unchanged") {
38-
MessageSendHelper.sendChatMessage("$chatName Use the ${formatValue("${CommandManager.prefix}set Custom")}"
39-
+ " command to change the custom users list. For example, "
40-
+ formatValue("${CommandManager.prefix}set Custom dominika,Dewy,086"))
30+
MessageSendHelper.sendChatMessage(
31+
"$chatName Use the ${formatValue("${CommandManager.prefix}set Custom")}"
32+
+ " command to change the custom users list. For example, "
33+
+ formatValue("${CommandManager.prefix}set Custom dominika,Dewy,086")
34+
)
4135
}
4236
}
4337
}
@@ -61,6 +55,7 @@ internal object ChatPlusRemoteCommand: PluginModule(
6155
}
6256
}
6357
}
58+
6459
private fun isValidUser(username: String): Boolean {
6560
return when (allow.value) {
6661
Allow.ANYBODY -> true
@@ -69,9 +64,11 @@ internal object ChatPlusRemoteCommand: PluginModule(
6964
Allow.FRIENDS_AND_CUSTOM -> FriendManager.isFriend(username) || isCustomUser(username)
7065
}
7166
}
67+
7268
private fun isCustomUser(username: String): Boolean {
7369
return custom.split(",").any { it.equals(username, true) }
7470
}
71+
7572
private enum class Allow {
7673
ANYBODY, FRIENDS, CUSTOM, FRIENDS_AND_CUSTOM
7774
}

src/main/kotlin/ChatPlusSpecialChat.kt

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
1-
import com.lambda.client.command.CommandManager
1+
import com.lambda.client.manager.managers.MessageManager.newMessageModifier
22
import com.lambda.client.module.Category
33
import com.lambda.client.plugin.api.PluginModule
4-
5-
import com.lambda.client.event.events.PacketEvent
6-
import com.lambda.client.manager.managers.FriendManager
7-
import com.lambda.client.manager.managers.MessageManager
8-
import com.lambda.client.manager.managers.MessageManager.newMessageModifier
9-
import com.lambda.client.mixin.extension.textComponent
10-
import com.lambda.client.util.text.MessageDetection
114
import com.lambda.client.util.text.MessageSendHelper
12-
import com.lambda.client.util.text.MessageSendHelper.sendServerMessage
13-
import com.lambda.client.util.text.format
14-
import com.lambda.client.util.text.formatValue
15-
import com.lambda.client.util.threads.defaultScope
16-
import com.lambda.client.util.threads.safeListener
17-
import com.lambda.commons.utils.SystemUtils
18-
import com.lambda.event.listener.listener
19-
import kotlinx.coroutines.Dispatchers
20-
import kotlinx.coroutines.launch
21-
import net.minecraft.network.play.server.SPacketChat
22-
import net.minecraft.util.text.TextFormatting
235

24-
internal object ChatPlusSpecialChat: PluginModule(
6+
internal object ChatPlusSpecialChat : PluginModule(
257
name = "SpecialChat",
268
description = "Add color and linebreak support to upstream chat packets using formatting",
279
category = Category.CHAT,

0 commit comments

Comments
 (0)