READ THE RULES
0 Members and 1 Guest are viewing this topic.
--Server Board 1.03 10/20/04 LUA 5--converted to LUA 5 - 09/15/05--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---- +Changes from v 1.00-- +Added case sensitive commands, request by NeoUltimicia-- +Added date/time to message, request by NeoUltimicia-- +Errors now sent to PM as well as main-- +Corrected save string and tweaked table read-- +Changes from v 1.01-- +converted to LUA 5 - by blackwings-- +these prefixes can be used = !+?$# - by blackwings-- +Changes from v 1.02-- +fixed a load file bug - by blackwings-- +Changes from v 1.03-- +fixed file handling bug-- +fixed left over lua4 parts-- -removed VaildCmd stuff-- +changed MsgBoard function to ToArrival-- +fixed Prefix error-- +added auto detect if bot has hubbotname-- +fixed some minor bugs-- +added support for mainchat-- +fixed extra linespacing-- ^ Moded by Madman ^-- ?To Do-- ?Allow users to delete their own messages-- ?Add context menu----User Settings-------------------------------------------------------------------------------------Comm1 = string.lower("servers") -- Script Command, read boardComm2 = string.lower("addserver") -- Script Command, write to boardComm3 = string.lower("delserver") -- Script Command, delete messagesMaxMessages = 50 -- Max number of messages to cacheMsgBoardFile = "ServerBoard.txt" -- Message file, creat this file in your scripts dir.rprofiles = {[0]=1,[1]=1,[2]=1,[3]=1,[-1]=1} -- Which profiles may read the board?wprofiles = {[0]=1,[1]=1,[2]=1,[3]=1,[-1]=1} -- Which profiles may write to the board?dprofiles = {[0]=1,[1]=1,[2]=1,[3]=1,[-1]=1} -- Which profiles may delete messages?Hub = frmHub:GetHubName() -- Hub name, pulled from the PxBot = frmHub:GetHubBotName() -- Botname, use frmHub:GetHubBotName() or "BotName"--End User Settings----------------------------------------------------------------------------------BoardMessages = {}function Main() LoadFromFile(MsgBoardFile) if not (Bot == frmHub:GetHubBotName()) then frmHub:RegBot(Bot) endendfunction ToArrival(user,data) local s,e,whoTo = string.find(data, "%$To:%s(%S+)") if whoTo == Bot then return MsgBoard(user, data) endendfunction ChatArrival(user, data) return MsgBoard(user, data)endfunction MsgBoard(user, data) local data = string.sub(data,1, -2) local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?%$%#](%S+)") if cmd then s,e,Prefix = string.find(data, "%b<>%s+(%p)%S+") local tCmds = { [Comm1] = function(user, data) if rprofiles[user.iProfile]==1 then ReadBoard(user) end end, [Comm2] = function(user, data) if wprofiles[user.iProfile]==1 then local s,e,msg = string.find(data, "%b<>%s+%S+%s(.*)") if msg == nil then local dsp dsp = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp = dsp.."\t"..Hub.."\tMessage Board\r\n" dsp = dsp.."\tDid you forget what you were going to say?\r\n" dsp = dsp.."\tCommand syntax is ->> "..Prefix..Comm2.." <your message>\r\n" dsp = dsp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" user:SendData(Bot,dsp) SendPmToNick(user.sName,Bot,dsp) return 1 else Write2Board(user, msg) end end end, [Comm3] = function(user, data) if dprofiles[user.iProfile]==1 then local s,e,delmsg = string.find(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.." <msg #>\r\n" dsp0 = dsp0.."\tType ->> "..Prefix..Comm1.." to list messages \r\n" dsp0 = dsp0.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" user:SendData(Bot,dsp0) SendPmToNick(user.sName,Bot,dsp0) return 1 else --if BoardMessages[delmsg] ~= 1 then user:SendData(Bot,dsp0) return 1 end table.remove(BoardMessages, delmsg) SaveToFile(MsgBoardFile , BoardMessages , "BoardMessages") user:SendData(Bot,"Server [ "..delmsg.." ] has been deleted.") return 0 end end end, } if tCmds[cmd] then return tCmds[cmd](user, data) end endendfunction ReadBoard(user) local n = table.getn(BoardMessages) local dsp1 dsp1 = "" dsp1 = dsp1.."Servers:-" dsp1 = dsp1.."\n" for i = 1, n do dsp1 = dsp1.."[ "..i.." ]\t"..BoardMessages[i].."\r\n" end SendToAll(Bot, dsp1)endfunction Write2Board(user, msg) local dsp2 dsp2 = "" dsp2 = dsp2.." "..user.sName.."'s Server added." dsp2 = dsp2.."" dsp2 = dsp2.."Type "..Prefix..Comm1.." in main." dsp2 = dsp2.."\t" SendToAll(Bot, dsp2) table.insert(BoardMessages, (""..os.date("%B %d %Y %X ").." [ "..user.sName.."'s ] Server: ")..msg) if table.getn(BoardMessages) > MaxMessages then table.remove(BoardMessages, 1) end SaveToFile(MsgBoardFile , BoardMessages , "BoardMessages") endfunction 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 string.format("[%q]",key) or string.format("[%d]",key); if(type(value) == "table") then sTmp = sTmp..Serialize(value, sKey, sTab.."\t"); else local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value); sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue end sTmp = sTmp..",\n" end sTmp = sTmp..sTab.."}" return sTmpendfunction SaveToFile(file , table , tablename) local handle = io.open(file,"w+") handle:write(Serialize(table, tablename)) handle:flush() handle:close()endfunction LoadFromFile(file) local handle = io.open(file,"r") if (handle ~= nil) then dofile(file) handle:flush() handle:close() endend
--Server Board 1.03 10/20/04 LUA 5--converted to LUA 5 - 09/15/05--by Patrick
Yahoo i said i did not want to take the credits.. and i also apologised for that...so noo need to take this matter more further !!!