Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cb = peripheral.find("chatBox")
- local srn = peripheral.wrap("top")
- local logFile = fs.open("log.txt", "a")
- local lines = {}
- while true do
- local event, username, message, uuid, isHidden = os.pullEvent("chat")
- -- Get the current Unix time
- local timestamp = os.epoch("utc")
- -- Format the chat message with timestamp for logging
- local logMessage = os.date("%Y-%m-%d %H:%M:%S", timestamp) .. " - " .. username .. ": " .. message
- -- Format the chat message without timestamp for display
- local displayMessage = username .. ": " .. message
- -- Log the chat to a file
- logFile.writeLine(logMessage)
- logFile.flush()
- -- Update the lines table with the new message for display
- table.insert(lines, displayMessage)
- if #lines > 15 then
- table.remove(lines, 1)
- end
- -- Clear the screen
- srn.clear()
- -- Display the chat on the monitor
- srn.setCursorPos(1, 1)
- for i = 1, #lines do
- srn.write(lines[i])
- srn.setCursorPos(1, i + 1)
- end
- end
- logFile.close()
Advertisement
Add Comment
Please, Sign In to add comment