ComputerCraft Archive

readChatTerm

computer operating-system Vexatos github

Description

My Computercraft program collection

Installation

Copy one of these commands into your ComputerCraft terminal:

wget:wget https://raw.githubusercontent.com/Vexatos/ComputerCraft-Programs/master/Main/readChat/readChatTerm.lua readchatterm
Archive:wget https://cc.shobie.xyz/cc/get/gh-Vexatos-ComputerCraft-Programs-main-readchat-readchatterm readchatterm
Quick Install: wget https://cc.shobie.xyz/cc/get/gh-Vexatos-ComputerCraft-Programs-main-readchat-readchatterm readChatTerm

Usage

Run: readChatTerm

Tags

none

Source

View Original Source

Code Preview

os.loadAPI("/rom/apis/miscperipheralsutil")
chattbl = {}

chat, chatSide = miscperipheralsutil.getPeripheral("chat")
if chat == nil then
  print("No Chat peripheral found")
  return
end

print("Using Chat peripheral on "..chatSide)
print("Reading chat...")
print("")

local file = fs.open("/liveLog","a")

function read()
 while true do
  event,player,message = os.pullEventRaw("chat")
  write("[d".. os.day() .. "," .. textutils.formatTime(os.time(),true) .. "]")
  print(player .. "> " .. message)
  file.writeLine("[d".. os.day() .. "," .. textutils.formatTime(os.time(),true).. "]" .. player .. "> " .. message)
  chattbl[#chattbl+1] = "[d".. os.day() .. "," .. textutils.formatTime(os.time(),true).. "]" .. player .. "> " .. message
 end
end

function stop()
 event2,key = os.pullEventRaw("key")
 if key == 211 then
  file.close()
  shell.run("save")
  print("Terminated!")
  return
 end
end

parallel.waitForAny(read,stop)