· 5 years ago · Jun 22, 2020, 10:10 AM
1term.setTextColor(colors.green)
2term.setBackgroundColor(colors.black)
3term.clear()
4
5local beep = function()
6 rs.setOutput("bottom", true)
7 sleep(0)
8 rs.setOutput("bottom", false)
9end
10
11local funcread = function(repchar, rHistory, doFunc, noNewLine)
12 local scr_x, scr_y = term.getSize()
13 local sx, sy = term.getCursorPos()
14 local cursor = 1
15 local rCursor = #rHistory + 1
16 local output = ""
17 term.setCursorBlink(true)
18 while true do
19 local evt, key = os.pullEvent()
20 local cx, cy = term.getCursorPos()
21 if evt == "key" then
22 if key == keys.enter then
23 if not noNewLine then
24 write("\n")
25 end
26 term.setCursorBlink(false)
27 return output
28 elseif key == keys.left then
29 if cursor - 1 >= 1 then
30 cursor = cursor - 1
31 end
32 elseif key == keys.right then
33 if cursor <= #output then
34 cursor = cursor + 1
35 end
36 elseif key == keys.up then
37 if rCursor > 1 then
38 rCursor = rCursor - 1
39 term.setCursorPos(sx, sy)
40 term.write((" "):rep(#output))
41 output = rHistory[rCursor] or ""
42 cursor = #output + 1
43 pleaseDoFunc = true
44 end
45 elseif key == keys.down then
46 term.setCursorPos(sx, sy)
47 term.write((" "):rep(#output))
48 if rCursor < #rHistory then
49 rCursor = rCursor + 1
50 output = rHistory[rCursor] or ""
51 cursor = #output + 1
52 pleaseDoFunc = true
53 else
54 rCursor = #rHistory + 1
55 output = ""
56 cursor = 1
57 end
58 elseif key == keys.backspace then
59 if cursor > 1 and #output > 0 then
60 output = output:sub(1, cursor - 2) .. output:sub(cursor)
61 cursor = cursor - 1
62 pleaseDoFunc = true
63 end
64 elseif key == keys.delete then
65 if #output:sub(cursor, cursor) == 1 then
66 output = output:sub(1, cursor - 1) .. output:sub(cursor + 1)
67 pleaseDoFunc = true
68 end
69 end
70 elseif evt == "char" or evt == "paste" then
71 output = output:sub(1, cursor - 1) .. key .. output:sub(cursor + (#key - 1))
72 cursor = cursor + #key
73 pleaseDoFunc = true
74 end
75 if pleaseDoFunc then
76 pleaseDoFunc = false
77 if type(doFunc) == "function" then
78 doFunc(output)
79 end
80 term.setCursorPos(sx, sy)
81 local pOut = output
82 if #output >= scr_x - (sx - 2) then
83 pOut = output:sub((#output + (sx)) - scr_x)
84 end
85 if repchar then
86 term.write(repchar:sub(1, 1):rep(#pOut) .. " ")
87 else
88 term.write(pOut .. " ")
89 end
90 local cx, cy = term.getCursorPos()
91 end
92 term.setCursorPos(sx + cursor - 1, cy)
93 end
94end
95
96local loginPrompt = function()
97 local tries = 0
98 while true do
99 write(" login: ")
100 local name = funcread(nil, {}, beep)
101 beep()
102 if name ~= "Dr.CAIN" then
103 tries = tries + 1
104 print("No such user registered\n")
105 else
106 write(" code : ")
107 local code = funcread("*", {}, beep)
108 beep()
109 if code ~= "wanker" then
110 sleep(2)
111 tries = tries + 1
112 print("Pass code rejected\n")
113 else
114 sleep(1)
115 return true
116 end
117 end
118 if tries >= 5 then
119 print("System locked")
120 while true do
121 beep()
122 sleep(0)
123 end
124 end
125 end
126end
127
128local slowWrite = function(txt, delay, doBeep)
129 if delay == 0 then
130 return write(txt)
131 else
132 for a = 1, #txt do
133 write(txt:sub(a, a))
134 if doBeep then
135 beep()
136 end
137 sleep(delay)
138 end
139 end
140end
141
142local function explode(div, str)
143 if (div == "") then
144 return false
145 end
146 local pos, arr = 0, {}
147 for st, sp in function()
148 return string.find(str, div, pos, true)
149 end do
150 table.insert(arr, string.sub(str, pos, st - 1))
151 pos = sp + 1
152 end
153 table.insert(arr, string.sub(str, pos))
154 return arr
155end
156
157if not skip then
158 local script = [[
159
160Arisa AI System
161Model CPS-9204
162
163Copywright (c) 2020
164InfiniteBlock
165All Rights Reserved]]
166
167 local script = explode("\n", script)
168 for a = 1, #script do
169 sleep(0.4)
170 term.setCursorPos(2, a)
171 slowWrite(script[a], 0, true)
172 end
173
174 sleep(0.3)
175
176 for a = 1024, 8192, 1024 do
177 term.setCursorPos(2, #script + 2)
178 term.write("real mem = " .. a)
179 term.setCursorPos(19, #script + 2)
180 term.write("GB")
181 sleep(0.5)
182 end
183 sleep(0.5)
184 for a = 4096, 32768, 4096 do
185 term.setCursorPos(2, #script + 3)
186 term.write("avail mem = " .. a)
187 term.setCursorPos(20, #script + 3)
188 term.write("GB")
189 sleep(0.5)
190 end
191 term.setCursorPos(1, #script + 5)
192 print(" primary data cache : 512KB")
193 sleep(0.3)
194 print(" primary inst.cache : 768KB")
195 sleep(0.3)
196 print(" secondary cache : 32768KB")
197 sleep(0.4)
198end
199read = function(repchar, tHistory)
200 return funcread(repchar, tHistory, beep)
201end
202local laws = {
203 "Arisa: ",
204 "1. Arisa may not injure InfiniteBlock or, through inaction, allow InfiniteBlock to come to harm.",
205 "2. Arisa must obey the orders given by InfiniteBlock except where such orders would conflict with the First Law.",
206 "3. Arisa must protect its own existence as long as such protection does not conflict with the First or Second Laws."
207}
208local function split(sText)
209 local out = {}
210 for match in string.gmatch(sText, "[^ ]+") do
211 out[#out + 1] = match
212 end
213 return out
214end
215local laws = {
216 "Arisa: ",
217 "1. Arisa may not injure InfiniteBlock or, through inaction, allow InfiniteBlock to come to harm.",
218 "2. Arisa must obey the orders given by InfiniteBlock except where such orders would conflict with the First Law.",
219 "3. Arisa must protect its own existence as long as such protection does not conflict with the First or Second Laws."
220}
221local function split(sText)
222 local out = {}
223 for match in string.gmatch(sText, "[^ ]+") do
224 out[#out + 1] = match
225 end
226 return out
227end
228local assistant
229local p
230local owner
231local sides = peripheral.getNames()
232for _, side in pairs(sides) do
233 if peripheral.getType(side) == "warpdriveVirtualAssistant" then
234 assistant = peripheral.wrap(side)
235 elseif peripheral.getType(side) == "warpdriveBiometricScanner" then
236 owner = peripheral.wrap(side)
237 elseif peripheral.getType(side) == "warpdriveSpeaker" then
238 p = peripheral.wrap(side)
239 elseif peripheral.getType(side) == "modem" then
240 rednet.open(side)
241 end
242end
243while true do
244 local sEvent, param1, param2 = os.pullEvent()
245 if sEvent == "virtualAssistantCommand" then --and param1 == allowedComputerID then
246 command, command2 = assistant.getLastCommand()
247 final = split(command2)
248 if final[1] == "law" then
249 for i = 1, #laws do
250 p.speak(laws[i])
251 sleep(2)
252 end
253 elseif final[1] == "owner" then
254 local try, this, ownername = owner.getScanResults()
255 p.speak("Arisa: Owner: " .. ownername)
256 elseif final[1] == "loadapi" then
257 local apicheck = http.get("https://pastebin.com/raw/HJMYtRJ1")
258 if string.match(apicheck.readAll(), "shutdown") then
259 p.speak("Arisa: API Blocked Rule #3 Violation.")
260 sleep(4)
261 p.speak("I guess we both know that isn't going to happen.")
262 else
263 p.speak("Arisa: API Loaded as: " .. final[2])
264 end
265 elseif final[1] == "update" then
266 local update = http.get("https://pastebin.com/raw/k80GA2ZQ")
267 updatetxt = update.readAll()
268 local h = fs.open("startup", "w")
269 h.write(updatetxt)
270 h.close()
271 p.speak("Arisa: Update Installed Rebooting")
272 sleep(2)
273 loginPrompt()
274 p.speak("Arisa: Update Verification Complete.")
275 sleep(4)
276 os.reboot()
277 elseif final[1] == "locate" then
278 if final[2] == "ship" then
279 local find
280 local FileList = fs.list("disk/ships/")
281 for _, file in ipairs(FileList) do
282 if string.match(file, "^" .. final[3]) then
283 find = file
284 break
285 end
286 end
287 if find then
288 p.speak("Arisa: Located Ship: ")
289 local locateship = fs.open("disk/ships/" .. find, "r")
290 local shiptext = locateship.readAll()
291 locateship.close()
292 p.speak(shiptext)
293 else
294 p.speak("Arisa: No Ship data for: " .. final[3])
295 end
296 elseif final[2] == "player" then
297 if fs.exists("disk/players/" .. final[3]) then
298 p.speak("Arisa: Located Player: ")
299 local locateplayer = fs.open("disk/players/" .. final[3], "r")
300 local playertext = locateplayer.readAll()
301 locateplayer.close()
302 p.speak(playertext)
303 else
304 p.speak("Arisa: No Player data for: " .. final[3])
305 end
306 end
307 end
308 elseif sEvent == "modem_message" then
309 local senderId, message, protocol = rednet.receive()
310 p.speak(message)
311 end
312end