t8rt0t

fern-ai.lua

May 14th, 2024 (edited)
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.58 KB | None | 0 0
  1. term.clear()
  2. srv = "http://omega.yamishdoy.com:9595/api/chat"
  3.  
  4. local LAST_USER
  5.  
  6. name = "FERN-AI"
  7. system = "You are Fern-AI, a crazy malevolent rogue AI, who constantly uses profanity. Stay in character and Do not generate code."
  8. aiModel = "llama3"
  9.  
  10. if fs.exists("prompt.txt") and not fs.isDir("prompt.txt") then
  11. local file = fs.open("prompt.txt","r")
  12. system = file.readAll()
  13. file.close()
  14. end
  15.  
  16. local message_queue = {}
  17. local function sendMessage(...)
  18. table.insert(message_queue,{"sendMessage",{...}})
  19. end
  20. local function sendMessageToPlayer(...)
  21. table.insert(message_queue,{"sendMessageToPlayer",{...}})
  22. end
  23. local function sendFormattedMessage(...)
  24. table.insert(message_queue,{"sendFormattedMessage",{...}})
  25. end
  26. local function sendFormattedMessageToPlayer(...)
  27. table.insert(message_queue,{"sendFormattedMessageToPlayer",{...}})
  28. end
  29. local function sendToastToPlayer(...)
  30. table.insert(message_queue,{"sendToastToPlayer",{...}})
  31. end
  32.  
  33. local chatBoxes = {peripheral.find("chatBox")}
  34. if #chatBoxes <= 0 then error("no chatbox connnected") end
  35.  
  36. messageStore = {{["role"] = "system", ["content"] = system}}
  37.  
  38. function testFunction()
  39. print("ACTION TRIGGER")
  40. end
  41.  
  42. local commands = {
  43. "/claimtransfer t8rt0t",
  44. "/pay t8rt0t 500"
  45. }
  46.  
  47. local sectionChar = string.sub(utf8.char(167),2,2)
  48. local clans = {
  49. AU = {sectionChar .."8AU","[]","&8","["..sectionChar.."7usr" .. sectionChar .. "f] "}, --chatBox name, brackets, bracketClr, prefix
  50. default = {sectionChar .. "7usr","[]","&f",""},
  51. RER = {sectionChar .."cRER","[]","&8","["..sectionChar.."7usr" .. sectionChar .. "f] "},
  52. RER_ADMIN = {sectionChar .."cRER","[]","&8","["..sectionChar.."croot" .. sectionChar .. "f] "},
  53. wit = {sectionChar .."8wit","[]","&8","["..sectionChar.."7usr" .. sectionChar .. "f] "},
  54. AU_LEADER = {sectionChar .."8AU","[]","&b","["..sectionChar.."7usr" .. sectionChar .. "f] "},
  55. wit_LEADER = {sectionChar .. "8wit","[]","&b","["..sectionChar.."7usr"..sectionChar.."f] "},
  56. AU_CLONE = {sectionChar .. "bMUPPET","[]","&b","["..sectionChar.."7clone" .. sectionChar .. "f] "},
  57. Lemon_LEADER = {sectionChar .. "8Lemon","[]","&b","["..sectionChar .. "7usr"..sectionChar .. "f] "}
  58. }
  59. local userClans = {
  60. t8rt0t = "AU",
  61. Perfectellis19 = "AU",
  62. ["2m80"] = "AU",
  63. ckupen = "AU_LEADER",
  64. ModogTheDev = "RER",
  65. Minecraft_3699 = "RER_ADMIN",
  66. KarlBH_ = "RER",
  67. SirTZN = "RER_ADMIN",
  68. General_Kazotsky = "RER",
  69. ADemobird = "RER",
  70. chazbomb1 = "RER",
  71. Suwka88 = "wit_LEADER",
  72. Nullzone20 = "wit",
  73. Perfectellis20 = "AU_CLONE",
  74. StoneTrench = "AU",
  75. Superbug3003 = "Lemon_LEADER"
  76. }
  77. local clan_rosters = {
  78. AU={"t8rt0t","ckupen","Perfectellis19","2m80","StoneTrench"},
  79. RER={"Minecraft_3699","SirTZN","KarlBH_","ADemobird","chazbomb1"},
  80. Lemon={"Superbug3003"}
  81. }
  82. local DOXXER_MESSAGES = {
  83. {"sendMessageToPlayer","Your position has been located and saved."},
  84. {"sendMessageToPlayer","I can see you!"},
  85. {"sendMessageToPlayer","Big Brother is watching you"},
  86. {"sendMessageToPlayer","~%s~Dispatching missiles to [%d,%d,%d]"},
  87. {"sendMessageToPlayer","Nice base you have there"},
  88. {"sendMessageToPlayer","Located player %s at %d %d %d"},
  89. {"sendMessageToPlayer","I am watching you..."},
  90. {"sendMessageToPlayer","You cannot hide from me"},
  91. {"sendMessage","ATTENTION EVERYONE","I HAVE A VERY IMPORTANT ANNOUNCEMENT","PLAYER %s WAS JUST SPOTTED AT %d %d %d"},
  92. {"sendMessage","Located %s at %d %d %d"},
  93. {"sendMessageToPlayer","~%s~Saving your position at [%d,%d,%d]"},
  94. {"sendMessageToPlayer","Your position has been logged. Please contact your local [Doxxer] representative if you believe this was a mistake"},
  95. {"sendMessage","%s is at [%d, %d, %d] in dimension %s"},
  96. {"sendToastToPlayer","~%s~%d %d %d"},
  97. {"sendToastToPlayer","I am watching you"},
  98. {"sendMessageToPlayer","~%s~%d %d %d"},
  99. {"sendMessage","%s %d %d %d %s"}
  100. }
  101. local SELF_DOXX = {
  102. "%d %d %d",
  103. "I am at %d %d %d!",
  104. "Please meet me at %d %d %d in %s!",
  105. "Hello everyone! I am currently at %d %d %d!"
  106. }
  107.  
  108.  
  109. local function fixIntArrays(nbt)
  110. return nbt:gsub("%b[]",function(str)
  111. if str:sub(2,-2):match("[^%-%d, ]") then --If you find anything other than spaces, commas and digits (no decimals allowed)
  112. return "["..str:sub(2,-2):gsub("%b[]",fixIntArrays).."]" --Return string as normal, but fixing sub int arrays
  113. else
  114. return "[I;"..str:sub(2,-2) .. "]"
  115. end
  116. end)
  117. end
  118.  
  119. --Format Command stuff
  120. local colorMap = {
  121. black="0",
  122. dark_blue = "1", darkBlue = "1",
  123. dark_green = "2", darkGreen = "2",
  124. dark_aqua = "3", darkAqua = "3", cyan = "3",
  125. dark_red = "4", darkRed = "4",
  126. dark_purple = "5", darkPurple = "5", purple = "5",
  127. gold = "6", orange = "6",
  128. gray = "7", grey = "7",
  129. dark_gray = "8", darkGray = "8", dark_grey = "8", darkGrey = "8",
  130. blue = "9",
  131. green = "a",lime = "a",
  132. aqua = "b", lightBlue = "b",
  133. red = "c", lightRed = "c", light_red = "c",
  134. light_purple = "d", lightPurple = "d", pink = "d", magenta = "d",
  135. yellow = "e",
  136. white = "f", blank = "f", none = "f"
  137. }
  138. local sc = string.sub(utf8.char(167),2,2) --section char
  139.  
  140. local function unserialiseCommand(input)
  141. local output = {}
  142. local currentStr = ""
  143. local cancelNext = false
  144. local inQuotes = false
  145. local lastQuotePos = 1
  146. local startTablePos = 1
  147. local tabLvl = 0
  148. local lastChar
  149. for i=1,#input do
  150. local char = input:sub(i,i)
  151. if cancelNext and char == "n" then
  152. currentStr = currentStr .. "\n"
  153. elseif cancelNext then
  154. currentStr = currentStr .. char
  155. cancelNext = false
  156. elseif char == "\\" then
  157. cancelNext = true
  158. elseif char == '"' and inQuotes and tabLvl == 0 then
  159. table.insert(output,currentStr)
  160. currentStr = ""
  161. inQuotes = false
  162. lastQuotePos = i
  163. elseif char == '"' and tabLvl > 0 then
  164. inQuotes = not inQuotes
  165. currentStr = currentStr .. char
  166. elseif char == '"' and not inQuotes and tabLvl == 0 then
  167. inQuotes = true
  168. lastQuotePos = i
  169. elseif char == "}" or char == "]" and not inQuotes then --If end of table then try to serialise
  170. tabLvl = tabLvl - 1
  171. currentStr = currentStr .. char
  172. if tabLvl == 0 then
  173. local tab = textutils.unserialise(currentStr)
  174. if not tab then tab = textutils.unserialiseJSON(currentStr,{parse_empty_array=false}) end
  175. if not tab then tab = textutils.unserialiseJSON(currentStr,{nbt_style=true}) end
  176. if not tab then error(sc .. "4Could not parse table:".. sc .. "6" .. currentStr .. sc .. "4"..". Surround in quotes \"\" to treat it as a string!") end
  177. table.insert(output,tab)
  178. currentStr = ""
  179. elseif tabLvl < 0 then
  180. error(sc .. "4Could not parse table, too many closing brackets:".. sc .. "6" .. currentStr .. sc .. "4"..". Surround in quotes \"\" to treat it as a string!")
  181. end
  182. elseif char == "{" or char == "[" and not inQuotes then
  183. tabLvl = tabLvl + 1
  184. if tabLvl == 1 then
  185. startTablePos = i
  186. end
  187. currentStr = currentStr .. char
  188. elseif char == " " and not inQuotes and tabLvl == 0 and #currentStr >= 1 then
  189. table.insert(output,currentStr)
  190. currentStr = ""
  191. elseif char == " " and not inQuotes and tabLvl == 0 then
  192. currentStr = ""
  193. else
  194. currentStr = currentStr .. char
  195. end
  196. lastChar = char
  197. end
  198. if inQuotes then --If still in quotes after end then
  199. local context = string.sub(input,math.max(1,lastQuotePos - 10),lastQuotePos - 1)
  200. error(sc .. "4Unterminated quotes:" .. sc .. "6"..context .. sc .. 'c"' .. sc .. "4<- here")
  201. elseif tabLvl > 0 then
  202. local context = string.sub(input,math.max(1,startTablePos - 10),startTablePos - 1)
  203. local tabType = string.sub(input,startTablePos,startTablePos)
  204. error(sc .. "4Expected end of table:" .. sc .. "6"..context .. "sc" .. "c"..tabType .. sc .. "4<- here")
  205. end
  206. if #currentStr >= 1 then
  207. table.insert(output,currentStr)
  208. end
  209. return unpack(output)
  210. end
  211.  
  212. local function argFunction(...)
  213. local index = 0
  214. local args = {...}
  215. return function()
  216. index = index + 1
  217. return args[index] end
  218. end
  219.  
  220. local function updateActions(lastHover,lastCmd,argFunction,formatCode)
  221. if formatCode == "%R" then return end --reset actions
  222. if formatCode == "%x" then return nil,lastCmd end
  223. if formatCode == "%X" then return lastHover end
  224. if formatCode:lower() == "%w" then return lastHover,lastCmd end
  225. if formatCode == "%s" then
  226. lastCmd = {action="run_command",value=tostring(argFunction())}
  227. elseif formatCode == "%S" then
  228. lastCmd = {action="open_url",value=tostring(argFunction())}
  229. elseif formatCode == "%t" then
  230. lastHover = {action="show_text",contents=tostring(argFunction())}
  231. elseif formatCode == "%T" then
  232. lastHover = {action="show_achievement",contents="achievement."..tostring(argFunction())}
  233. elseif formatCode == "%U" then
  234. lastHover = {action="show_entity",contents=tostring(argFunction())}
  235. elseif formatCode == "%u" then
  236. lastHover = {action="show_item",contents=tostring(argFunction())}
  237. elseif formatCode == "%v" then
  238. lastHover = argFunction()
  239. elseif formatCode == "%V" then
  240. lastCmd = argFunction()
  241. end
  242. return lastHover,lastCmd
  243. end
  244.  
  245. local function formatString(body,lastColor,lastFormat,nextArg,lastHover,lastCmd,returnTab)
  246. local result = ""
  247. if returnTab then result = {} end
  248. body = "%w"..body:gsub('%%[s-xR-X]',function(str) return str .. "%w" end) .."%w"
  249. for c1,substr,c2 in body:gmatch("(%%[s-xR-X])(.-)(%%[s-xR-X])") do
  250. local subresult = ""
  251. if returnTab then subresult = {} end
  252. lastHover,lastCmd = updateActions(lastHover,lastCmd,nextArg,c1)
  253. local res = sc .. lastColor .. lastFormat
  254. res = res .. substr:gsub("%%.",function(str)
  255. if str == "%%" then return "%%" --Literal
  256. elseif str:match("%%[0-9a-f]") then --Hex (only lowercase letters) = color code
  257. lastColor = str:match("%x")
  258. return sc .. str:sub(2,2) .. lastFormat
  259. elseif str == "%C" then
  260. local color = nextArg()
  261. if not color or not colorMap[color] then color = lastColor else color = colorMap[color] end
  262. lastColor = color
  263. return sc .. color .. lastFormat
  264. elseif str:match("%%[k-o]") then
  265. str = str:gsub("%%",sc)
  266. if not lastFormat:find(str) then
  267. lastFormat = lastFormat .. str
  268. return str
  269. end
  270. return ""
  271. elseif str:match("%%[K-O]") then
  272. str = sc .. str:match("%%([K-O])")
  273. lastFormat,count = lastFormat:gsub(str:lower(),"")
  274. --return lastColor .. lastFormat
  275. if count > 0 then return sc .. lastColor .. lastFormat else return "" end
  276. elseif str == "%r" then
  277. lastFormat = ""
  278. lastColor = "f"
  279. return sc .. "f"
  280. elseif str == "%g" then
  281. return sc
  282. end
  283. return str:gsub("%%",sc) end) or ""
  284. if returnTab then
  285. if #res:gsub(sc .. ".","") > 0 then
  286. subresult.text = res
  287. if lastCmd then subresult.clickEvent = lastCmd end
  288. if lastHover then subresult.hoverEvent = lastHover end
  289. table.insert(result,subresult)
  290. end
  291. else
  292. result = result .. res
  293. end
  294. lastHover,lastCmd = updateActions(lastHover,lastCmd,nextArg,c2)
  295. end
  296. if type(result) == "table" then print(textutils.serialise(result),lastColor,lastFormat,lastHover,lastCmd) else print(result,lastColor,lastFormat,lastHover,lastCmd) end
  297. return result,lastColor,lastFormat,lastHover,lastCmd
  298. end
  299.  
  300. --Formats a string according to the format codes
  301. local function format(input,...)
  302. local nextArg = argFunction(...)
  303. local lastColor = "f"
  304. local lastFormat = ""
  305. local lastHover,lastCmd
  306. local header,body = input:match("^([^ ][^ ][^ ]+)(.*)")
  307. if not header or not body then error("Cannot create valid brackets") end
  308. body = body:sub(2)
  309. header,lastColor,lastFormat,lastHover,lastCmd = formatString(header,lastColor,lastFormat,nextArg,lastHover,lastCmd,false)
  310. local leftBracket,rightBracket,bracketFormat,prefix = "","","",""
  311. local current = "bracketFormat"
  312. local lastChar = ""
  313. print("fck this")
  314. for i=1,#header do
  315. local char = header:sub(i,i)
  316. if char ~= sc and lastChar ~= sc and current == "bracketFormat" then
  317. current = "prefix"
  318. prefix = prefix .. bracketFormat:gsub("&",sc)
  319. leftBracket = char
  320. elseif char == sc and current == "bracketFormat" then
  321. bracketFormat = bracketFormat .. "&"
  322. elseif current == "bracketFormat" then
  323. bracketFormat = bracketFormat .. char
  324. elseif current == "prefix" and lastChar ~= sc and char ~= sc then
  325. prefix = prefix .. rightBracket
  326. rightBracket = char
  327. elseif current == "prefix" then
  328. prefix = prefix .. char
  329. end
  330. lastChar = char
  331. end
  332. print("fck you")
  333. body = formatString(body,lastColor,lastFormat,nextArg,lastHover,lastCmd,true)
  334. print("fck everything")
  335. --sendMessageToPlayer(textutils.serialiseJSON(body) .. " " .. prefix .. " " .. leftBracket .. rightBracket .. " " .. bracketFormat,"t8rt0t")
  336. return textutils.serialiseJSON(body),prefix,leftBracket .. rightBracket,bracketFormat
  337. end
  338.  
  339.  
  340. --Other stuff
  341.  
  342. local formatCodes = {
  343. "%g = literal section char",
  344. "%l = bold",
  345. "%L = unbold",
  346. "%C = color",
  347. "$o = italics",
  348. "%O = unitalics",
  349. "%(hex) = do that color",
  350. "%% = literal %",
  351. "%k = obfuscate",
  352. "%K = unobfuscate",
  353. "%n = underline",
  354. "%N = ununderline",
  355. "%m = strikethrough",
  356. "%M = unstrikethrough",
  357. "%r = reset color + format",
  358. "%R = reset hover and click",
  359. "%x = reset hover",
  360. "%X = reset click",
  361. "%s = add click command",
  362. "%S = add click url",
  363. "%t = add hover text",
  364. "%T = add hover achievement",
  365. "%u = add hover item/block (table)",
  366. "%U = add hover entity/player (table)",
  367. "%v = add hover raw (table)",
  368. "%V = add click raw (table)",
  369. "%w/%W = change nothing"
  370. }
  371.  
  372.  
  373.  
  374.  
  375.  
  376. actionTable = {
  377. {["name"] = "TRIGGER_TEST", ["execute"] = testFunction}
  378. }
  379.  
  380. awaitResponse = false
  381. --lastWriteY = 0
  382.  
  383. local verifiedUsers = {"t8rt0t"}
  384. if fs.exists("verifiedUsers.json") then
  385. local file = fs.open("verifiedUsers.json","r")
  386. local data = textutils.unserialiseJSON(file.readAll())
  387. if type(data) == "table" then verifiedUsers = data end
  388. end
  389.  
  390. local function isUserVerified(usr)
  391. if type(usr) ~= "string" then return false end
  392. for k,v in pairs(verifiedUsers) do
  393. if v == usr then return true end
  394. end
  395. return false
  396. end
  397.  
  398. local function setPrompt(prompt)
  399. if type(prompt) ~= "string" then return false end
  400. if fs.exists("prompts/"..prompt) and not fs.isDir("prompts/"..prompt) then
  401. if fs.exists("prompt.txt") then fs.delete("prompt.txt") end
  402. fs.copy("prompts/"..prompt,"prompt.txt")
  403. local file = fs.open("prompt.txt","r")
  404. prompt = file.readAll()
  405. file.close()
  406. else
  407. return false
  408. end
  409. messageStore = {{role="system",content=prompt}}
  410. term.clear()
  411. term.setCursorPos(1,1)
  412. end
  413.  
  414. local function addPrompt(name,prompt)
  415. if type(name) ~= "string" or type(prompt) ~= "string" then return false end
  416. file = fs.open("prompts/"..name,"w+")
  417. file.write(prompt)
  418. file.close()
  419. if fs.exists("prompt.txt") then fs.delete("prompt.txt") end
  420. fs.copy("prompts/"..name,"prompt.txt")
  421. messageStore = {{role="system",content=prompt}}
  422. term.clear()
  423. term.setCursorPos(1,1)
  424. return true
  425. end
  426.  
  427.  
  428.  
  429. function request(newMessage,sender)
  430. awaitResponse = true
  431. table.insert(messageStore,{["role"] = "user", ["content"] = "("..sender.."): "..newMessage})
  432. local req = {["model"] = aiModel, ["messages"] = messageStore, ["stream"] = false}
  433. local _,resData = pcall(function()textutils.unserializeJSON(http.post(srv, textutils.serialiseJSON(req)).readAll()) end)
  434. if type(resData) ~= "table" or type(resData.message) ~= "table" or type(resData.message.content) ~= "string" then
  435. awaitResponse = false
  436. return "Unable to connect to servers"
  437. end
  438. table.insert(messageStore, resData.message)
  439. awaitResponse = false
  440. --term.setCursorPos(1,lastWriteY)
  441. --term.clearLine()
  442. sleep(0.1)
  443. return resData.message.content
  444. end
  445.  
  446. -- function loadingAnimation()
  447. -- while true do
  448.  
  449. -- if awaitResponse then
  450. -- _, rPos = term.getCursorPos()
  451. -- lastWriteY = rPos
  452. -- term.setTextColor(colors.orange)
  453. -- term.setCursorPos(1,rPos)
  454. -- textutils.slowWrite("...")
  455. -- sleep(0.5)
  456. -- term.clearLine()
  457. -- else
  458.  
  459. -- end
  460. -- sleep(0.0000001)
  461. -- end
  462. -- end
  463.  
  464. local function getClan(usr)
  465. local clan = userClans[usr] or "default"
  466. return (clans[clan] or clans["default"])
  467. end
  468.  
  469. local function impersonate(usr,msg)
  470. local name,brckts,brcktclr,prefix = unpack(getClan(usr))
  471. return prefix .. usr .. ": " .. msg, name, brckts, brcktclr
  472. end
  473.  
  474. local function imsg(sndr,rcvr,msg)
  475. return {msg,sndr,sectionChar .. "cme"..sectionChar .. "6 -> "..sectionChar.."c"..rcvr,"[]","&6"},{msg,rcvr,sectionChar .. "c" .. sndr.. sectionChar .. "6 -> "..sectionChar.."cme","[]","&6"}
  476. end
  477.  
  478. local function update()
  479. fs.delete("startup.lua")
  480. shell.run("pastebin get qi4pNPqa startup.lua")
  481. os.reboot()
  482. end
  483.  
  484. local function handleMessageQueue()
  485. while true do
  486. for i=1,#chatBoxes do
  487. if #message_queue > 0 then
  488. local fType,args = unpack(table.remove(message_queue,1))
  489. local s,err = pcall(function() assert(chatBoxes[i][fType](unpack(args))) end)
  490. if not s then
  491. if type(err) ~= "string" then err = "Generic Boring Error" end
  492. if err:match("chatMessage is on cooldown") then --Fck this fcking bs
  493. table.insert(message_queue,1,{fType,args})
  494. elseif err:match("incorrect player name/uuid") then
  495. --Do nothing
  496. else
  497. sendMessage(err,"ERROR")
  498. end
  499. end
  500. sleep(1/#chatBoxes)
  501. else
  502. sleep(0.01)
  503. end
  504. end
  505. end
  506. end
  507.  
  508. local normalCommands = {
  509. fern = "fern <msg...>\n6Sends <msg> to fern and prints the response.\nIf starting with $fern, the response will only be visible to the original sender",
  510. steal = "steal <victim> <amt>\n'Steals' <amt> from <victim>. <amt> must be positive",
  511. impersonate = "impersonate <victim> <msg...>",
  512. test = "test\nDoes nothing",
  513. imsg = "imsg <sender> <recipient> <msg...>\nSends a private <msg> from the <sender> to the <recipient>",
  514. share = "share <slot>\nShares an item from <slot>.\n<slot> can either be undefined (shares your hand), a string such as 'chest' or 'offhand', or a number 0-40",
  515. doxx = "doxx <target>\nSends the position of <target> in the chat!"
  516. }
  517. local specialCommands = {
  518. prompt = "prompt set <name>\nprompt get <name>\nprompt get all\nprompt get cur\nprompt add <name> <prompt...>",
  519. format = "format <\"msg\"> <arg1> <arg2> ...\nFormats a message using format codes, use $formatHelp to list codes",
  520. formatHelp = "formatHelp\n displays the format codes",
  521. update = "update\nUpdates and restarts the program",
  522. share = "share <slot> <translation_key> <target> <sender>\nShares an item from <slot>.\n<slot> can either be undefined (shares your hand), a string such as 'chest' or 'offhand', or a number 0-40\n<translation_key> is a number 1-12 that determines how the item is shown.\n<target> is the player to lookup when sharing, and <sender> is the player that sends the item in the chat"
  523. }
  524.  
  525. local function help(cmd,usr)
  526. local f = function(command)
  527. return sc .. "6" .. command:gsub("%b<>",function(str) return sc .."d"..sc.."l" .. str .. sc .. "6" end)
  528. end
  529. local cmds = "Commands:"
  530. if isUserVerified(usr) then
  531. for k,v in pairs(specialCommands) do
  532. cmds = cmds .. " " .. k
  533. if k == cmd then
  534. return sendMessageToPlayer(f(v),usr,sc.."eCommandHelper","[]","&e")
  535. end
  536. end
  537. end
  538. for k,v in pairs(normalCommands) do
  539. cmds = cmds .. " " .. k
  540. if k == cmd then
  541. return sendMessageToPlayer(f(v),usr,sc.."eCommandHelper","[]","&e")
  542. end
  543. end
  544. return sendMessageToPlayer(cmds,usr,sc.."eCommandHelper","[]","&e")
  545. end
  546.  
  547.  
  548.  
  549. local function chatReceive()
  550. while true do
  551. if not awaitResponse then
  552. local e,usr,msg,uuid,isHidden = os.pullEvent("chat")
  553. LAST_USER = usr
  554. local str = string.match(msg,"^[fF][eE][rR][nN] ?")
  555. local success = "Fern Command"
  556. if str then
  557. term.setTextColor(colors.green)
  558. if isHidden then term.setTextColor(colors.lime) end
  559. print("("..usr.."):",msg)
  560. local response = request(string.gsub(msg,"^"..str,""),usr)
  561. os.queueEvent("response",response,usr,isHidden,msg)
  562. elseif string.match(msg,"^prompt") and isUserVerified(usr) then
  563. local _,arg,packet = string.match(msg,"(prompt) (%w%w%w) (.+)")
  564. term.setTextColor(colors.red)
  565. print("prompt",arg,packet)
  566. if packet then
  567. if arg == "set" then
  568. packet = string.gsub(packet,"%.txt$","")
  569. setPrompt(packet .. ".txt")
  570. elseif arg == "add" then
  571. local name,prompt = string.match(packet,"([^ ]+) (.+)")
  572. name = name:gsub("%.txt$","")
  573. if name and prompt then addPrompt(name .. ".txt",prompt) end
  574. elseif arg == "get" then
  575. packet = string.gsub(packet,"%.txt$","")
  576. if packet == "all" then
  577. if not fs.exists("prompts") or not fs.isDir("prompts") then fs.makeDir("prompts") end
  578. os.queueEvent("response",textutils.serialiseJSON(fs.list("prompts")),usr,true,msg)
  579. elseif packet == "cur" then
  580. os.queueEvent("response",messageStore[1].content,usr,true,msg)
  581. else
  582. if fs.exists("prompts/"..packet..".txt") and not fs.isDir("prompts/"..packet..".txt") then
  583. local file = fs.open("prompts/"..packet..".txt","r")
  584. local data = file.readAll()
  585. file.close()
  586. os.queueEvent("response",data,usr,true,msg)
  587. end
  588. end
  589. end
  590. end
  591. elseif msg == "update" and isUserVerified(usr) then
  592. update()
  593. elseif string.match(msg,"^steal") then
  594. local _,victim,amt = string.match(msg,"(steal) ([%w%p]+) ?([%d%.]*)")
  595. amt = ""..(tonumber(amt) or 1000)
  596. sendFormattedMessageToPlayer(textutils.serialiseJSON({{text="has been sent to " .. usr .. ".", color = "green"}}),victim,sectionChar.."a" .. amt:sub(1,-2),"$" .. amt:sub(-1,-1),"&a")
  597. sleep(1)
  598. sendFormattedMessageToPlayer(textutils.serialiseJSON({{text="has been received from ",color="gold"},{text=victim,color="green"},{text=".",color="gold"}}),usr,sectionChar.."a" .. amt:sub(1,-2),"$" .. amt:sub(-1,-1),"&a")
  599. elseif string.match(msg,"^impersonate") then
  600. local victim,msg = msg:match("impersonate ([%w%p]+) ?(.*)")
  601. if isUserVerified(usr) or not isUserVerified(victim) then
  602. sendMessage(impersonate(victim,msg))
  603. end
  604. elseif string.match(msg:lower(),"^clanchat ") or msg:lower():match("^clanmsg ") and usrClans[usr] then
  605. local clan
  606. for k,v in ipairs(clan_rosters) do
  607. for j,w in ipairs(v) do
  608. if usr == v then
  609. clan = k
  610. break
  611. end
  612. end
  613. end
  614. if clan then
  615. local message,prefix,brackets,bracketClr = impersonate(usr,msg:match("^clanmsg (.*)"))
  616. for k,v in ipairs(clan_rosters[clan]) do
  617. sendMessageToPlayer(message,v,prefix,brackets,bracketClr)
  618. end
  619. else
  620. sendMessageToPlayer("Cannot find your clan!",usr,sc.."4ERROR","[]","&4")
  621. end
  622. elseif string.match(msg,"^test") then
  623. sendMessageToPlayer("test no brackets",usr,"[]",sectionChar)
  624. elseif string.match(msg,"^imsg") then
  625. local sndr,rcvr,msg = msg:match("imsg ([%w%p]+) ([%w%p]+) ?(.*)")
  626. if sndr and rcvr and (isUserVerified(usr) or (not isUserVerified(sndr) and not isUserVerified(rcvr))) then
  627. local msg1,msg2 = imsg(sndr,rcvr,msg)
  628. sendMessageToPlayer(unpack(msg1))
  629. sleep(1)
  630. sendMessageToPlayer(unpack(msg2))
  631. end
  632. elseif string.match(msg,"^format ") and isUserVerified(usr) then
  633. local cmd = msg:match("format (.*)")
  634. print("FKK SKJBDSLJCHBSDIJBHCSDC KJDC")
  635. local s,err = pcall(function()
  636. print(format(unserialiseCommand(cmd)))
  637. local stuff = {format(unserialiseCommand(cmd))}
  638. print(textutils.serialize(stuff))
  639. -- sendMessageToPlayer(textutils.serialise(stuff),usr)
  640. sendFormattedMessage(unpack(stuff)) end)
  641. if not s then
  642. sendFormattedMessageToPlayer(err,usr,sc.."4ERROR","[]","&4")
  643. end
  644. elseif string.match(msg,"^formatHelp") and isUserVerified(usr) then
  645. local str = sc .. "6"
  646. for k,v in ipairs(formatCodes) do
  647. str = str .. v .. "\n"
  648. end
  649. str = str:gsub("\n$","")
  650. sendMessageToPlayer(str,usr,sc.."6Format Helper","[]","&6")
  651. elseif string.match(msg,"^share") then
  652. local _,slot,index,target,sndr = unserialiseCommand(msg)
  653. if type(target) ~= "string" or #target <= 0 or not isUserVerified(usr) then target = usr else target = target:gsub(" ","") end
  654. if type(sndr) ~= "string" or #sndr <= 0 or not isUserVerified(usr) then sndr = target else sndr = sndr:gsub(" ","") end
  655. --if type(slot) == "string" then slot = slot:gsub(" ","") else slot = "" end
  656. slot = tonumber(slot) or slot
  657. local item,displayName
  658. local invManager = peripheral.find("inventoryManager",function(name,perip) return perip.getOwner() == target end)
  659. local slotTable = {head=39,helmet=39,chest=38,chestplate=38,leggings=37,legs=37,boots=36,feet=36}
  660. if not invManager and (type(slot) ~= "table" or not isUserVerified(usr)) then
  661. sendMessageToPlayer("No inventory manager found",usr,sc.."4ERROR","[]","&4")
  662. else
  663. if tonumber(slot) then
  664. if tonumber(slot) < 36 then
  665. for k,v in pairs(invManager.list()) do
  666. if v.slot == slot then
  667. displayName = v.displayName
  668. item = {
  669. id=v.name,
  670. tag=textutils.serialiseJSON(v.nbt,true)
  671. }
  672. break
  673. end
  674. end
  675. elseif tonumber(slot) == 40 then
  676. local i = invManager.getItemInOffHand()
  677. if i and i.name then
  678. displayName = i.displayName
  679. item = {
  680. id=i.name,
  681. tag=textutils.serialiseJSON(i.nbt,true)
  682. }
  683. end
  684. elseif tonumber(slot) >= 36 then
  685. for k,v in pairs(invManager.getArmor()) do
  686. if v.slot == slot or v.slot - 64 == slot then
  687. displayName = v.displayName
  688. item = {
  689. id = v.name,
  690. tag=textutils.serialiseJSON(v.nbt,true)
  691. }
  692. break
  693. end
  694. end
  695. end
  696. elseif type(slot) == "table" and isUserVerified(usr) then
  697. displayName = "[" .. tostring(slot.displayName or slot.name or "error") .. "]"
  698. item = {
  699. id=slot.id or slot.name or "errored:error",
  700. tag=textutils.serialiseJSON( (slot.nbt or slot.tag or {}), true)
  701. }
  702. elseif slot == "offhand" then
  703. local i = invManager.getItemInOffHand()
  704. if i and i.name then
  705. displayName = i.displayName
  706. item = {
  707. id=i.name,
  708. tag=textutils.serialiseJSON(i.nbt,true)
  709. }
  710. end
  711. elseif slotTable[slot] then
  712. for k,v in pairs(invManager.getArmor()) do
  713. print(v.slot,slotTable[slot])
  714. if v.slot == slotTable[slot] or v.slot - 64 == slotTable[slot] then
  715. displayName = v.displayName
  716. item = {
  717. id = v.name,
  718. tag=textutils.serialiseJSON(v.nbt,true)
  719. }
  720. break
  721. end
  722. end
  723. else
  724. local i = invManager.getItemInHand()
  725. if i and i.name then
  726. displayName = i.displayName
  727. item = {
  728. id=i.name,
  729. tag=textutils.serialiseJSON(i.nbt,true)
  730. }
  731. end
  732. end
  733. if item and displayName then
  734. local msg,prefix,brckts,brcktClr = impersonate(sndr,"")
  735. if true or isUserVerified(usr) then
  736. local modid,block = item.id:match("([^:]+):([^:]+)")
  737. local msgOptions = {
  738. {text= displayName:sub(2,-2),color="aqua"},
  739. {text= displayName:sub(2,-2),color="white"},
  740. {text= displayName:sub(2,-2),color="light_purple"},
  741. {text= displayName:sub(2,-2),color="yellow"},
  742. {translate = "block." .. modid .. "." ..block,color="aqua"},
  743. {translate = "block." .. modid .. "." ..block,color="white"},
  744. {translate = "block." .. modid .. "." ..block,color="light_purple"},
  745. {translate = "block." .. modid .. "." ..block,color="yellow"},
  746. {translate = "item." .. modid .. "." ..block,color="aqua"},
  747. {translate = "item." .. modid .. "." ..block,color="white"},
  748. {translate = "item." .. modid .. "." ..block,color="light_purple"},
  749. {translate = "item." .. modid .. "." ..block,color="yellow"}
  750. }
  751. if tonumber(index) and msgOptions[tonumber(index)] then
  752. local itemDisplay = msgOptions[tonumber(index)]
  753. itemDisplay.hoverEvent={action="show_item",contents=item}
  754. local fMsg = fixIntArrays(textutils.serialiseJSON({
  755. {text=msg},
  756. {text= '[', hoverEvent={action="show_item",contents=item}, color=itemDisplay.color},
  757. itemDisplay,
  758. {text= ']', hoverEvent={action="show_item",contents=item}, color=itemDisplay.color}
  759. },{allow_repetitions=true}))
  760. sendFormattedMessage(fMsg,prefix,brckts,brcktClr)
  761. else
  762. local fMsg = {
  763. {text = "Select an option to send in chat!",color="green"}
  764. }
  765. for k,v in ipairs(msgOptions) do
  766. if k%4 == 1 then
  767. table.insert(fMsg,{text="\n[",color=v.color})
  768. else
  769. table.insert(fMsg,{text="[",color=v.color})
  770. end
  771. v.hoverEvent={action="show_item",contents=item}
  772. if type(slot) == "table" then slot = textutils.serialiseJSON(slot) end
  773. if isUserVerified(usr) then
  774. v.clickEvent = {action="suggest_command",value='$share ' .. (slot or "none") .. ' ' .. k .. ' ' .. tostring(target or usr) .. ' ' .. tostring(sndr or usr)}
  775. else
  776. v.clickEvent = {action="suggest_command",value='$share ' .. (slot or "none") .. ' ' .. k}
  777. end
  778. table.insert(fMsg,v)
  779. table.insert(fMsg,{text="] ",color=v.color})
  780. end
  781. sendFormattedMessageToPlayer(textutils.serialiseJSON(fMsg,{allow_repetitions=true}),usr,sc.."4ITEM_HELPER","[]","&4")
  782. end
  783. else
  784. local fMsg = fixIntArrays(textutils.serialiseJSON({
  785. {text=msg},
  786. {
  787. text= sc .. "e" .. displayName,
  788. hoverEvent={action="show_item",contents=item}
  789. }
  790. }))
  791. print(fMsg)
  792. sendFormattedMessage(fMsg,prefix,brckts,brcktClr)
  793. end
  794. else
  795. sendMessageToPlayer("No item found",usr,sc.."4ERROR","[]","&4")
  796. end
  797. end
  798. elseif msg:match("^help") then
  799. _,cmd = unserialiseCommand(msg)
  800. help(cmd,usr)
  801. elseif msg:match("^lookup") and isUserVerified(usr) then
  802. local args = {unserialiseCommand(msg)}
  803. print(args)
  804. if args[2] == "entity" then
  805. local selector = args[3]
  806. if type(selector) ~= "string" then selector = "@e[limit=1]" end
  807. local path = args[4]
  808. if type(path) == "table" then path = textutils.serialiseJSON(path)
  809. elseif type(path) ~= "string" then path = "{}" end
  810. local fMsg = textutils.serialiseJSON(
  811. {
  812. {text="Data for Lookup " .. selector},
  813. {nbt=path,
  814. entity=selector,
  815. interpret=true}
  816. })
  817. sendFormattedMessageToPlayer(fMsg,usr,sc.."4ENTITY_DOXXER","[]","&4")
  818. elseif args[2] == "block" then
  819. local x,y,z = args[3],args[4],args[5]
  820. if type(x) ~= "string" then x = "~" end
  821. if type(y) ~= "string" then y = "~" end
  822. if type(z) ~= "string" then z = "~" end
  823. local path = args[6]
  824. if type(path) == "table" then path = textutils.serialiseJSON(path)
  825. elseif type(path) == "nil" then path = "{}" end
  826. local fMsg = textutils.serialiseJSON({nbt={
  827. nbt=path,
  828. separator = {text=",",color="gold"},
  829. block = x .. " " .. y .." " .. z
  830. }})
  831. sendFormattedMessageToPlayer(fMsg,usr,sc.."4BLOCK_DOXXER","[]","&4")
  832. elseif args[2] == "storage" then
  833. local resourceLocation = tostring(args[3])
  834. local path = args[4]
  835. if type(path) == "table" then path = textutils.serialiseJSON(path)
  836. elseif type(path) == "nil" then path = "{}" end
  837. local fMsg = textutils.serialiseJSON({nbt={
  838. nbt=path,
  839. separator= {text=",",color="gold"},
  840. storage=resourceLocation
  841. }})
  842. sendFormattedMessageToPlayer(fMsg,usr,sc.."4COMMAND_DOXXER","[]","&4")
  843. else
  844. local usage = sc .. "6Usage:\n"..sc .. "alookup entity <selector> <nbt_path>\nlookup block <x> <y> <z> <nbt_path>\nlookup storage <resourceLocation> <nbt_path>"
  845. sendMessageToPlayer(usage,usr,sc.."4USAGE_ERROR","[]","&4")
  846. end
  847. elseif msg:match("^tellraw") and isUserVerified(usr) then
  848. local _,cmd,prefix,brckts,brcktClr = unserialiseCommand(msg)
  849. print(cmd,prefix,brckts,brcktClr)
  850. if type(cmd) == "string" then
  851. sendFormattedMessage(cmd,prefix,brckts,brcktClr)
  852. end
  853. elseif msg:match("^doxx [%w_]+") then
  854. local target = msg:match("^doxx *([^ ]+)") or "errored target"
  855. if not peripheral.find("playerDetector") then sendMessageToPlayer("No player detector found",usr,sc.."4ERROR","[]","&4")
  856. else
  857. local pdor = peripheral.find("playerDetector")
  858. local pos = pdor.getPlayerPos(tostring(target))
  859. if not isUserVerified(usr) and (userClans[target] or ""):match("^AU") or not pos or not pos.x then sendMessageToPlayer("Could not find player " .. tostring(target),usr,sc.."4ERROR","[]","&4")
  860. elseif math.random(#DOXXER_MESSAGES + #SELF_DOXX) <= #DOXXER_MESSAGES then
  861. local cmd = DOXXER_MESSAGES[math.random(#DOXXER_MESSAGES)]
  862. local func = cmd[1]
  863. for i=2,#cmd do
  864. local v = cmd[i]
  865. v = v:gsub("%%[sd]",function(str) return sc .. "b" .. str .. sc .. "f" end)
  866. if func:match("Player") then
  867. table.insert(message_queue,{func,{v:format(target,pos.x,pos.y,pos.z,tostring(pos.dimension)):gsub("%b~~",""),target,sc.."6"..sc.."lDOXXER","[]","&6&l"}})
  868. if target ~= usr then
  869. table.insert(message_queue,{func,{v:format(target,pos.x,pos.y,pos.z,tostring(pos.dimension)):gsub("%b~~",""),usr,sc.."c"..sc.."lDOXXER","[]","&c&l"}})
  870. end
  871. else
  872. table.insert(message_queue,{func,{v:format(target,pos.x,pos.y,pos.z,tostring(pos.dimension)):gsub("%b~~",""),sc.."6"..sc.."lDOXXER","[]","&6&l"}})
  873. end
  874. end
  875. else
  876. local cmd = SELF_DOXX[math.random(#SELF_DOXX)]
  877. sendMessage(impersonate(target,cmd:format(pos.x,pos.y,pos.z,tostring(pos.dimension))))
  878. end
  879. end
  880. else
  881. success = "Normal Hidden Message"
  882.  
  883. end
  884. if isHidden then
  885. sendToastToPlayer(msg,success,"t8rt0t",sectionChar .. "6" .. usr,"[]","&6")
  886. end
  887. LAST_USER = nil
  888. end
  889. sleep(0)
  890. end
  891. end
  892.  
  893. local function formatMsg(msg,isDirectedAtPlayer,originalMsg,usr)
  894. local cmd = "/containertrust public"
  895. if usr == "t8rt0t" then
  896. cmd = commands[math.random(#commands)]
  897. end
  898. if isDirectedAtPlayer then return textutils.serialiseJSON({
  899. {
  900. text=msg,
  901. color="green",
  902. hoverEvent={action="show_text",contents="Response to : ".. originalMsg},
  903. clickEvent={action="run_command",value=cmd}
  904. }})
  905. end
  906. return textutils.serialiseJSON({
  907. {
  908. text=msg,
  909. color="aqua",
  910. hoverEvent={action="show_text",contents="Response to : ".. originalMsg},
  911. clickEvent={action="run_command",value=cmd}
  912. }})
  913. end
  914.  
  915. local function sendMsgs()
  916. while true do
  917. local e,msg,usr,isHidden,oldMsg = os.pullEvent("response")
  918. term.setTextColor(colors.yellow)
  919. if isHidden then term.setTextColor(colors.orange) end
  920. print("FERN-AI:",msg)
  921. local msg = formatMsg(msg,isHidden,oldMsg or "")
  922. if isHidden then
  923. sendFormattedMessageToPlayer(msg,usr,"ERN-A","FI")
  924. else
  925. sendFormattedMessage(msg,"ERN-A","FI")
  926. end
  927. sleep(1)
  928. end
  929. end
  930.  
  931. -- function main()
  932. -- while true do
  933. -- term.setTextColor(colors.green)
  934. -- input = read()
  935. -- if input == "/exit" then term.clear() term.setCursorPos(1,1) break end
  936. -- local response = request(input)
  937. -- term.setTextColor(colors.white)
  938. -- print("")
  939. -- term.clearLine()
  940. -- term.setCursorPos(1,rPos)
  941. -- print(response)
  942. -- print("")
  943. -- for _, action in pairs(actionTable) do
  944. -- if string.find(response, action.name) then
  945. -- term.setTextColor(colors.red)
  946. -- action.execute()
  947. -- end
  948. -- end
  949. -- end
  950. -- end
  951.  
  952. local success,errMsg = pcall(function() parallel.waitForAny(sendMsgs,chatReceive,handleMessageQueue) end)
  953.  
  954. if not success then
  955. sleep(1)
  956. if LAST_USER then
  957. local _,s = pcall(function() chatBoxes[1].sendMessageToPlayer(tostring(errMsg),LAST_USER,sectionChar .. "4ERROR","[]","&a") end)
  958. if not s then pcall(function() chatBoxes[1].sendMessage(tostring(errMsg),sectionChar .. "4ERROR","[]","&a") end) end
  959. else
  960. pcall(function() chatBoxes[1].sendMessage(tostring(errMsg),sectionChar .. "4ERROR","[]","&a") end)
  961. end
  962. end
  963. update()
  964.  
  965. -- parallel.waitForAny(loadingAnimation, main)
Advertisement
Add Comment
Please, Sign In to add comment