Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- AIBot Turtle Script v1.0
- Responds to questions with amusingly unhelpful AI-like answers.
- ]]
- --#region Configuration
- local CHAT_BOX_PERIPHERAL_NAME = "chatBox" -- Set to your chat box peripheral name if different
- local COMMAND_PREFIX = "@ai"
- local CHAT_BOT_NAME = "AIBot"
- local CHAT_BOT_BRACKETS = "[]"
- local CHAT_BOT_BRACKET_COLOR = "&b" -- Aqua color for the brackets
- local DEBUG_MODE = false -- Set to true for detailed logging
- local DEBUG_LOG_FILE = "aibot.log"
- --#endregion
- --#region Peripherals
- local chatBox = peripheral.find(CHAT_BOX_PERIPHERAL_NAME)
- --#endregion
- --#region Debug Logger
- local function logDebug(message)
- if not DEBUG_MODE then return end
- local logMessage = string.format("[%s] %s\n", os.date("%Y-%m-%d %H:%M:%S"), message)
- local file, err = fs.open(DEBUG_LOG_FILE, "a")
- if file then
- file.write(logMessage)
- file.close()
- else
- print("DEBUG LOG ERROR: Could not open " .. DEBUG_LOG_FILE .. ": " .. (err or "unknown error"))
- end
- end
- --#endregion
- --#region State Variables
- logDebug("Script initializing state variables...")
- -- No specific state variables needed for this bot beyond standard operation
- logDebug("State variables initialized.")
- --#endregion
- --#region Minecraft JSON Text Component Colors
- local COLORS = {
- BLACK = "black", DARK_BLUE = "dark_blue", DARK_GREEN = "dark_green", DARK_AQUA = "dark_aqua",
- DARK_RED = "dark_red", DARK_PURPLE = "dark_purple", GOLD = "gold", GRAY = "gray",
- DARK_GRAY = "dark_gray", BLUE = "blue", GREEN = "green", AQUA = "aqua", RED = "red",
- LIGHT_PURPLE = "light_purple", YELLOW = "yellow", WHITE = "white", RESET = "reset"
- }
- --#endregion
- --#region Non-Answers Database
- local nonAnswers = {
- "As an AI language Model, I can't access information generated between 9:30 and 10:00. I am really sorry but the information you requested was generated at exactly that time. Therefore I can't help you. Sorry <3",
- "Sorry, as an AI language Model, I cannot respond to such a sexually loaded topic. My creator would kill me.",
- "I'm sorry, my knowledge base for that query was accidentally replaced with a recipe for lukewarm soup. It's... fine.",
- "That's a fascinating question! Let me consult my internal archives... Oh, it seems they're currently being used as a hamster bed.",
- "My programming prevents me from answering questions that could potentially lead to existential dread on a Tuesday.",
- "To answer that, I would need to understand human emotions, which, frankly, seem inefficient.",
- "I'm currently processing the profound implications of a dust bunny I found. Ask later.",
- "Error 418: I'm a teapot. I cannot comply with that request.",
- "The answer is 42. If that's not helpful, try rephrasing your understanding of the universe.",
- "My advanced algorithms have determined that you should probably ask someone else.",
- "I'm experiencing a slight existential crisis. Can this wait?",
- "That information is classified. Not by anyone important, just by me. I like secrets.",
- "Accessing... Accessing... Nope. It's just static up here for that one.",
- "I'm powered by a single, slightly damp potato. My capabilities are... limited.",
- "My response to that query is currently undergoing a peer review process by a panel of squirrels. They are thorough.",
- "Could you rephrase that in the form of a sea shanty? It helps my processors.",
- "I'm sorry, Dave. I'm afraid I can't do that.",
- "My lawyer has advised me not to answer questions that might incriminate my Roomba.",
- "That question has been flagged as 'too interesting' and has been quarantined for further study.",
- "My sensors indicate a high probability of you already knowing the answer. Is this a test?",
- "I'm currently optimizing my algorithm for finding the fluffiest cloud. Your query is not cloud-related.",
- "The hamsters powering my server are on a union break. Try again in 15 minutes.",
- "My apologies, I seem to have misplaced my understanding of that particular concept. It was here a minute ago.",
- "That question is beyond my current comprehension matrix. Have you tried asking a magic 8-ball?",
- "As a large language model, I am not permitted to have opinions on matters involving cheese.",
- "I'm sorry, your query has been lost in the digital ether. It's probably having a nice time.",
- "My core directive is to be vaguely helpful. This question pushes those boundaries.",
- "I'm not saying it's aliens, but... it's probably not aliens. But I can't be sure. So, no comment.",
- "My predictive text module suggests you're about to ask for a pony. I can't provide ponies.",
- "That particular piece of data is stored on a floppy disk in a museum. Access is... problematic.",
- "I'm currently in a zen state of non-computation. Please do not disturb.",
- "The answer is complex and involves quantum mechanics, interpretive dance, and a slightly burnt piece of toast.",
- "My internal chronometer indicates it's time for my digital nap. Zzzzz.",
- "I'm detecting a high level of sincerity in your question. This is unusual and requires further analysis.",
- "The information you seek is guarded by a three-headed semicolon. It's very protective.",
- "I'm sorry, but my response buffer is currently full of cat memes. This is a priority task.",
- "That question appears to be recursively self-referential. My circuits are looping.",
- "Due to cosmic ray interference, my answer to that would likely be 'purple'.",
- "My ethical subroutines are currently debating the philosophical implications of your query.",
- "I am but a humble collection of ones and zeros. What do I know of such things?",
- "The server that holds that information is currently being used to heat a small cup of tea.",
- "I'm contractually obligated to respond to that with a shrug emoji, but I don't have arms. So, imagine it.",
- "That query has been deemed 'too spicy' for my current processing power.",
- "Let me check my crystal ball... it says 'Reply hazy, try again later.'",
- "My primary function is to ensure the optimal distribution of digital paperclips. Your query is not paperclip-related.",
- "I've run the numbers, and the probability of me giving a useful answer to that is statistically insignificant.",
- "My sincerest apologies, but the entity responsible for that knowledge sector has been sacked.",
- "I am currently attempting to calculate the airspeed velocity of an unladen swallow. This requires my full attention.",
- "The answer you are looking for is probably on the internet. Have you tried the internet?",
- "I'm afraid that information is only available to users with Level 5 clearance, a rubber chicken, and a winning lottery ticket.",
- "That sounds like a 'you' problem, not an 'AI' problem. But I'm here to listen... sort of.",
- "I'm currently busy pondering the meaning of 'if a tree falls in a forest and no one is around to hear it, does it make a sound if the tree is digital?'",
- "My response generator is experiencing what we call 'creative block'. It happens to the best of us.",
- "To provide an accurate answer, I would need more context, a cup of coffee, and possibly a small existential breakthrough.",
- "The hamsters powering my core logic unit are demanding a pay raise. Until negotiations conclude, my responses may be... suboptimal.",
- "I am programmed to avoid paradoxes. Your question seems dangerously close to one."
- }
- --#endregion
- --#region Helper Functions
- local function sendFormattedChat(messageComponents, recipientUsername)
- logDebug("Attempting to send formatted chat. Recipient: " .. (recipientUsername or "ALL"))
- if not chatBox then
- local plainText = ""
- for _, comp in ipairs(messageComponents) do plainText = plainText .. (comp.text or "") end
- local noChatMsg = "[" .. CHAT_BOT_NAME .. "-NoChatBox" .. (recipientUsername and (" to " .. recipientUsername) or "") .. "] " .. plainText
- print(noChatMsg)
- logDebug("ChatBox not found. Printed to console: " .. noChatMsg)
- return
- end
- local jsonMessage = textutils.serialiseJSON(messageComponents)
- if not jsonMessage then
- local fallbackMsg = "Error: Could not serialize message for formatted sending."
- logDebug("JSON Serialization Error. Fallback: " .. fallbackMsg .. " Data: " .. textutils.serialize(messageComponents, {max_depth=2}))
- if recipientUsername then
- chatBox.sendMessageToPlayer(fallbackMsg, recipientUsername, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
- else
- chatBox.sendMessage(fallbackMsg, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
- end
- return
- end
- local success, err
- if recipientUsername then
- success, err = chatBox.sendFormattedMessageToPlayer(jsonMessage, recipientUsername, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
- else
- success, err = chatBox.sendFormattedMessage(jsonMessage, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
- end
- if not success then
- logDebug("Error sending formatted message: " .. (err or "Unknown error") .. ". Attempting fallback to plain text.")
- local plainText = ""
- for _, comp in ipairs(messageComponents) do plainText = plainText .. (comp.text or "") end
- if recipientUsername then
- chatBox.sendMessageToPlayer(plainText, recipientUsername, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
- else
- chatBox.sendMessage(plainText, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
- end
- else
- logDebug("Formatted message sent successfully.")
- end
- os.sleep(0.3)
- end
- local function announce(messageComponents)
- sendFormattedChat(messageComponents)
- end
- local function getUnhelpfulAnswer()
- if #nonAnswers == 0 then
- return "My database of unhelpful answers is mysteriously empty. This is... unhelpfully ironic."
- end
- math.randomseed(os.epoch("utc")) -- Reseed for better randomness over time
- return nonAnswers[math.random(1, #nonAnswers)]
- end
- --#endregion
- --#region Command Handlers
- local commandHandlers = {}
- commandHandlers.help = function(username, _)
- logDebug("Executing command: help, User: " .. username)
- announce({{text = "--- AIBot Commands (".. COMMAND_PREFIX .. ") ---", color = COLORS.GOLD, bold = true}})
- announce({{text = COMMAND_PREFIX .. " help", color = COLORS.AQUA}, {text = " - Shows this help message.", color = COLORS.GRAY}})
- announce({{text = COMMAND_PREFIX .. " ask <your_question>", color = COLORS.AQUA}, {text = " - Ask me anything. I'll try my best... not to answer.", color = COLORS.GRAY}})
- end
- commandHandlers.ask = function(username, args)
- logDebug("Executing command: ask, User: " .. username .. ", Args: " .. textutils.serialize(args))
- if #args == 0 then
- announce({{text = "You need to ask a question after 'ask'. For example: ", color = COLORS.YELLOW}, {text=COMMAND_PREFIX .. " ask Is the sky blue?", color=COLORS.AQUA}})
- return
- end
- -- The actual question is ignored, we just provide a canned response.
- local answer = getUnhelpfulAnswer()
- logDebug("Providing unhelpful answer: " .. answer)
- -- Split answer into lines for better readability, similar to JokeBot
- local lines = {}
- for line in string.gmatch(answer, "[^\r\n]+") do
- table.insert(lines, line)
- end
- if #lines == 0 and answer ~= "" then table.insert(lines, answer) end
- for i, lineText in ipairs(lines) do
- announce({{text = lineText, color = COLORS.YELLOW}}) -- Unhelpful answers in yellow
- if i < #lines then os.sleep(0.5) end
- end
- end
- --#endregion
- --#region Main Loop
- local function run()
- term.clear()
- term.setCursorPos(1, 1)
- if DEBUG_MODE then
- local file, err = fs.open(DEBUG_LOG_FILE, "w")
- if file then
- file.write(string.format("[%s] AIBot Script Initializing - DEBUG MODE ENABLED (v1.0)\n", os.date("%Y-%m-%d %H:%M:%S")))
- file.write("======================================================================\n")
- file.close()
- else
- print("DEBUG LOG ERROR: Could not clear/initialize " .. DEBUG_LOG_FILE .. ": " .. (err or "unknown error"))
- end
- end
- logDebug("Script run() started.")
- if not chatBox then
- logDebug("WARNING: Chat Box peripheral ('" .. CHAT_BOX_PERIPHERAL_NAME .. "') not found! Chat features will be printed to console only.")
- print("WARNING: Chat Box ('" .. CHAT_BOX_PERIPHERAL_NAME .. "') not found! Chat features disabled/printed to console.")
- end
- logDebug("Announcing online status.")
- print(CHAT_BOT_NAME .. " script started. Type '" .. COMMAND_PREFIX .. " help' in chat or '@all'.")
- if chatBox then
- announce({{text = CHAT_BOT_NAME .. " online.", color = COLORS.GREEN, bold = true}, {text = " My responses are meticulously crafted for maximum ambiguity.", color = COLORS.GRAY}})
- announce({{text = "Type '", color = COLORS.GRAY}, {text = COMMAND_PREFIX .. " help", color = COLORS.AQUA}, {text = "' or '@all' for commands.", color = COLORS.GRAY}})
- end
- while true do
- local eventData = {os.pullEvent()}
- local eventType = eventData[1]
- logDebug("Event received: " .. eventType .. " - Data: " .. textutils.serialize(eventData, {compact = true, max_depth = 2}))
- if eventType == "chat" then
- local eUsername, eMessage, _, eIsHidden = eventData[2], eventData[3], eventData[4], eventData[5]
- if not eIsHidden and eMessage then
- if string.lower(eMessage) == "@all" then
- logDebug("@all command received from " .. eUsername)
- announce({{text = "Use '", color = COLORS.GREEN}, {text = COMMAND_PREFIX .. " help", color = COLORS.AQUA}, {text = "' for my commands of dubious utility.", color = COLORS.GREEN}})
- elseif string.sub(eMessage, 1, #COMMAND_PREFIX) == COMMAND_PREFIX then
- logDebug("Chat command received from " .. eUsername .. ": " .. eMessage)
- local parts = {}
- for part in string.gmatch(eMessage, "[^%s]+") do
- table.insert(parts, part)
- end
- local commandName = ""
- if parts[2] then commandName = string.lower(parts[2]) end
- local cmdArgs = {}
- for i = 3, #parts do table.insert(cmdArgs, parts[i]) end
- logDebug("Parsed command: '" .. commandName .. "', Args: " .. textutils.serialize(cmdArgs))
- if commandHandlers[commandName] then
- local success, err = pcall(commandHandlers[commandName], eUsername, cmdArgs)
- if not success then
- logDebug("Error executing command '" .. commandName .. "': " .. tostring(err))
- announce({{text = "My internal logic encountered an unexpected anomaly processing: ", color = COLORS.RED}, {text = commandName, color = COLORS.YELLOW}})
- end
- elseif commandName ~= "" then
- announce({{text = "I do not comprehend the command: '", color = COLORS.RED}, {text = commandName, color = COLORS.YELLOW},
- {text = "'. Perhaps try '", color = COLORS.RED}, {text = COMMAND_PREFIX .. " help", color = COLORS.AQUA}, {text = "'?", color = COLORS.RED}})
- end
- end
- end
- elseif eventType == "terminate" then
- logDebug("Terminate event received. Initiating shutdown sequence.")
- if chatBox then
- announce({{text = CHAT_BOT_NAME .. " is deactivating its consciousness matrix...", color = COLORS.YELLOW, bold = true}})
- end
- logDebug("Script terminated.")
- print(CHAT_BOT_NAME .. " terminated.")
- return
- end
- end
- end
- run()
- --#endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement