Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("sha256.lua")
- local chatBox = peripheral.find("chat_box")
- local name = "\167l\1672KristList"
- local prefixColor = "\1670"
- local lines = {}
- local function countLines()
- local file = fs.open("posts","r")
- if file then
- lines = {}
- local line = file.readLine()
- while line do
- table.insert(lines,line)
- line = file.readLine()
- end
- file.close()
- end
- end
- while true do
- local event, user, command, args = os.pullEvent("command")
- if command == "kristlist" then
- countLines()
- if args[1] == "post" then
- table.remove(args,1)
- local message = table.concat(args, " ")
- local file = fs.open("posts","a")
- file.writeLine(user..": "..message)
- file.close()
- elseif args[1] == "read" then
- if args[2] == nil then
- chatBox.tell(user,"\167rInsufficient arguments, \1674\\kristlist help <command> \167r for more information on how to use kristlist",name,prefixColor)
- elseif tonumber(args[2]) > 0 and tonumber(args[2]) <= #lines then
- local file = fs.open("posts","r")
- for i = 1, args[2] do
- chatBox.tell(user,"\167r"..file.readLine(),name,prefixColor)
- end
- end
- elseif args[1] == "register" then
- if args[2] == nil then
- chatBox.tell(user,"\167Please provide a password to register. NOTE: Your passwords are not stored in plaintext.",name,prefixColor)
- else
- local file = fs.open("users","a")
- local input = tostring(args[2])
- local hashedPassword = sha256.hash(input)
- local salt = math.random(1,1000)
- local password = hashedPassword..salt
- local newUser =file.writeLine(user.." : "..password)
- file.close()
- end
- elseif args[1] == "help" then
- if args[2] == nil then
- chatBox.tell(user,"167rThe following arguments are accepted: \1674\kstlist post, \kstlist read",name,prefixColor)
- end
- elseif args[1] == nil then
- chatBox.tell(user,"\167rInsufficient arguments, \1674\\kristlist help <command> \167r for more information on how to use kristlist",name,prefixColor)
- else
- chatBox.tell(user,"\167rInvalid argument, \1674\\kristlist help <command> \167r for more information on how to use kristlist",name,prefixColor)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement