AutoChatGame module

AutoChatGame: Minecraft 26.3 cheat module, full source for every implementation (1 client: LiquidBounce (Kotlin)).

1 implementationMISC

Clients with this module

Full module source: 1 implementation

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

LiquidBounce (Kotlin)MISCsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleAutoChatGame.ktKotlin · 190 lines · 7.5 KB

Uses OpenAI to play chat games.

SettingsBaseUrlOpenAiKeyModelReactionTimeCooldownBufferTimeTriggerSentenceIncludeTriggerServerNameAnswerTemplatePrompt
ModuleAutoChatGame.ktKotlin · Minecraft 26.2 · 190 lines · 7.5 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
package net.ccbluex.liquidbounce.features.module.modules.misc
20
21
import kotlinx.coroutines.Dispatchers
22
import kotlinx.coroutines.delay
23
import kotlinx.coroutines.withContext
24
import net.ccbluex.liquidbounce.api.thirdparty.OPENAI_BASE_URL
25
import net.ccbluex.liquidbounce.api.thirdparty.OpenAiApi
26
import net.ccbluex.liquidbounce.event.events.ChatReceiveEvent
27
import net.ccbluex.liquidbounce.event.sequenceHandler
28
import net.ccbluex.liquidbounce.event.tickHandler
29
import net.ccbluex.liquidbounce.event.tickUntil
30
import net.ccbluex.liquidbounce.features.module.ClientModule
31
import net.ccbluex.liquidbounce.features.module.ModuleCategories
32
import net.ccbluex.liquidbounce.utils.client.Chronometer
33
import net.ccbluex.liquidbounce.utils.client.chat
34
import kotlin.time.Duration.Companion.milliseconds
35
36
/**
37
 * Automatically solves chat game riddles.
38
 */
