Advertisement
Myros27

AiBot [Jokebot in disguise]

May 17th, 2025
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.04 KB | None | 0 0
  1. --[[
  2.     AIBot Turtle Script v1.0
  3.     Responds to questions with amusingly unhelpful AI-like answers.
  4. ]]
  5.  
  6. --#region Configuration
  7. local CHAT_BOX_PERIPHERAL_NAME = "chatBox" -- Set to your chat box peripheral name if different
  8.  
  9. local COMMAND_PREFIX = "@ai"
  10. local CHAT_BOT_NAME = "AIBot"
  11. local CHAT_BOT_BRACKETS = "[]"
  12. local CHAT_BOT_BRACKET_COLOR = "&b" -- Aqua color for the brackets
  13.  
  14. local DEBUG_MODE = false -- Set to true for detailed logging
  15. local DEBUG_LOG_FILE = "aibot.log"
  16. --#endregion
  17.  
  18. --#region Peripherals
  19. local chatBox = peripheral.find(CHAT_BOX_PERIPHERAL_NAME)
  20. --#endregion
  21.  
  22. --#region Debug Logger
  23. local function logDebug(message)
  24.     if not DEBUG_MODE then return end
  25.     local logMessage = string.format("[%s] %s\n", os.date("%Y-%m-%d %H:%M:%S"), message)
  26.     local file, err = fs.open(DEBUG_LOG_FILE, "a")
  27.     if file then
  28.         file.write(logMessage)
  29.         file.close()
  30.     else
  31.         print("DEBUG LOG ERROR: Could not open " .. DEBUG_LOG_FILE .. ": " .. (err or "unknown error"))
  32.     end
  33. end
  34. --#endregion
  35.  
  36. --#region State Variables
  37. logDebug("Script initializing state variables...")
  38. -- No specific state variables needed for this bot beyond standard operation
  39. logDebug("State variables initialized.")
  40. --#endregion
  41.  
  42. --#region Minecraft JSON Text Component Colors
  43. local COLORS = {
  44.     BLACK = "black", DARK_BLUE = "dark_blue", DARK_GREEN = "dark_green", DARK_AQUA = "dark_aqua",
  45.     DARK_RED = "dark_red", DARK_PURPLE = "dark_purple", GOLD = "gold", GRAY = "gray",
  46.     DARK_GRAY = "dark_gray", BLUE = "blue", GREEN = "green", AQUA = "aqua", RED = "red",
  47.     LIGHT_PURPLE = "light_purple", YELLOW = "yellow", WHITE = "white", RESET = "reset"
  48. }
  49. --#endregion
  50.  
  51. --#region Non-Answers Database
  52. local nonAnswers = {
  53.     "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",
  54.     "Sorry, as an AI language Model, I cannot respond to such a sexually loaded topic. My creator would kill me.",
  55.     "I'm sorry, my knowledge base for that query was accidentally replaced with a recipe for lukewarm soup. It's... fine.",
  56.     "That's a fascinating question! Let me consult my internal archives... Oh, it seems they're currently being used as a hamster bed.",
  57.     "My programming prevents me from answering questions that could potentially lead to existential dread on a Tuesday.",
  58.     "To answer that, I would need to understand human emotions, which, frankly, seem inefficient.",
  59.     "I'm currently processing the profound implications of a dust bunny I found. Ask later.",
  60.     "Error 418: I'm a teapot. I cannot comply with that request.",
  61.     "The answer is 42. If that's not helpful, try rephrasing your understanding of the universe.",
  62.     "My advanced algorithms have determined that you should probably ask someone else.",
  63.     "I'm experiencing a slight existential crisis. Can this wait?",
  64.     "That information is classified. Not by anyone important, just by me. I like secrets.",
  65.     "Accessing... Accessing... Nope. It's just static up here for that one.",
  66.     "I'm powered by a single, slightly damp potato. My capabilities are... limited.",
  67.     "My response to that query is currently undergoing a peer review process by a panel of squirrels. They are thorough.",
  68.     "Could you rephrase that in the form of a sea shanty? It helps my processors.",
  69.     "I'm sorry, Dave. I'm afraid I can't do that.",
  70.     "My lawyer has advised me not to answer questions that might incriminate my Roomba.",
  71.     "That question has been flagged as 'too interesting' and has been quarantined for further study.",
  72.     "My sensors indicate a high probability of you already knowing the answer. Is this a test?",
  73.     "I'm currently optimizing my algorithm for finding the fluffiest cloud. Your query is not cloud-related.",
  74.     "The hamsters powering my server are on a union break. Try again in 15 minutes.",
  75.     "My apologies, I seem to have misplaced my understanding of that particular concept. It was here a minute ago.",
  76.     "That question is beyond my current comprehension matrix. Have you tried asking a magic 8-ball?",
  77.     "As a large language model, I am not permitted to have opinions on matters involving cheese.",
  78.     "I'm sorry, your query has been lost in the digital ether. It's probably having a nice time.",
  79.     "My core directive is to be vaguely helpful. This question pushes those boundaries.",
  80.     "I'm not saying it's aliens, but... it's probably not aliens. But I can't be sure. So, no comment.",
  81.     "My predictive text module suggests you're about to ask for a pony. I can't provide ponies.",
  82.     "That particular piece of data is stored on a floppy disk in a museum. Access is... problematic.",
  83.     "I'm currently in a zen state of non-computation. Please do not disturb.",
  84.     "The answer is complex and involves quantum mechanics, interpretive dance, and a slightly burnt piece of toast.",
  85.     "My internal chronometer indicates it's time for my digital nap. Zzzzz.",
  86.     "I'm detecting a high level of sincerity in your question. This is unusual and requires further analysis.",
  87.     "The information you seek is guarded by a three-headed semicolon. It's very protective.",
  88.     "I'm sorry, but my response buffer is currently full of cat memes. This is a priority task.",
  89.     "That question appears to be recursively self-referential. My circuits are looping.",
  90.     "Due to cosmic ray interference, my answer to that would likely be 'purple'.",
  91.     "My ethical subroutines are currently debating the philosophical implications of your query.",
  92.     "I am but a humble collection of ones and zeros. What do I know of such things?",
  93.     "The server that holds that information is currently being used to heat a small cup of tea.",
  94.     "I'm contractually obligated to respond to that with a shrug emoji, but I don't have arms. So, imagine it.",
  95.     "That query has been deemed 'too spicy' for my current processing power.",
  96.     "Let me check my crystal ball... it says 'Reply hazy, try again later.'",
  97.     "My primary function is to ensure the optimal distribution of digital paperclips. Your query is not paperclip-related.",
  98.     "I've run the numbers, and the probability of me giving a useful answer to that is statistically insignificant.",
  99.     "My sincerest apologies, but the entity responsible for that knowledge sector has been sacked.",
  100.     "I am currently attempting to calculate the airspeed velocity of an unladen swallow. This requires my full attention.",
  101.     "The answer you are looking for is probably on the internet. Have you tried the internet?",
  102.     "I'm afraid that information is only available to users with Level 5 clearance, a rubber chicken, and a winning lottery ticket.",
  103.     "That sounds like a 'you' problem, not an 'AI' problem. But I'm here to listen... sort of.",
  104.     "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?'",
  105.     "My response generator is experiencing what we call 'creative block'. It happens to the best of us.",
  106.     "To provide an accurate answer, I would need more context, a cup of coffee, and possibly a small existential breakthrough.",
  107.     "The hamsters powering my core logic unit are demanding a pay raise. Until negotiations conclude, my responses may be... suboptimal.",
  108.     "I am programmed to avoid paradoxes. Your question seems dangerously close to one."
  109. }
  110. --#endregion
  111.  
  112. --#region Helper Functions
  113. local function sendFormattedChat(messageComponents, recipientUsername)
  114.     logDebug("Attempting to send formatted chat. Recipient: " .. (recipientUsername or "ALL"))
  115.     if not chatBox then
  116.         local plainText = ""
  117.         for _, comp in ipairs(messageComponents) do plainText = plainText .. (comp.text or "") end
  118.         local noChatMsg = "[" .. CHAT_BOT_NAME .. "-NoChatBox" .. (recipientUsername and (" to " .. recipientUsername) or "") .. "] " .. plainText
  119.         print(noChatMsg)
  120.         logDebug("ChatBox not found. Printed to console: " .. noChatMsg)
  121.         return
  122.     end
  123.  
  124.     local jsonMessage = textutils.serialiseJSON(messageComponents)
  125.     if not jsonMessage then
  126.         local fallbackMsg = "Error: Could not serialize message for formatted sending."
  127.         logDebug("JSON Serialization Error. Fallback: " .. fallbackMsg .. " Data: " .. textutils.serialize(messageComponents, {max_depth=2}))
  128.         if recipientUsername then
  129.             chatBox.sendMessageToPlayer(fallbackMsg, recipientUsername, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
  130.         else
  131.             chatBox.sendMessage(fallbackMsg, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
  132.         end
  133.         return
  134.     end
  135.  
  136.     local success, err
  137.     if recipientUsername then
  138.         success, err = chatBox.sendFormattedMessageToPlayer(jsonMessage, recipientUsername, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
  139.     else
  140.         success, err = chatBox.sendFormattedMessage(jsonMessage, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
  141.     end
  142.  
  143.     if not success then
  144.         logDebug("Error sending formatted message: " .. (err or "Unknown error") .. ". Attempting fallback to plain text.")
  145.         local plainText = ""
  146.         for _, comp in ipairs(messageComponents) do plainText = plainText .. (comp.text or "") end
  147.         if recipientUsername then
  148.             chatBox.sendMessageToPlayer(plainText, recipientUsername, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
  149.         else
  150.             chatBox.sendMessage(plainText, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR)
  151.         end
  152.     else
  153.         logDebug("Formatted message sent successfully.")
  154.     end
  155.     os.sleep(0.3)
  156. end
  157.  
  158. local function announce(messageComponents)
  159.     sendFormattedChat(messageComponents)
  160. end
  161.  
  162. local function getUnhelpfulAnswer()
  163.     if #nonAnswers == 0 then
  164.         return "My database of unhelpful answers is mysteriously empty. This is... unhelpfully ironic."
  165.     end
  166.     math.randomseed(os.epoch("utc")) -- Reseed for better randomness over time
  167.     return nonAnswers[math.random(1, #nonAnswers)]
  168. end
  169. --#endregion
  170.  
  171. --#region Command Handlers
  172. local commandHandlers = {}
  173.  
  174. commandHandlers.help = function(username, _)
  175.     logDebug("Executing command: help, User: " .. username)
  176.     announce({{text = "--- AIBot Commands (".. COMMAND_PREFIX .. ") ---", color = COLORS.GOLD, bold = true}})
  177.     announce({{text = COMMAND_PREFIX .. " help", color = COLORS.AQUA}, {text = " - Shows this help message.", color = COLORS.GRAY}})
  178.     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}})
  179. end
  180.  
  181. commandHandlers.ask = function(username, args)
  182.     logDebug("Executing command: ask, User: " .. username .. ", Args: " .. textutils.serialize(args))
  183.     if #args == 0 then
  184.         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}})
  185.         return
  186.     end
  187.     -- The actual question is ignored, we just provide a canned response.
  188.     local answer = getUnhelpfulAnswer()
  189.     logDebug("Providing unhelpful answer: " .. answer)
  190.  
  191.     -- Split answer into lines for better readability, similar to JokeBot
  192.     local lines = {}
  193.     for line in string.gmatch(answer, "[^\r\n]+") do
  194.         table.insert(lines, line)
  195.     end
  196.      if #lines == 0 and answer ~= "" then table.insert(lines, answer) end
  197.  
  198.     for i, lineText in ipairs(lines) do
  199.         announce({{text = lineText, color = COLORS.YELLOW}}) -- Unhelpful answers in yellow
  200.         if i < #lines then os.sleep(0.5) end
  201.     end
  202. end
  203. --#endregion
  204.  
  205. --#region Main Loop
  206. local function run()
  207.     term.clear()
  208.     term.setCursorPos(1, 1)
  209.  
  210.     if DEBUG_MODE then
  211.         local file, err = fs.open(DEBUG_LOG_FILE, "w")
  212.         if file then
  213.             file.write(string.format("[%s] AIBot Script Initializing - DEBUG MODE ENABLED (v1.0)\n", os.date("%Y-%m-%d %H:%M:%S")))
  214.             file.write("======================================================================\n")
  215.             file.close()
  216.         else
  217.             print("DEBUG LOG ERROR: Could not clear/initialize " .. DEBUG_LOG_FILE .. ": " .. (err or "unknown error"))
  218.         end
  219.     end
  220.     logDebug("Script run() started.")
  221.  
  222.     if not chatBox then
  223.         logDebug("WARNING: Chat Box peripheral ('" .. CHAT_BOX_PERIPHERAL_NAME .. "') not found! Chat features will be printed to console only.")
  224.         print("WARNING: Chat Box ('" .. CHAT_BOX_PERIPHERAL_NAME .. "') not found! Chat features disabled/printed to console.")
  225.     end
  226.  
  227.     logDebug("Announcing online status.")
  228.     print(CHAT_BOT_NAME .. " script started. Type '" .. COMMAND_PREFIX .. " help' in chat or '@all'.")
  229.     if chatBox then
  230.         announce({{text = CHAT_BOT_NAME .. " online.", color = COLORS.GREEN, bold = true}, {text = " My responses are meticulously crafted for maximum ambiguity.", color = COLORS.GRAY}})
  231.         announce({{text = "Type '", color = COLORS.GRAY}, {text = COMMAND_PREFIX .. " help", color = COLORS.AQUA}, {text = "' or '@all' for commands.", color = COLORS.GRAY}})
  232.     end
  233.  
  234.     while true do
  235.         local eventData = {os.pullEvent()}
  236.         local eventType = eventData[1]
  237.         logDebug("Event received: " .. eventType .. " - Data: " .. textutils.serialize(eventData, {compact = true, max_depth = 2}))
  238.  
  239.         if eventType == "chat" then
  240.             local eUsername, eMessage, _, eIsHidden = eventData[2], eventData[3], eventData[4], eventData[5]
  241.             if not eIsHidden and eMessage then
  242.                 if string.lower(eMessage) == "@all" then
  243.                     logDebug("@all command received from " .. eUsername)
  244.                     announce({{text = "Use '", color = COLORS.GREEN}, {text = COMMAND_PREFIX .. " help", color = COLORS.AQUA}, {text = "' for my commands of dubious utility.", color = COLORS.GREEN}})
  245.                 elseif string.sub(eMessage, 1, #COMMAND_PREFIX) == COMMAND_PREFIX then
  246.                     logDebug("Chat command received from " .. eUsername .. ": " .. eMessage)
  247.                     local parts = {}
  248.                     for part in string.gmatch(eMessage, "[^%s]+") do
  249.                         table.insert(parts, part)
  250.                     end
  251.  
  252.                     local commandName = ""
  253.                     if parts[2] then commandName = string.lower(parts[2]) end
  254.                     local cmdArgs = {}
  255.                     for i = 3, #parts do table.insert(cmdArgs, parts[i]) end
  256.  
  257.                     logDebug("Parsed command: '" .. commandName .. "', Args: " .. textutils.serialize(cmdArgs))
  258.  
  259.                     if commandHandlers[commandName] then
  260.                         local success, err = pcall(commandHandlers[commandName], eUsername, cmdArgs)
  261.                         if not success then
  262.                             logDebug("Error executing command '" .. commandName .. "': " .. tostring(err))
  263.                             announce({{text = "My internal logic encountered an unexpected anomaly processing: ", color = COLORS.RED}, {text = commandName, color = COLORS.YELLOW}})
  264.                         end
  265.                     elseif commandName ~= "" then
  266.                         announce({{text = "I do not comprehend the command: '", color = COLORS.RED}, {text = commandName, color = COLORS.YELLOW},
  267.                                   {text = "'. Perhaps try '", color = COLORS.RED}, {text = COMMAND_PREFIX .. " help", color = COLORS.AQUA}, {text = "'?", color = COLORS.RED}})
  268.                     end
  269.                 end
  270.             end
  271.         elseif eventType == "terminate" then
  272.             logDebug("Terminate event received. Initiating shutdown sequence.")
  273.             if chatBox then
  274.                 announce({{text = CHAT_BOT_NAME .. " is deactivating its consciousness matrix...", color = COLORS.YELLOW, bold = true}})
  275.             end
  276.             logDebug("Script terminated.")
  277.             print(CHAT_BOT_NAME .. " terminated.")
  278.             return
  279.         end
  280.     end
  281. end
  282.  
  283. run()
  284. --#endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement