-- Guestbook by kepp -- Date 04 / 07 / 26 strBot = "[Gu€stb00k]" strFile = "GuestBook.lst"; tblCom = { ["+addgb"] = function(curUser,strData) local s,e,strMessage = strfind(strData,"%b<>%s+%S+%s+(.*)") if strMessage == "" then curUser:SendData(strBot,"Could you please provide a message.") rc = 1 else tinsert(GB,1,{date(),curUser.sName,strMessage}) WriteFile(GB,"GB",strFile) curUser:SendPM(strBot,"Uploading went well, Thank you.") SendToAll(strBot,curUser.sName.." Posted a message in Guestbook, Please type ( +showgb ) or ( +showgb ) to wiew it.") rc = 1 end end, ["+showgb"] = function(curUser,strData) local s,e,strUser = strfind(strData,"%b<>%s+%S+%s*(%S*)") if strUser == "" then -- Show all for i=1,getn(GB) do local strOutput = "" strOutput = strOutput.."\r\n•-=-=-=-• "..GB[i][1].." •-=-=-=-•\r\n" strOutput = strOutput.."Message By : "..GB[i][2].."\r\n\r\n" strOutput = strOutput.."Message : \r\n" strOutput = strOutput..""..GB[i][3].."\r\n\r\n" curUser:SendPM(strBot,strOutput) rc = 1 rc = 1 end else -- Show users posted ones for i=1,getn(GB) do if strlower(GB[i][2]) == strlower(strUser) then local strOutput = "" strOutput = strOutput.."\r\n•-=-=-=-• "..GB[i][1].." •-=-=-=-•\r\n" strOutput = strOutput.."Message By : "..GB[i][2].."\r\n\r\n" strOutput = strOutput.."Message : \r\n" strOutput = strOutput..""..GB[i][3].."\r\n\r\n" curUser:SendPM(strBot,strOutput) rc = 1 end end end end, ["+delgb"] = function(curUser,strData) if curUser.iProfile == 0 or curUser.iProfile == 1 then local s,e,strDate = strfind(strData,"%b<>%s+%S+%s+(.*)") if strDate == "" then curUser:SendData(strBot,"Please enter the date a post was posted.") rc = 1 else -- Find Date for i = 1,getn(GB) do if GB[i][1] == strDate then tremove(GB,i) WriteFile(GB,"GB",strFile) curUser:SendPM(strBot,"Entry was successfully deleted.") rc = 1 end end end else curUser:SendData(strBOT,"You are not allowed to use this command.") rc = 1 end end, ["+cleargb"] = function(curUser,strData) if curUser.iProfile == 0 or curUser.iProfile == 1 then GB = nil GB = {} collectgarbage() flush() WriteFile(GB,"GB",strFile) SendToAll(strBot,"Guestbook is now deleted and ready for new posts.") rc = 1 else curUser:SendData(strBot,"You are not allowed to use this command.") rc = 1 end end } function Main() frmHub:RegBot(strBot) if ( readfrom(strFile) == nil ) then local handle = openfile(strFile,"w") write(handle,"GB = {\r\n}") closefile(handle) end assert(dofile(strFile),strFile.." Wasen't found.") end function DataArrival(curUser,strData) if ( strsub(strData,1,1) == "<" ) then local strData = strsub(strData,1,-2); local s,e,strCMD = strfind(strData,"^%b<>%s+(%S+)") if s then if tblCom[strCMD] then SendToAll(tblCom[strCMD](curUser,strData)) end end if rc == 1 then return 1 end end end function WriteFile(table, tablename, file) local handle = openfile(file, "w") Serialize(table, tablename, handle) closefile(handle) end function Serialize(tTable, sTableName, hFile, sTab) sTab = sTab or ""; write(hFile, sTab..sTableName.." = {\n" ); for key, value in tTable do local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key); if(type(value) == "table") then Serialize(value, sKey, hFile, sTab.."\t"); else local sValue = (type(value) == "string") and format("%q",value) or tostring(value); write(hFile, sTab.."\t"..sKey.." = "..sValue); end write(hFile, ",\n"); end write(hFile, sTab.."}"); end