39
object ModuleAutoChatGame : ClientModule("AutoChatGame", ModuleCategories.MISC) {
40
41
    init {
42
        doNotIncludeAlways()
43
    }
44
45
    private val baseUrl by text("BaseUrl", OPENAI_BASE_URL)
46
    private val openAiKey by text("OpenAiKey", "")
47
    private val model by text("Model", "gpt-4o-mini") // GPT 4O Mini should be enough for this
48
    private val delayResponse by intRange("ReactionTime", 1000..5000, 0..10000,
49
        "ms")
50
    private val cooldownMinutes by int("Cooldown", 2, 0..60, "minutes")
51
    private val bufferTime by int("BufferTime", 200, 0..500, "ms")
52
    private val triggerSentence by text("TriggerSentence", "Chat Game")
53
    private val includeTrigger by boolean("IncludeTrigger", true)
54
    private val serverName by text("ServerName", "Minecraft")
55
    private val answerTemplate by text("AnswerTemplate", "%s")
56
57
    /**
58
     * Default prompt for the AI.
59
     * This is the text that the AI will use to generate answers.
60
     *
61
     * It is recommended to not change this, as it is already optimized for the chat game.
62
     * If you want to change it, make sure to keep the same structure.
63
     *
64
     * Do not create any line breaks, as it might break the JSON format.
65
     */
66
    private val defaultPrompt = """
67
        You participate in a chat game in which you have to answer questions or do tasks.
68
        Your goal is to answer them as short and precise as possible and win the game.
69
        The questions might be based on the game Minecraft or the minecraft server you are playing on.
70
        The server name is {SERVER_NAME}.
71
        On true or false questions, respond without any dots, in lower-case with 'true' or 'false'.
72
        On math questions, respond with the result.
73
        On first to type tasks, respond with the word.
74
        On unscramble tasks, the word is scrambled and might be from the game Minecraft (ex. Spawners, Iron Golem),
75
        respond with the unscrambled word.
76
        On other questions, respond with the answer.
77
        DO NOT SAY ANYTHING ELSE THAN THE ANSWER! If you do, you will be disqualified.
78
        A few hints: [
79
        Amethyst geodes spawn at Y level and below in 1.18 -> 30,
80
        Minecraft's moon has the same amount of lunar phases as the moon in real life -> true
81
        ]
82
        """.trimIndent().replace('\n', ' ')
83
    private val prompt by text("Prompt", defaultPrompt)
84
85
    override fun onEnabled() {
86
        if (openAiKey.isBlank()) {
87
            chat("§cPlease enter your OpenAI key in the module settings.")
88
            enabled = false
89
            return
90
        }
91
    }
92
93
    private val chatBuffer = mutableListOf<String>()
94
    private val triggerWordChronometer = Chronometer()
95
    private val cooldownChronometer = Chronometer()
96
97
    @Suppress("unused")
98
    val chatHandler = sequenceHandler<ChatReceiveEvent> { event ->
99
        val message = event.message
100
101
        // Only handle game messages. It is unlikely that any server will use a player for the chat game.
102
        if (event.type != ChatReceiveEvent.ChatType.GAME_MESSAGE) {
103
            return@sequenceHandler
104
        }
105
106
        // Auto GG
107
        if (message.contains("Show some love by typing")) {
108
            delay(delayResponse.random().milliseconds)
109
            network.sendChat("gg")
110
            return@sequenceHandler
111
        }
112
113
        // Trigger word checking. Cooldown prevents the bot from answering the question twice
114
        // if the result has the same tag.
115
        if (cooldownChronometer.hasElapsed(cooldownMinutes * 60000L)) {
116
            // Does the message contain the magic trigger word?
117
            if (message.contains(triggerSentence)) {
118
                triggerWordChronometer.reset()
119
120
                chatBuffer.clear()
121
                if (!includeTrigger) {
122
                    // Do not include the trigger word in the buffer.
123
                    return@sequenceHandler
124
                }
125
            }
126
127
            // If the trigger word has been said, add the message to the buffer.
128
            if (!triggerWordChronometer.hasElapsed(bufferTime.toLong())) {
129
                chatBuffer.add(message)
130
            }
131
        } else {
132
            chatBuffer.clear()
133
        }
134
    }
135
136
    @Suppress("unused")
137
    val tickHandler = tickHandler {
138
        tickUntil {
139
            // Has the trigger word been said and has the buffer time elapsed?
140
            triggerWordChronometer.hasElapsed(bufferTime.toLong())
141
                // Is the buffer empty? - If it is we already answered the question.
142
                && chatBuffer.isNotEmpty()
143
        }
144
145
        // Handle questions
146
        val question = chatBuffer
147
            .joinToString(" ")
148
            // Remove duplicated spaces
149
            .replace(Regex("\\s+"), " ")
150
            // Remove leading and trailing whitespace
151
            .trim()
152
153
        chatBuffer.clear()
154
        cooldownChronometer.reset()
155
156
        chat("§aUnderstood question: $question")
157
158
        val startAsk = System.currentTimeMillis()
159
160
        val answer = withContext(Dispatchers.IO) {
161
            runCatching {
162
                // Create new AI instance with OpenAI key
163
                val ai = OpenAiApi(baseUrl, openAiKey, model, prompt.replace("{SERVER_NAME}", serverName))
164
165
                ai.requestNewAnswer(question).trimEnd {
166
                    // Remove dot on the end of answer
167
                    it == '.'
168
                }
169
            }.onFailure {
170
                logger.error("GPT AutoChatGame failed", it)
171
                chat("§cFailed to answer question: ${it.message}")
172
            }.getOrNull()
173
        } ?: return@tickHandler
174
175
        chat("§aAnswer: $answer, took ${System.currentTimeMillis() - startAsk}ms.")
176
177
        val delay = delayResponse.random()
178
        chat("§aAnswering question: $answer, waiting for ${delay}ms.")
179
        delay(delay.milliseconds)
180
181
        // Send answer
182
        val formattedAnswer = answerTemplate.format(answer)
183
        if (formattedAnswer.startsWith('/')) {
184
            network.sendCommand(formattedAnswer.substring(1))
185
        } else {
186
            network.sendChat(formattedAnswer)
187
        }
188
    }
189
}
190