Update buddies.lua

This commit is contained in:
Ale32bit 2015-10-30 19:28:14 +01:00
parent b26bdbb608
commit 0cc393e852

View file

@ -24,6 +24,7 @@ local function header(aR, xChar)
end end
users = {} users = {}
if fs.exists("/.sPhone/config/buddies") then if fs.exists("/.sPhone/config/buddies") then
local f = fs.open("/.sPhone/config/buddies", "r") local f = fs.open("/.sPhone/config/buddies", "r")
repeat repeat
@ -48,19 +49,19 @@ local function add()
return return
end end
end end
add = read() addUser = read()
term.setCursorBlink(false) term.setCursorBlink(false)
--local check = http.post("http://sertex.esy.es/check.php","user="..add).readLine() local check = http.post("http://sertex.esy.es/exists.php","user="..addUser).readLine()
--if check == "true" then if check == "true" then
table.insert(users,add) table.insert(users,add)
local f = fs.open("/.sPhone/config/buddies", "a") local f = fs.open("/.sPhone/config/buddies", "a")
f.write(add.."\n") f.write(addUser.."\n")
f.close() f.close()
sPhone.winOk("Added!") sPhone.winOk("Added!")
--else else
--sPhone.winOk("User does", "not exist!") sPhone.winOk("User does", "not exist!")
--end end
end end
local function remove() local function remove()
@ -73,17 +74,21 @@ local function remove()
for i = 1, #users do for i = 1, #users do
print(users[i]) print(users[i])
end end
local _,_,x,y = os.pullEvent("mouse_click") _,_,x,y = os.pullEvent("mouse_click")
if y == 1 and x == w then if y == 1 and x == w then
return return
elseif y ~= 1 then elseif y ~= 1 then
if users[y-1] then userToRemove = users[y-1]
local user = users[y-1] if userToRemove then
if sPhone.yesNo("Remove "..users[y-1].."?",nil,false) then if sPhone.yesNo("Remove "..userToRemove.."?",nil) then
local f = fs.open("/.sPhone/config/buddies", "w") local f = fs.open("/.sPhone/config/buddies", "w")
table.remove(users,users[y-1]) oldUsers = users
for i = 1, #users do users = {}
f.write(users[i].."\n") for i = 1, #oldUsers do
if oldUsers[i] ~= oldUsers[y-1] then
f.writeLine(oldUsers[i])
table.insert(users, oldUsers[i])
end
end end
f.close() f.close()
end end
@ -92,12 +97,15 @@ local function remove()
end end
end end
while true do while true do
local function redraw() local function redraw()
clear() clear()
header(true, "X") header(true, "X")
term.setBackgroundColor(colors.white) term.setBackgroundColor(colors.white)
term.setTextColor(colors.black) term.setTextColor(colors.black)
for i = 1, #users do for i = 1, #users do
print(users[i]) print(users[i])
end end