-- --Message Board 1.0 -- --by Mutor -- -- Provides common message board. Allow users to read/write the board by profiles -- Option to delete messages, permission bt profile -- Caches board messages to exteernal text file for script/hub restarts -- Purges oldest message after MaxMessages reached -- --User Settings------------------------------------------------------------------------------------- Prefix = "+" -- Command Prefix Comm1 = "read" -- Script Command, read board Comm2 = "write" -- Script Command, write to board Comm3 = "del" -- Script Command, delete messages MaxMessages = 50 -- Max number of messages to cache MsgBoard = "MessageBoard.txt" -- Message file, creat this file in your scripts dir. rprofiles = {[0]=1,[1]=1,[2]=1} -- Which profiles may read the board? wprofiles = {[0]=1,[1]=1,[2]=1} -- Which profiles may write to the board? dprofiles = {[0]=1,[1]=1,[2]=1} -- Which profiles may delete messages? Hub = frmHub:GetHubName() -- Hub name, pulled from the Px Bot = frmHub:GetHubBotName() -- Uncomment frmHub:RegBot(Bot)in function Main for custom name --End User Settings---------------------------------------------------------------------------------- BoardMessages = {} function Main() --dofile(MsgBoard) LoadFromFile(MsgBoard) frmHub:EnableFullData(1) --frmHub:RegBot(Bot) -- Uncomment for custom name end function DataArrival(user, data) local data = strsub(data,1,-2) if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(Bot)) == "$To: "..Bot) then s,e,cmd = strfind(data, "%b<>%s+(%S+)") if (cmd==Prefix..Comm1) and rprofiles[user.iProfile]==1 then ReadBoard(user) elseif(cmd==Prefix..Comm2) and wprofiles[user.iProfile]==1 then s,e,msg = strfind(data, "%b<>%s+%S+%s(.*)") if msg == nil then local dsp0 dsp0 = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp0 = dsp0.."\t"..Hub.."\tMessage Board\r\n" dsp0 = dsp0.."\tDid you forget what you were going to say?\r\n" dsp0 = dsp0.."\tCommand syntax is ->> "..Prefix..Comm2.." \r\n" dsp0 = dsp0.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" user:SendData(Bot,dsp0) return 1 else Write2Board(user, msg) return 1 end elseif(cmd==Prefix..Comm3) and dprofiles[user.iProfile]==1 then s,e,delmsg = strfind(data, "%b<>%s+%S+%s(%d+)") if delmsg == nil then local dsp0 dsp0 = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp0 = dsp0.."\t"..Hub.."\tMessage Board\r\n" dsp0 = dsp0.."\tDelete which message? Provide message number\r\n" dsp0 = dsp0.."\tCommand syntax is ->> "..Prefix..Comm3.." \r\n" dsp0 = dsp0.."\tType ->> "..Prefix..Comm1.." to list messages \r\n" dsp0 = dsp0.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" user:SendData(Bot,dsp0) return 1 else tremove(BoardMessages, delmsg) SaveToFile(MsgBoard , BoardMessages , "BoardMessages") user:SendData(Bot,"Message number [ "..delmsg.." ] has been deleted.") return 1 end else user:SendData(Bot, "Your not allowed this command!") return 1 end end end function ReadBoard(user) local n = getn(BoardMessages) local dsp1 dsp1 = "\r\n=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp1 = dsp1.." "..Hub.."\tMessage Board\t Displayng last [ "..n.." ] message(s)\r\n" dsp1 = dsp1.."=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n\r\n" for i = 1, n do dsp1 = dsp1.."\r\n[ "..i.." ]\t"..BoardMessages[i].."\r\n\r\n" end SendPmToNick(user.sName, Bot, dsp1) end function Write2Board(user, msg) local dsp2 dsp2 = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp2 = dsp2.."\t[ "..user.sName.." ] just posted to the "..Hub.." Message Board\r\n" dsp2 = dsp2.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp2 = dsp2.."\ttype "..Prefix..Comm1.." in main/pm to list or "..Prefix..Comm2.." to post .\r\n" dsp2 = dsp2.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n\r\n" SendToAll(Bot, dsp2) tinsert(BoardMessages, (user.sName.." ...Wrote: \r\n ")..msg) if getn(BoardMessages) > MaxMessages then tremove(BoardMessages, 1) end SaveToFile(MsgBoard , BoardMessages , "BoardMessages") end function Serialize(tTable, sTableName, sTab) assert(tTable, "tTable equals nil"); assert(sTableName, "sTableName equals nil"); assert(type(tTable) == "table", "tTable must be a table!"); assert(type(sTableName) == "string", "sTableName must be a string!"); sTab = sTab or ""; sTmp = "" sTmp = sTmp..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 sTmp = sTmp..Serialize(value, sKey, sTab.."\t"); else local sValue = (type(value) == "string") and format("%q",value) or tostring(value); sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue end sTmp = sTmp..",\n" end sTmp = sTmp..sTab.."}" return sTmp end function SaveToFile(file , table , tablename) writeto(file) write(Serialize(table, tablename)) writeto() end function LoadFromFile(file) if (readfrom(file) ~= nil) then readfrom(file) dostring(read("*all")) readfrom() end end