Hello to all the Guru's,
I have a need, as I am switching from the OLD NMDC to Ptokax 3.3.21 hub, I have ( vb script ) from Gadget ( bullettin board ) which I have used for a long long time. )
I found a LUA script that I think will work simiular but, it gives me an error " [15:10] Syntax [string "--
..."]:23: attempt to call global `strlower' (a nil value) "
the heading part of the script is as follows:)
--Message Board 1.01 10/20/04
--
--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.
-------------------------------------------------
I can provide the entire script if neccessary..
----------
If someone has a script which will provide a global read/write -- authorized message removal/delete which those who are not online/offline can read/write/post would be greatly appreciated...
Thank you in advance...
I have converted the script to lua 5 for you + changed so that several different prefixes can be used with the commands = --Message Board 1.02 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
--
-- ?To Do
-- ?Allow users to delete their own messages
-- ?Add context menu
--
--User Settings-------------------------------------------------------------------------------------
Comm1 = string.lower("read") -- Script Command, read board
Comm2 = string.lower("write") -- Script Command, write to board
Comm3 = string.lower("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()
LoadFromFile(MsgBoard)
--frmHub:RegBot(Bot) -- Uncomment for custom name
local cPrefix = "!+?$#"
frmHub:SetPrefixes(cPrefix)
end
function ToArrival(user,data)
local s,e,whoTo,from,cmd = string.find(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s%$%b<>%s+(%S+).*|")
if whoTo == Bot then
return MsgBoard(user,cmd)
end
end
function MsgBoard(user,cmd)
s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if IfValidCMD(cmd, "Comm1") and rprofiles[user.iProfile]==1 then
ReadBoard(user)
return 1
elseif IfValidCMD(cmd, "Comm2") and wprofiles[user.iProfile]==1 then
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.." \r\n"
dsp = dsp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
user:SendData(Bot,dsp)
SendPmToNick(user.sName,Bot,dsp)
return 1
else
Write2Board(user, msg)
return 1
end
elseif IfValidCMD(cmd, "Comm3") and dprofiles[user.iProfile]==1 then
s,e,delmsg = string.find(data, "%b<>%s+%S+%s(%d+)")
if delmsg == nil or BoardMessages[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)
SendPmToNick(user.sName,Bot,dsp0)
return 1
else
--if BoardMessages[delmsg] ~= 1 then user:SendData(Bot,dsp0) return 1 end
tremove(BoardMessages, delmsg)
SaveToFile(MsgBoard , BoardMessages , "BoardMessages")
user:SendData(Bot,"Message number [ "..delmsg.." ] has been deleted.")
SendPmToNick(user.sName,Bot,"Message number [ "..delmsg.." ] has been deleted.")
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
BoardMessages[i] = gsub(BoardMessages[i],"\n","\r\n\t")
BoardMessages[i] = gsub(BoardMessages[i],"wrote::","wrote::\r\n\t")
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, ("On "..os.date("%B %d %Y %X ").." [ "..user.sName.." ] wrote::")..msg)
if getn(BoardMessages) > MaxMessages then tremove(BoardMessages, 1) end
SaveToFile(MsgBoard , BoardMessages , "BoardMessages")
end
function Serialize(tTable, sTableName, sTab)--Fixed
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"); -- The Bug was here
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.."}\r\n"
return sTmp
end
function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
function LoadFromFile(file)
local sTmp = ""
for line in io.lines(file) do
sTmp = sTmp..line.."\r\n"
end
return sTmp
end
tPrefix = frmHub:GetPrefixes()
function IfValidCMD(sIsCMD, sWhatCMD)
for sIndex in tPrefix do
if sIsCMD == (tPrefix[sIndex]..sWhatCMD) then
return 1
end
end
end
Great script there. Should come in handy.
QuoteOriginally posted by blackwings
I have converted the script to lua 5 for you
WOW... I would have never thought I would get such a quick reply... my thanks....... however, :( I have a small problem..
I get the following error:
"SyntaxC:\Ptokax2scripts\MessageBoardBlkWing.lua:153: bad argument #1 to `lines' (string expected, got function) "
When I restart the scripts.. but when I do a syntax check, no errors are shown.
I am using Ptokax 3.3.21 ,, with no bot, was running Terminator 5, but stopped it to test this script.
Also, The bot ( message board ) does not seem to register in the user list of the client.
I would like it's bot name to be " NewsPaper" as registered in the Client.. I am using "PeerWeb DC++ 3.01 " as the DC client.
MY many many thanks to you for your assistants you have no idea how much I appreciate this effort..
try this = --Message 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
--
-- ?To Do
-- ?Allow users to delete their own messages
-- ?Add context menu
--
--User Settings-------------------------------------------------------------------------------------
Comm1 = string.lower("read") -- Script Command, read board
Comm2 = string.lower("write") -- Script Command, write to board
Comm3 = string.lower("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()
LoadFromFile(MsgBoard)
--frmHub:RegBot(Bot) -- Uncomment for custom name
local cPrefix = "!+?$#"
frmHub:SetPrefixes(cPrefix)
end
function ToArrival(user,data)
local s,e,whoTo,from,cmd = string.find(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s%$%b<>%s+(%S+).*|")
if whoTo == Bot then
return MsgBoard(user,cmd)
end
end
function MsgBoard(user,cmd)
s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if IfValidCMD(cmd, "Comm1") and rprofiles[user.iProfile]==1 then
ReadBoard(user)
return 1
elseif IfValidCMD(cmd, "Comm2") and wprofiles[user.iProfile]==1 then
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.." \r\n"
dsp = dsp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
user:SendData(Bot,dsp)
SendPmToNick(user.sName,Bot,dsp)
return 1
else
Write2Board(user, msg)
return 1
end
elseif IfValidCMD(cmd, "Comm3") and dprofiles[user.iProfile]==1 then
s,e,delmsg = string.find(data, "%b<>%s+%S+%s(%d+)")
if delmsg == nil or BoardMessages[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)
SendPmToNick(user.sName,Bot,dsp0)
return 1
else
--if BoardMessages[delmsg] ~= 1 then user:SendData(Bot,dsp0) return 1 end
tremove(BoardMessages, delmsg)
SaveToFile(MsgBoard , BoardMessages , "BoardMessages")
user:SendData(Bot,"Message number [ "..delmsg.." ] has been deleted.")
SendPmToNick(user.sName,Bot,"Message number [ "..delmsg.." ] has been deleted.")
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
BoardMessages[i] = gsub(BoardMessages[i],"\n","\r\n\t")
BoardMessages[i] = gsub(BoardMessages[i],"wrote::","wrote::\r\n\t")
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, ("On "..os.date("%B %d %Y %X ").." [ "..user.sName.." ] wrote::")..msg)
if getn(BoardMessages) > MaxMessages then tremove(BoardMessages, 1) end
SaveToFile(MsgBoard , BoardMessages , "BoardMessages")
end
function Serialize(tTable, sTableName, sTab)--Fixed
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"); -- The Bug was here
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.."}\r\n"
return sTmp
end
function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
function LoadFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
dofile(file)
handle:flush()
handle:close()
end
end
tPrefix = frmHub:GetPrefixes()
function IfValidCMD(sIsCMD, sWhatCMD)
for sIndex in tPrefix do
if sIsCMD == (tPrefix[sIndex]..sWhatCMD) then
return 1
end
end
end
[15:07] Syntax C:\ptokax0.3.3.21\scripts\msgboard.lua:154: bad argument #1 to `open' (string expected, got function)
kunal, have you created the file MessageBoard.txt in Scripts?
If you have, try to test to change the current LoadFromFile to one of these and see if the bug disappear.
If you find that one of them doesn't give you the bug, post which one it was here.
Code = function LoadFromFile(file)
local handle = io.open(file)
if handle then
dofile(file)
handle:flush()
handle:close()
end
end
function LoadFromFile(file)
local handle = io.open(file,"r")
if handle then
dofile(file)
handle:flush()
handle:close()
end
end
function LoadFromFile(file)
local handle = io.open(file)
if (handle ~= nil) then
dofile(file)
handle:flush()
handle:close()
end
end
tried all three.
but none seems to work
get this error
[16:06] Syntax C:\ptokax0.3.3.21\scripts\msgboard.lua:154: bad argument #1 to `open' (string expected, got function)
--Message 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("read") -- Script Command, read board
Comm2 = string.lower("write") -- Script Command, write to board
Comm3 = string.lower("del") -- Script Command, delete messages
MaxMessages = 50 -- Max number of messages to cache
MsgBoardFile = "MessageBoard.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} -- Which profiles may delete messages?
Hub = frmHub:GetHubName() -- Hub name, pulled from the Px
Bot = 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)
end
end
function ToArrival(user,data)
local s,e,whoTo = string.find(data, "%$To:%s(%S+)")
if whoTo == Bot then
return MsgBoard(user, data)
end
end
function ChatArrival(user, data)
return MsgBoard(user, data)
end
function 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) return 1
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.." \r\n"
dsp = dsp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
user:SendData(Bot,dsp)
SendPmToNick(user.sName,Bot,dsp)
return 1
else
Write2Board(user, msg)
return 1
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.." \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,"Message number [ "..delmsg.." ] has been deleted.")
SendPmToNick(user.sName,Bot,"Message number [ "..delmsg.." ] has been deleted.")
return 1
end
end
end,
}
if tCmds[cmd] then
return tCmds[cmd](user, data)
end
end
end
function ReadBoard(user)
local n = table.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)
table.insert(BoardMessages, ("On "..os.date("%B %d %Y %X ").." [ "..user.sName.." ] wrote: ")..msg)
if table.getn(BoardMessages) > MaxMessages then table.remove(BoardMessages, 1) end
SaveToFile(MsgBoardFile , 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 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 sTmp
end
function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
function LoadFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
dofile(file)
handle:flush()
handle:close()
end
end
Give this a try..
Blackwings
The problem was that you hade
MsgBoard = "MessageBoard.txt"
LoadFromFile(MsgBoard)
function MsgBoard(user,cmd)
madman ur script doesnt give any error but when i try any cmds they dont work
Hello all..
I have loaded the script, and it loads with no syntax error. however:
Either I don't understand how the commands work or they don't... I have tried all the prefix's "! + $ ? # " and nothing..
Yes I have created, prior to loading the script, the file "MessageBoard" in the script folder.. and it remains empty, regardless of the command..
In Main and as a PM I entered the following command/commands..
+write ,,, +Write (etc for each prefix.) and the message what ever it would be.. in and out of " " 's
and still no message is written to the file..
I wish to thank all whom have contributed to this effort of problem resolution.
Thanks again for all of your support.
My above post has been edited...
still the cmds dont work
Script updated...
Now the cmd's should work...
They worked 4 me..
the cmds work in pm but not in main.
QuoteOriginally posted by madman
Script updated...
Now the cmd's should work...
They worked 4 me..
Sorry, Madman, but I must be a blind, deaf moronic idiot.
the Cmd's for some reason do not work for me, either in Main or PM to the MsgBoard in the Userlist.
I do have a file " MessageBoard.txt " in the scripts folder along with the Message board script..
would you mind in giving an example of the commands.?
I PM MsgBoard and key " +write this is a test " enter ... I then key " +write "this is test two"
I then +read
nothing........
I then look at the content of the MessageBoard.Txt and nothing is there.
Any assistance would be greatly appreciated..
thank you
i just type +write test to the bot in pm...
check if there is any other script that blocks the commands some how..
But the del command dont seem to work... tho....
*Edit*
Fixed the del command...
nice work madman :) , I just simply made an conversion and a couple off small things.
But then I noticed the script was generally messed up and I didn't really feel like to rewrite the whole script :P
Its good that you did it anyway ;)
QuoteOriginally posted by blackwings
nice work madman :) , I just simply made an conversion and a couple off small things.
But then I noticed the script was generally messed up and I didn't really feel like to rewrite the whole script :P
Its good that you did it anyway ;)
Hehe... i dont have anything else to do anyway...
the cmds work only in pm not in main.
also the cmds only work for operators.
QuoteOriginally posted by kunal
the cmds work only in pm not in main.
also the cmds only work for operators.
Why in main, pm is only needed. But madman can surely fix it for you ;)
cmds should work for master's,operator's and vip's
use this and both reg and normal users can read the board =
rprofiles = {[0]=1,[1]=1,[2]=1,[3]=1,[-1]=1} -- Which profiles may read the board?
QuoteOriginally posted by kunal
the cmds work only in pm not in main.
also the cmds only work for operators.
Hummm,,,, very interesting,,, but what is the following statements in the script for ?? :
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?
If would seem strange that the orginal author would code for different profiles and yet only one will function.
humm.. not real sure what to do now... Thought that was going to be great to use.. instead, this LUA experience is causing me a bit of wonderment.
OH well...
I wish to thank all, for great effort put into this MsgBoard script. However, just for ops, I have no need.
YOU ALL have a great day/weekend..
QuoteOriginally posted by kunal
the cmds work only in pm not in main.
also the cmds only work for operators.
QuoteOriginally posted by blackwings
cmds should work for master's,operator's and vip's
use this and both reg and normal users can read the board =rprofiles = {[0]=1,[1]=1,[2]=1,[3]=1,[-1]=1} -- Which profiles may read the board?
Not sure I really understand the code you are showing me BlackWings, but I offer the following as an attempt of understanding with questions:
In your string of code, [-1]=1 , what does the -1 indicate and how is that applied to the levels of profiles?
Also, if one was to apply the same code string to the wprofiles and dprofiles, would that provide the ability for all to read, write and delete all?
In Ptokax I see a sequence of Ranks as follows: Master, operator, VIP, REG, Moderator, netfounder.
As there are 6 items, levels, I would say that
- = Master, [1]=Operator, [2]=VIP, [3]=Reg, [4]=Moderator, [5]=netfounder.
However, I do see that only 0,1,2,3 are coded (in an array, however, I don't see where the array is defined) or does it default to the
- =y, as being 1, and so on?
I sure would like a Picture if at all possible, better yet, the MsgBoard script function with all levels, rather than OP only...
Thank again for all the assistance..
0 = master
1 = operator
3 = vip
4 = moderator (not a default ptokax profile)
5 = netfounder (not a default ptokax profile)
-1 = normal/unregisterd users
rprofiles = {[0]=1,[1]=1,[2]=1}
rprofiles is a table, becaue it doesn't start with 1, anyway its should have been shown liks this for easier view =
rprofiles = {
- =1,
[1]=1,
[2]=1
}
- =1 = [index]=value
and why 1 if to allow profile, well its because of this line =
if rprofiles[user.iProfile]==1 then
QuoteOriginally posted by blackwings
0 = master
1 = operator
3 = vip
4 = moderator (not a default ptokax profile)
5 = netfounder (not a default ptokax profile)
-1 = normal/unregisterd users
THANKS... and I mean BIG THANKS...
I see # 2 missing,, you have 0,1,3,4,5,-1 ........
Would it be that # 2 = VIP and # 3 = Reg ??
Youu have shed some light on this issue.. However, as I look in the profiles of Ptokax 3.3.21 I see, already defined, All the above (0,1,2,3,4,5) as established in the Profiles. Of course I have no clue what is or what is not considered a default. Perhaps the author knows. LOL
As I typed the above paragraph, I was thinking on how one might control those who are registered and I see that # 2 has been omitted from your list. I would then say #2 or #3 are REG , VIP or VIP , REG. ????
So, IF -1 then you are a person who has connected, but have not registered but are considered normal.
Therefore anyone not registered, is normal. Which brings a thought, when/how does the -1 become a value ?
Thanks again and sorry for all my questions.. but I gotta..
sorry I meant =
0 = master
1 = operator
2 = vip
3 = reg
4 = moderator (not a default ptokax profile)
5 = netfounder (not a default ptokax profile)
-1 = normal/unregisterd users
4 and 5 isn't default profiles, you must have gotten it from when you upgraded from the old ptokax to
the new one (0.3.3.0 b16.04 and later), or you use robocop.
explaination of rprofiles[user.iProfile]==1 then =
if users profile match with a index in variable rprofiles and has a value that is 1,
then do whatever code that is within the "if" and "end".
you are consider to be a normal user if you have no account in ptokax.
All users that hasn't an account is a normal user = -1.
QuoteOriginally posted by blackwings
QuoteOriginally posted by kunal
the cmds work only in pm not in main.
also the cmds only work for operators.
Why in main, pm is only needed. But madman can surely fix it for you ;)
Yup.. post has been updated..
thank you madman works fine. :))
QuoteOriginally posted by blackwings
explaination of rprofiles[user.iProfile]==1 then =
You have done it again, F A N T A S T I C ... for your explanation in allowing me to have more insight of this stuff.. thanks.
Not real sure that this next question/request, would be proper here or not, but here goes.
"In looking at the script I see, such as (user.iProfile), Data Names (Variables), which are not defined within the script itself" Therefore, I take it that the HUB (Ptokax) has the Data Names (Variables) defined and one could access hub information via those Data Names (variables), which I would now call " API " (Application Program Interface)".
So,, the question is, where would one get the API, Ptokax (protocol, Data Names, variables, etc. ) list/documentation ?? I am not sure I asked the question correctly as I am not sure as to get that infomation which is provided by the Ptokax Hub for scripting or ????
Thanks again for your gracious assistance.. VERY MUCH appreciated..
Have a great day
for ptokax lua api, check =
http://ptxwiki.psycho-chihuahua.net/doku.php
and also check this file in ptokax main folder =
Scripting-Interface.txt
Madman....... BlackWing
I wish to thank you for your skills in working with the MsgBoard script. Between you and BlackWing, you both are performing way beyond the call.. I thank you for that.
Yep,, you are right,, I do have a question.
As of this writing, I have yet to see any results from my exercising the commands to write/read , etc. but I get no syntax errors and Ptokax does load. ( one issue I see, is that I do not get a name for the script in the User Nick list of the client unless I substitute in FrmHub:Regbot (Bot) as FrmHub:Regbot ("PostBox"). and even then via PM or Main Chat, I get no response, nor any thing posted in the file, (messageBoard.txt).
However, states "kunal" it is working. Soooo, I guess my
question is:
Do I need some supporting drivers, *dll, etc, runtime moduals or ??, which are preventing the script to function for me??
I am running Windows 2000 Pro (up to date via Msft), Ptokax 3.3.21 (debug), Terminator V5, (However, I turn Terminator off and on to ensure it is not causing my problem). I have no other scripts running or even installed, excepting those that installed with Ptokax. Oh.. Msft netframework 1.1 is installed.
Thanks again, I appreciate all that has been accomplished and the curve of learning that I have gained from this experience..and I do hope you don't mind in my gleaning knowledge from you both.
have a good day.
QuoteOriginally posted by blackwings
for ptokax lua api, check =
http://ptxwiki.psycho-chihuahua.net/doku.php
and also check this file in ptokax main folder =
Scripting-Interface.txt
W O W !!!!
A reply before I could complete my post to Madman and you.....
Thanks..
To the books I go... :)
QuoteOriginally posted by effgjamis
Madman....... BlackWing
I wish to thank you for your skills in working with the MsgBoard script. Between you and BlackWing, you both are performing way beyond the call.. I thank you for that.
Yep,, you are right,, I do have a question.
As of this writing, I have yet to see any results from my exercising the commands to write/read , etc. but I get no syntax errors and Ptokax does load. ( one issue I see, is that I do not get a name for the script in the User Nick list of the client unless I substitute in FrmHub:Regbot (Bot) as FrmHub:Regbot ("PostBox"). and even then via PM or Main Chat, I get no response, nor any thing posted in the file, (messageBoard.txt).
All you need to do is to change...
Bot = "MsgBoard" to Bot = "PostBox"
and...
is your txt called
Message
Board.txt ? it's important with the small and big letters...
QuoteOriginally posted by effgjamis
However, states "kunal" it is working. Soooo, I guess my
question is:
Do I need some supporting drivers, *dll, etc, runtime moduals or ??, which are preventing the script to function for me??
No...
Thank you for your assistance.. I shall give it a try. (again. LOL )
QuoteOriginally posted by madman
All you need to do is to change...
Bot = "MsgBoard" to Bot = "PostBox"
and...
is your txt called MessageBoard.txt ? it's important with the small and big letters...
I am very sorry, but apparently, I don't know what I am doing, or missing something, not formating the commands correctly, or ? or ? or ?
AS the SCRIPT does NOT work for me.
At least the script I have for NMDC works.
thanks for all your consideration and assistance, going back to the drawing board and make some final decisions about LUA vs VB ...
Copy the script again... and see if it works for you directly.... before you start to config as you like...
QuoteOriginally posted by madman
Copy the script again... and see if it works for you directly.... before you start to config as you like...
Thank you MadMan..
3 times did I copy from the forum the script and the last time I was here, that is prior to now.
I ran it as if out of the box.(Main and PM). same problems, no syntax error, and commands donot seem to work, and nothing is posted, and the script does not indicate that a posting was or not made. No command error ( syntactical or otherwise ).
I had one other script running, Terminator 5, however, not only did I disable it, I removed it from the script area and made sure no instances were available to Ptokax.
I then loaded the message board script .. and still Nothing.
What else can one DO? this is getting quite annoying and ridiculus.
This issue has me scratching up the walls, barking at the wife, and locking up the cat and dog in the garage.. However, I do not have a Cat nor Dog...
I would say 99.5% of the time I do not give up on an issue.. but this issue may just be that other .5% .....
Thanks again for your support
this one works for me
--Message 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
-- ^ Moded by Madman ^
-- ?To Do
-- ?Allow users to delete their own messages
-- ?Add context menu
--
--User Settings-------------------------------------------------------------------------------------
Comm1 = string.lower("read") -- Script Command, read board
Comm2 = string.lower("write") -- Script Command, write to board
Comm3 = string.lower("del") -- Script Command, delete messages
MaxMessages = 50 -- Max number of messages to cache
MsgBoardFile = "MessageBoard.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} -- Which profiles may delete messages?
Hub = frmHub:GetHubName() -- Hub name, pulled from the Px
Bot = 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)
end
end
function ToArrival(user,data)
local s,e,whoTo = string.find(data, "%$To:%s(%S+)")
if whoTo == Bot then
return MsgBoard(user, data)
end
end
function ChatArrival(user, data)
return MsgBoard(user, data)
end
function 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) return 1
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.." \r\n"
dsp = dsp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
user:SendData(Bot,dsp)
SendPmToNick(user.sName,Bot,dsp)
return 1
else
Write2Board(user, msg)
return 1
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.." \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,"Message number [ "..delmsg.." ] has been deleted.")
SendPmToNick(user.sName,Bot,"Message number [ "..delmsg.." ] has been deleted.")
return 1
end
end
end,
}
if tCmds[cmd] then
return tCmds[cmd](user, data)
end
end
end
function ReadBoard(user)
local n = table.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
BoardMessages[i] = string.gsub(BoardMessages[i],"\n","\r\n\t")
BoardMessages[i] = string.gsub(BoardMessages[i],"wrote::","wrote::\r\n\t")
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)
table.insert(BoardMessages, ("On "..os.date("%B %d %Y %X ").." [ "..user.sName.." ] wrote::")..msg)
if table.getn(BoardMessages) > MaxMessages then table.remove(BoardMessages, 1) end
SaveToFile(MsgBoardFile , 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 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 sTmp
end
function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
function LoadFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
dofile(file)
handle:flush()
handle:close()
end
end
and dont forget to create a file MessageBoard.txt in scripts folder.
Kunal....
Quotethis one works for me
code:----------------------------------------------------------------------------------Message Board 1.03 10/20/04 LUA 5
--converted to LUA 5 - 09/15/05
Thank you Kunal,, I will try this one,, as I see some differences..
Will let you know. :)
QuoteOriginally posted by kunal
this one works for me
--Message 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
[/quote]
Hey Kunal...
As you said " it works " yep.. thank you ..
When I ran it out of box ( before any modifications ) I see that the bot name did not appear in the Nick user list ( at least for me ). I then made the following change to your script
[code]
from:
Bot = frmHub:GetHubBotName() -- Botname, use frmHub:GetHubBotName() or "BotName"
to:
Bot = ("NewsBoard") -- frmHub:GetHubBotName() -- Botname, use frmHub:GetHubBotName() or "BotName"
By making this change, the script is now shown in the Nick User list as " NewsBoard"
I have not completely tested the script, for my use, but I am in the process of doing so. I will keep you advised as to any issues that appear..
Thank you so much, as I have not a clue ( yet ) why the other scripts would not function.. Weird...
Ah,, I did find a issue prior to writing this post.
It deals with a compatable issue, (apparently command Prefix's I think).
Not sure about RoboCop or others, but Terminator 5 for sure. If you load Terminator as the last script to run in the scipt section of Ptokax V3.3.21, you will not have an issue. However if you load it first, then the other scripts including the message board, the Message board script does not work.. This is not the case in my test's of the other scripts, as I had completely removed Terminator.
NOW, perhaps this ole man can get down to business of getting the Ptokax hub configured so it may replace, ( Oh YEAH) NMDC hub software..
Thanks goes to you, for giving me your copy, and MY thanks to all the others who contributed their talent to make this happen..
If gratitude was fat, I would have to buy new clothes or go naked.. Naked... NAH, the wife would....Censor'd ...
Upon my test completion, I will advise all, so that this thread can be closed... as a successfull resolution..
all have a good one,
Hello All...
Satus of Message Board..
I have had no problems in writing, reading or deleting the messages... WOW .. whooopie..
However.... :((
There seems to be an alot of extra white space in the message. When I key, in main chat or PM, +read
I have approx 6-10 lines between the written by and the actual text. So if you have 1-2-3 or more posters, you have a gillion lines of white space...well maybe not a gillion, but bucket full, for sure.
Is it possible for any of you to take a peek and see if those extra blank lines (white spaces) be removed.
I thank you in advance..
OH.. the code is what Kunal posted .. It works... :))
found and fixed..
and the only diffrence from mine and kunal...
is the fix i just made..
Thank you MadMan
I will test the white space fix shortly.
Really appreciate your efforts...
have a good one and I will get back here as soon as I can..
Hello ALL
Thank you so much in all of your time, consideration, talent, patience and timely responce to resolution of the problem/problems, modifications etc, to the Message Board Script..
I have tested it, in my feeble way, and I find that it works very well, except it must be loaded prior to Terminator/robocop/xthetic-server else it will not function.
My upmost appreciation goes to Blackwing, Madman, Kunal and last but not least, Mutor the orginal author.
IT WORKS........ Great JOB
Again.. Thanks ......... ( I guess this thread is finished..Whewww! )
I have modified the working script into two separate Scripts, which I call NewsPaper and the other OP_Journal. of which all users can read/write to the NewsPaper and only the OP's can use the OP_Journal.. If anyone would like a copy of them please contact me, here or email..
I thank all .. who have given me assistance.. learned alot from this experience, but still have mountains to climb.
i added a rightclick men? for the script the german version is aviable at follow link
German Version of MessageBoard 1.04 (http://skippy.dyndns.ws/Forum/viewtopic.php?t=51)
--Message 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 ^
-- +Changes from v 1.04
-- +added right click menu it displayed only for user allowed commands
-- touched by skippy84
-- ?To Do
-- ?Allow users to delete their own messages
--
--User Settings-------------------------------------------------------------------------------------
Comm1 = string.lower("read") -- Script Command, read board
Comm2 = string.lower("write") -- Script Command, write to board
Comm3 = string.lower("del") -- Script Command, delete messages
MaxMessages = 50 -- Max number of messages to cache
MsgBoardFile = "MessageBoard.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} -- Which profiles may delete messages?
Hub = frmHub:GetHubName() -- Hub name, pulled from the Px
Bot = 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)
end
end
-------------------------------------------------------------------------------------
--context men?
-------------------------------------------------------------------------------------
function NewUserConnected(user)
if user.bUserCommand then
if rprofiles[user.iProfile]==1 then
user:SendData("$UserCommand 1 3 :MessageBoard:\\read board$<%[mynick]> !"..Comm1.."||")
end
if wprofiles[user.iProfile]==1 then
user:SendData("$UserCommand 1 3 :MessageBoard:\\write to board$<%[mynick]> !"..Comm2.." %[line:Enter the Message:]||")
end
if dprofiles[user.iProfile]==1 then
user:SendData("$UserCommand 1 3 :MessageBoard:\\delete messages$<%[mynick]> !"..Comm3.." %[line:Enter Nr of post to Delete:]||")
end
end
end
OpConnected=NewUserConnected
-------------------------------------------------------------------------------------
--context men? end
-------------------------------------------------------------------------------------
function ToArrival(user,data)
local s,e,whoTo = string.find(data, "%$To:%s(%S+)")
if whoTo == Bot then
return MsgBoard(user, data)
end
end
function ChatArrival(user, data)
return MsgBoard(user, data)
end
function 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) return 1
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.." \r\n"
dsp = dsp.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
user:SendData(Bot,dsp)
SendPmToNick(user.sName,Bot,dsp)
return 1
else
Write2Board(user, msg)
return 1
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.." \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,"Message number [ "..delmsg.." ] has been deleted.")
SendPmToNick(user.sName,Bot,"Message number [ "..delmsg.." ] has been deleted.")
return 1
end
end
end,
}
if tCmds[cmd] then
return tCmds[cmd](user, data)
end
end
end
function ReadBoard(user)
local n = table.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)
table.insert(BoardMessages, ("On "..os.date("%B %d %Y %X ").." [ "..user.sName.." ] wrote: ")..msg)
if table.getn(BoardMessages) > MaxMessages then table.remove(BoardMessages, 1) end
SaveToFile(MsgBoardFile , 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 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 sTmp
end
function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
function LoadFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
dofile(file)
handle:flush()
handle:close()
end
end