-- texter v3.0 by plop -- thx 2 chilla for the faster routine for opening the files -- shows text files from a folder named text. -- doesn't mather what prefix it used. -- if the file excist it shows. -- files can be locked 2 certian levels. Bot = "something" FDFolder = "text" function Main() frmHub:RegBot(Bot) if readfrom(FDFolder.."/textlevels.lua") then dofile(FDFolder.."/textlevels.lua") else textlevels = {} save() end end msg = "\r\n\r\n" msg = msg.."+lock \t- locks the file to the given level numbers\r\n" msg = msg.."+free\t\t\t\t- free's the file again so every level can see them\r\n" msg = msg.."+show \t\t\t- shows which levels can see the file\r\n" msg = msg.."+list\t\t\t\t- shows all avail files\r\n" function DataArrival(user, data) if( strsub(data, 1, 1) == "<" ) then data=strsub(data,1,strlen(data)-1) s,e,cmd = strfind(data,"%b<>%s+%S(%w+)") if readfrom(FDFolder.."/"..cmd..".txt") then if textlevels[(cmd)] then if textlevels[(cmd)][user.iProfile] then showtext(user, cmd) end return 1 else showtext(user, cmd) return 1 end end elseif(strsub(data, 1, 4) == "$To:") then data=strsub(data,1,strlen(data)-1) s,e,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+%S(%w+)") if user.iProfile == 0 then if cmd == "help" then user:SendPM(Bot, msg.."|") elseif cmd == "lock" then s,e,file,args = strfind(data, "%$%b<>%s*%S+%s*(%S+)%s*(.*)") if readfrom(FDFolder.."/"..file..".txt") then if textlevels[(file)] then textlevels[(file)]=nil end textlevels[(file)]={} gsub(strlower(args), "(%S+)", function(number) textlevels[(file)][number]=number end) user:SendPM(Bot, "the file: "..file..".txt can now only be viewed by the levels "..args.."|") save() return 1 else user:SendPM(Bot, "can't lock the file: "..file..".txt as it doesn't excists!|") return 1 end elseif cmd == "free" then s,e,file,args = strfind(data, "%$%b<>%s*%S+%s*(%S+)") if readfrom(FDFolder.."/"..file..".txt") then if textlevels[(file)] then textlevels[(file)]=nil user:SendPM(Bot, "the file: "..file..".txt is now unlocked!") save() return 1 else user:SendPM(Bot, "the file "..file..".txt wasn't locked!|") return 1 end else user:SendPM(Bot, "can't free the file: "..file..".txt as it doesn't excists!|") return 1 end elseif cmd == "show" then s,e,file = strfind(data, "%$%b<>%s*%S+%s*(%S+)") if readfrom(FDFolder.."/"..file..".txt") then if textlevels[(file)] then local tmp = "the file: "..file..".txt can be viewed by the levels:" for a,b in textlevels[(file)] do tmp = tmp.." "..a end user:SendPM(Bot, tmp.."|") return 1 else user:SendPM(Bot, "the file "..file..".txt isn't locked!|") return 1 end else user:SendPM(Bot, "the file: "..file..".txt doesn't excists!|") return 1 end elseif cmd =="list" then execute("dir "..FDFolder.." > "..FDFolder.."/dirlist.lst") readfrom(FDFolder.."/dirlist.lst") local tmp = "\r\n\r\n" while 1 do local kicks = read() if kicks == nil then break end local s,e,name = strfind(kicks, "%s(%S+)%.txt$") if name then tmp = tmp..name.."\r\n" end end readfrom() remove(FDFolder.."/dirlist.lst") user:SendPM(Bot, tmp.."|") return 1 elseif readfrom(FDFolder.."/"..cmd..".txt") then if textlevels[(cmd)] then if textlevels[(cmd)][user.iProfile] then showtext(user, cmd) end return 1 else showtext(user, cmd) return 1 end end end if readfrom(FDFolder.."/"..cmd..".txt") then if textlevels[(cmd)] then if textlevels[(cmd)][user.iProfile] then showtext(user, cmd) end return 1 else showtext(user, cmd) return 1 end end end end function save() writeto(FDFolder.."/textlevels.lua") write("textlevels={\n") for a,b in textlevels do tmp = "" for c,d in textlevels[a] do if tmp == "" then tmp = tmp.."["..c.."]="..d else tmp = tmp..",".."["..c.."]="..d end end write(" [\""..a.."\"]={"..tmp.."},\n") end write("}") writeto() end function showtext(user, file) local handle = openfile(FDFolder.."/"..file..".txt", "r") local contents = gsub(read(handle, "*a"),strchar(10), "\r\n") closefile (handle) user:SendPM(Bot, "\r\n"..contents.."\r\n|") end function showtextold(user, cmd) lines = "\r\n\r\n" readfrom("text/"..cmd..".txt") while 1 do local line = read() if line == nil then readfrom() break end lines = lines..line.."\r\n" end user:SendPM(Bot, lines.." |") end