PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: bastya_elvtars on 06 September, 2004, 09:25:01

Title: PostMan by bastya_elvtars (the rock n' roll doctor)
Post by: bastya_elvtars on 06 September, 2004, 09:25:01
Just another offline messaging bot, it was a GREAT way to learn serializing tables, and play with gsub. Enjoy!

-- PostMan Bot 0.1 by bastya_elvtars (the rock n' roll doctor)
-- offline message system
-- you can set the inbox size and the bot name
-- code ripped from law maker bot
-- comands can be PMed or typed in main, the bot responds to them according to the environment (sometimes at least :D)
-- the commands are case insensitive, the parameters aren't :)
-- 0.2: added function so ppl cannot post 2 online users

------------- settings

Bot="PostMan" -- he he he

inboxsize=10 -- the maximum amount of messages users can have in their inbox

------------ end of settings

function Main()
if not readfrom("offline.ini") then message={} else dofile("offline.ini") end
frmHub:RegBot(Bot)
end

function loadlist(file) -- to see if the user was in the hub at all
table=nil
table={}
readfrom(file)
while 1 do
local line = read()
if line == nil then
readfrom()
break
end
table[line] = 1
end
readfrom()
if table then
return table
else
return {}
end
end

function savefile(table,file) -- save users names who were in the hub
writeto(file)
for a,b in table do
write(a.."\n")
end
writeto()
end

function postmsg(user,data,env)
local _,_,nick,msg=strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if nick then
if not GetItemByName[nick] then
local washere=loadlist("washere.lst")
if not washere then washere={} end
if washere[nick] then
if not message[nick] then
message[nick]={[1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}}
user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
savemsg()
else
if checksize(nick)>=inboxsize then -- >= only for safety lol
user:SendData(parseenv(user,env,Bot).."Sorry, but "..nick.." has a full inbox. Try again later.")
else
message[nick][checksize(nick)+1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}
user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
savemsg()
end
end
else
user:SendData(parseenv(user,env,Bot).."User "..nick.." has never been in the hub.")
end
else
user:SendData(parseenv(user,env,Bot)..nick.." is online! PM would be simpler in this case...")
end
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !postmsg ")
end
end

function readmsg (user,data,env)
if message[user.sName] then
local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
if args then
gsub(args,"(%d+)",function(nmbr)
nmbr=tonumber(nmbr)
if message[%user.sName][nmbr] then
local msg="\r\n\r\n\t\t\t\t\t\t\tMessage #"..nmbr.."\r\n=================================================================================================================================\r\n\r\nFrom: "..message[%user.sName][nmbr]["who"].."\r\nTime of sending: "..message[%user.sName][nmbr]["when"]..
"\r\nMessage: "..message[%user.sName][nmbr]["message"].."\r\n\r\n================================================================================================================================="
%user:SendPM(Bot,msg)
if message[%user.sName][nmbr]["read"]==0 then
message[%user.sName][nmbr]["read"]=1
savemsg()
end
else
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
end
end)
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !showmsg . Multiple numbers can be added separated by spaces.")
end
else
user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
end
end

function numess(nick,a)
if message[nick][a]["read"]==0 then return "no"
else return "yes" end
end

function inbox (user,env)
local msg="\r\n\r\n\t\t\t\t\t\t\tHere is your inbox:\r\n================================================================================================================================="..
"\r\nMessage #\t\t\tSender\t\t\t\t\tTime of sending\t\t\t\t\tRead\r\n================================================================================================================================="
if message[user.sName] then
for a,b in message[user.sName] do
msg=msg.."\r\n"..a.."\t\t\t\t"..b["who"].."\t\t\t"..b["when"].."\t\t\t\t"..numess(user.sName,a).."\r\n================================================================================================================================="
end
user:SendPM(Bot,msg)
user:SendPM(Bot,"Type !readmsg too see an individual message. Multiple numbers can be added separated by spaces.")
if checksize(user.sName) >= inboxsize then
user:SendPM(Bot,"Alert: Your inbox is full!")
end
else
user:SendData(parseenv(user,env,Bot).."You have no messages.")
end
end

function checksize(nick)
local array={}
for a,b in message[nick] do
tinsert(array,a)
end
return getn(array)
end

function delmsg(user,data,env)
if message[user.sName] then
local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
if args then
gsub(args,"(%d+)",function (nmbr)
nmbr=tonumber(nmbr)
if message[%user.sName][nmbr] then
message[%user.sName][nmbr]=nil
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." has been successfully deleted!")
else
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
end
end)
if checksize(user.sName)==0 then
message[user.sName]=nil
savemsg()
else
local array={}
for a,b in message[user.sName] do
tinsert(array,b)
end
for i=1,getn(array) do
message[user.sName]=resort(array)
end
savemsg()
end
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !delmsg . Multiple numbers can be added separated by spaces.")
end
else
user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
end
end

function resort(array)
local tbl={}
for i=1,getn(array) do
tbl[i]=array[i]
end
return tbl
end
-- nmbr, who, when, message
function parse(tbl)
local cnt=""
for a,b in tbl do
cnt=cnt.."\t\t\t\t\t\t\t\t\t["..a.."]=\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t[\"who\"]=\""..b["who"].."\",\n\t\t\t\t\t\t\t\t\t[\"when\"]=\""..b["when"]..
"\",\n\t\t\t\t\t\t\t\t\t[\"message\"]=\""..b["message"].."\",\n\t\t\t\t\t\t\t\t\t},\n"
end
return cnt
end

function savemsg()
writeto("offline.ini")
local what="message=\n{"
for a,b in message do
what=what.."\n\t\t\t[\""..a.."\"]={\n"..parse(b).."\t\t\t},"
end
what=what.."\n}"
write(what)
writeto()
end

function parseenv(user,env,bot)
if env=="PM" then
return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> "
elseif env=="MAIN" then
return "<"..bot.."> "
end
end

function NewUserConnected(user)
local washere=loadlist("washere.lst")
if not washere then washere={} end
if not washere[user.sName] then
washere[user.sName]=1
savefile(washere,"washere.lst")
end
if message[user.sName] then
local count={[user.sName]=0}
for a,b in message[user.sName] do
if b["read"]==0 then
count[user.sName]=count[user.sName]+1
end
end
if count[user.sName]>0 then
user:SendPM(Bot,"You have "..count[user.sName].." new messages. Type !inbox to see your inbox!")
end
end
end

function DataArrival(user,data)
if strsub(data,1,1)=="<" then
data=strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind(data,"%b<>%s+(%S+)")
cmd=strlower(cmd)
return parsecmds(user,data,cmd,"MAIN")
elseif strsub(data, 1, 4) == "$To:" then
data=strsub(data,1,strlen(data)-1)
local _,_,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == Bot) then
local _,_,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
cmd=strlower(cmd)
return parsecmds(user,data,cmd,"PM")
end
end
end

function parsecmds(user,data,cmd,env)
local returndata=0
if cmd=="!postmsg" then
postmsg(user,data,env) returndata=1
elseif cmd=="!readmsg" then
readmsg (user,data,env) returndata=1
elseif cmd=="!inbox" then
inbox(user,env) returndata=1
elseif cmd=="!delmsg" then
delmsg(user,data, env) returndata=1
end return returndata
end

function UserDisconnected(user)
local washere=loadlist("washere.lst")
if not washere then washere={} end
if not washere[user.sName] then
washere[user.sName]=1
savefile(washere,"washere.lst")
end
end

function OnExit()
savemsg()
end

OpDisconnected=UserDisconnected
OpConnected=NewUserConnected
Title:
Post by: REBEL on 06 September, 2004, 10:48:44
Hi bastya_elvtars
looks quite good bot , so i decided to try it.
but im getting this syntax error

Syntax Error: function arguments expected;
  last token read: `=' at line 11 in string "code:----------------------------------------------------------..."

i set the bot to suit my hub,so here is what ive done

code:---------------------------------------------------------------------------------- PostMan Bot 0.1 by bastya_elvtars (the rock n' roll doctor)
-- offline message system
-- you can set the inbox size and the bot name
-- code ripped from law maker bot
-- comands can be PMed or typed in main, the bot responds to them according to the environment (sometimes at least :D)
-- the commands are case insensitive, the parameters aren't :)
-- 0.2: added function so ppl cannot post 2 online users

------------- settings

Bot="=Pony_Express="

inboxsize=10 -- the maximum amount of messages users can have in their inbox

------------ end of settings

function Main()
   if not readfrom("offline.ini") then message={} else dofile("offline.ini") end
   frmHub:RegBot(Bot)
end

function loadlist(file) -- to see if the user was in the hub at all
   table=nil
   table={}
   readfrom(file)
   while 1 do
      local line = read()
      if line == nil then
         readfrom()
         break
      end
      table[line] = 1
   end
   readfrom()
   if table then
      return table
   else
      return {}
   end
end

function savefile(table,file) -- save users names who were in the hub
writeto(file)
   for a,b in table do
      write(a.."\n")
   end
writeto()
end

function postmsg(user,data,env)
   local _,_,nick,msg=strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
   if nick then
      if not GetItemByName[nick] then
         local washere=loadlist("washere.lst")
         if not washere then washere={} end
         if washere[nick] then
            if not message[nick] then
               message[nick]={[1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}}
               user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
               savemsg()
            else
               if checksize(nick)>=inboxsize then -- >= only for safety lol
                  user:SendData(parseenv(user,env,Bot).."Sorry, but "..nick.." has a full inbox. Try again later.")
               else
                  message[nick][checksize(nick)+1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}
                  user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
                  savemsg()
               end
            end
         else
            user:SendData(parseenv(user,env,Bot).."User "..nick.." has never been in the hub.")
         end
      else
         user:SendData(parseenv(user,env,Bot)..nick.." is online! PM would be simpler in this case...")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !postmsg ")
   end
end

function readmsg (user,data,env)
   if message[user.sName] then
      local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
      if args then
         gsub(args,"(%d+)",function(nmbr)
                        nmbr=tonumber(nmbr)
                        if message[%user.sName][nmbr] then
                           local msg="\r\n\r\n\t\t\t\t\t\t\tMessage #"..nmbr..& quot;\r\n==================================================================
 ===============================================================\r\n\r\nFrom
: "..message[%user.sName][nmbr]["who"].."\r\nTime of sending: "..message[%user.sName][nmbr]["when"]..
                           "\r\nMessage: "..message[%user.sName][nmbr]["message"]..& quot;\r\n\r\n==============================================================
==================================================================="
                           %user:SendPM(Bot,msg)
                           if message[%user.sName][nmbr]["read"]==0 then
                              message[%user.sName][nmbr]["read"]=1
                              savemsg()
                           end
                        else
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
                        end
                     end)
      else
         user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !showmsg . Multiple numbers can be added separated by spaces.")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
   end
end

function numess(nick,a)
   if message[nick][a]["read"]==0 then return "no"
   else return "yes" end
end

function inbox (user,env)
   local msg="\r\n\r\n\t\t\t\t\t\t\tHere is your  inbox:\r\n=================================================================
================================================================"..
            "\r\nMessage #\t\t\tSender\t\t\t\t\tTime of  sending\t\t\t\t\tRead\r\n==================================================
 ===========================================================================
===="
   if message[user.sName] then
      for a,b in message[user.sName] do
         msg=msg.."\r\n"..a.."\t\t\t\t"..b["who"].."\t\t\t"..b["when"].."\t\t\t\t"..numess(user.sName,a)..& quot;\r\n==================================================================
==============================================================="
      end
      user:SendPM(Bot,msg)
      user:SendPM(Bot,"Type !readmsg too see an individual message. Multiple numbers can be added separated by spaces.")
      if checksize(user.sName) >= inboxsize then
         user:SendPM(Bot,"Alert: Your inbox is full!")
      end
   else
      user:SendData(parseenv(user,env,Bot).."You have no messages.")
   end
end

function checksize(nick)
   local array={}
   for a,b in message[nick] do
      tinsert(array,a)
   end
   return getn(array)
end

function delmsg(user,data,env)
   if message[user.sName] then
      local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
      if args then
         gsub(args,"(%d+)",function (nmbr)
                        nmbr=tonumber(nmbr)
                        if message[%user.sName][nmbr] then
                           message[%user.sName][nmbr]=nil
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." has been successfully deleted!")
                        else
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
                        end
                     end)
         if checksize(user.sName)==0 then
            message[user.sName]=nil
            savemsg()
         else
            local array={}
            for a,b in message[user.sName] do
               tinsert(array,b)
            end
            for i=1,getn(array) do
               message[user.sName]=resort(array)
            end
            savemsg()
         end
      else
         user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !delmsg . Multiple numbers can be added separated by spaces.")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
   end
end

function resort(array)
   local tbl={}
   for i=1,getn(array) do
      tbl=array
   end
   return tbl
end
-- nmbr, who, when, message
function parse(tbl)
   local cnt=""
   for a,b in tbl do
      cnt=cnt.."\t\t\t\t\t\t\t\t\t["..a.."]=\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t[\"who\"]=\""..b["who"].."\",\n\t\t\t\t\t\t\t\t\t[\"when\"]=\""..b["when"]..
      "\",\n\t\t\t\t\t\t\t\t\t[\"message\"]=\""..b["message"].."\",\n\t\t\t\t\t\t\t\t\t},\n"
   end
   return cnt
end

function savemsg()
   writeto("offline.ini")
   local what="message=\n{"
   for a,b in message do
      what=what.."\n\t\t\t[\""..a.."\"]={\n"..parse(b).."\t\t\t},"
   end
   what=what.."\n}"
   write(what)
   writeto()
end

function parseenv(user,env,bot)
   if env=="PM" then
      return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> "
   elseif env=="MAIN" then
      return "<"..bot.."> "
   end
end

function NewUserConnected(user)
   local washere=loadlist("washere.lst")
   if not washere then washere={} end
   if not washere[user.sName] then
      washere[user.sName]=1
      savefile(washere,"washere.lst")
   end
   if message[user.sName] then
      local count={[user.sName]=0}
      for a,b in message[user.sName] do
         if b["read"]==0 then
            count[user.sName]=count[user.sName]+1
         end
      end
      if count[user.sName]>0 then
         user:SendPM(Bot,"You have "..count[user.sName].." new messages. Type !inbox to see your inbox!")
      end
   end
end

function DataArrival(user,data)
   if strsub(data,1,1)=="<" then
      data=strsub(data,1,strlen(data)-1)
         local _,_,cmd = strfind(data,"%b<>%s+(%S+)")
         cmd=strlower(cmd)
         return parsecmds(user,data,cmd,"MAIN")
   elseif strsub(data, 1, 4) == "$To:" then
      data=strsub(data,1,strlen(data)-1)
      local _,_,whoTo = strfind(data,"$To:%s+(%S+)")
      if (whoTo == Bot) then
         local _,_,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
         cmd=strlower(cmd)
         return parsecmds(user,data,cmd,"PM")
      end
   end
end

function parsecmds(user,data,cmd,env)
   local returndata=0
   if cmd=="!postmsg" then
      postmsg(user,data,env) returndata=1
   elseif cmd=="!readmsg" then
      readmsg (user,data,env) returndata=1
   elseif cmd=="!inbox" then
      inbox(user,env) returndata=1
   elseif cmd=="!delmsg" then
      delmsg(user,data, env) returndata=1
   end return returndata
end

function UserDisconnected(user)
   local washere=loadlist("washere.lst")
   if not washere then washere={} end
   if not washere[user.sName] then
      washere[user.sName]=1
      savefile(washere,"washere.lst")
   end
end

function OnExit()
   savemsg()
end

OpDisconnected=UserDisconnected
OpConnected=NewUserConnected--------------------------------------------------------------------------------

hope this helps to find the prob  :)
looking forward to useing it
Title:
Post by: bastya_elvtars on 06 September, 2004, 10:55:03
please send it again using the code function,or disable smilies in your post, cause it stuffs up the scripts, removing every brackets
Title:
Post by: REBEL on 06 September, 2004, 10:59:53
ohhh sorry ....hehehe


code:---------------------------------------------------------------------------------- PostMan Bot 0.1 by bastya_elvtars (the rock n' roll doctor)
-- offline message system
-- you can set the inbox size and the bot name
-- code ripped from law maker bot
-- comands can be PMed or typed in main, the bot responds to them according to the environment (sometimes at least :D)
-- the commands are case insensitive, the parameters aren't :)
-- 0.2: added function so ppl cannot post 2 online users

------------- settings

Bot="=Pony_Express=" -- he he he

inboxsize=10 -- the maximum amount of messages users can have in their inbox

------------ end of settings

function Main()
   if not readfrom("offline.ini") then message={} else dofile("offline.ini") end
   frmHub:RegBot(Bot)
end

function loadlist(file) -- to see if the user was in the hub at all
   table=nil
   table={}
   readfrom(file)
   while 1 do
      local line = read()
      if line == nil then
         readfrom()
         break
      end
      table[line] = 1
   end
   readfrom()
   if table then
      return table
   else
      return {}
   end
end

function savefile(table,file) -- save users names who were in the hub
writeto(file)
   for a,b in table do
      write(a.."\n")
   end
writeto()
end

function postmsg(user,data,env)
   local _,_,nick,msg=strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
   if nick then
      if not GetItemByName[nick] then
         local washere=loadlist("washere.lst")
         if not washere then washere={} end
         if washere[nick] then
            if not message[nick] then
               message[nick]={[1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}}
               user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
               savemsg()
            else
               if checksize(nick)>=inboxsize then -- >= only for safety lol
                  user:SendData(parseenv(user,env,Bot).."Sorry, but "..nick.." has a full inbox. Try again later.")
               else
                  message[nick][checksize(nick)+1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}
                  user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
                  savemsg()
               end
            end
         else
            user:SendData(parseenv(user,env,Bot).."User "..nick.." has never been in the hub.")
         end
      else
         user:SendData(parseenv(user,env,Bot)..nick.." is online! PM would be simpler in this case...")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !postmsg ")
   end
end

function readmsg (user,data,env)
   if message[user.sName] then
      local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
      if args then
         gsub(args,"(%d+)",function(nmbr)
                        nmbr=tonumber(nmbr)
                        if message[%user.sName][nmbr] then
                           local msg="\r\n\r\n\t\t\t\t\t\t\tMessage #"..nmbr..& quot;\r\n==================================================================
 ===============================================================\r\n\r\nFrom
: "..message[%user.sName][nmbr]["who"].."\r\nTime of sending: "..message[%user.sName][nmbr]["when"]..
                           "\r\nMessage: "..message[%user.sName][nmbr]["message"]..& quot;\r\n\r\n==============================================================
==================================================================="
                           %user:SendPM(Bot,msg)
                           if message[%user.sName][nmbr]["read"]==0 then
                              message[%user.sName][nmbr]["read"]=1
                              savemsg()
                           end
                        else
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
                        end
                     end)
      else
         user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !showmsg . Multiple numbers can be added separated by spaces.")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
   end
end

function numess(nick,a)
   if message[nick][a]["read"]==0 then return "no"
   else return "yes" end
end

function inbox (user,env)
   local msg="\r\n\r\n\t\t\t\t\t\t\tHere is your  inbox:\r\n=================================================================
================================================================"..
            "\r\nMessage #\t\t\tSender\t\t\t\t\tTime of  sending\t\t\t\t\tRead\r\n==================================================
 ===========================================================================
===="
   if message[user.sName] then
      for a,b in message[user.sName] do
         msg=msg.."\r\n"..a.."\t\t\t\t"..b["who"].."\t\t\t"..b["when"].."\t\t\t\t"..numess(user.sName,a)..& quot;\r\n==================================================================
==============================================================="
      end
      user:SendPM(Bot,msg)
      user:SendPM(Bot,"Type !readmsg too see an individual message. Multiple numbers can be added separated by spaces.")
      if checksize(user.sName) >= inboxsize then
         user:SendPM(Bot,"Alert: Your inbox is full!")
      end
   else
      user:SendData(parseenv(user,env,Bot).."You have no messages.")
   end
end

function checksize(nick)
   local array={}
   for a,b in message[nick] do
      tinsert(array,a)
   end
   return getn(array)
end

function delmsg(user,data,env)
   if message[user.sName] then
      local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
      if args then
         gsub(args,"(%d+)",function (nmbr)
                        nmbr=tonumber(nmbr)
                        if message[%user.sName][nmbr] then
                           message[%user.sName][nmbr]=nil
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." has been successfully deleted!")
                        else
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
                        end
                     end)
         if checksize(user.sName)==0 then
            message[user.sName]=nil
            savemsg()
         else
            local array={}
            for a,b in message[user.sName] do
               tinsert(array,b)
            end
            for i=1,getn(array) do
               message[user.sName]=resort(array)
            end
            savemsg()
         end
      else
         user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !delmsg . Multiple numbers can be added separated by spaces.")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
   end
end

function resort(array)
   local tbl={}
   for i=1,getn(array) do
      tbl=array
   end
   return tbl
end
-- nmbr, who, when, message
function parse(tbl)
   local cnt=""
   for a,b in tbl do
      cnt=cnt.."\t\t\t\t\t\t\t\t\t["..a.."]=\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t[\"who\"]=\""..b["who"].."\",\n\t\t\t\t\t\t\t\t\t[\"when\"]=\""..b["when"]..
      "\",\n\t\t\t\t\t\t\t\t\t[\"message\"]=\""..b["message"].."\",\n\t\t\t\t\t\t\t\t\t},\n"
   end
   return cnt
end

function savemsg()
   writeto("offline.ini")
   local what="message=\n{"
   for a,b in message do
      what=what.."\n\t\t\t[\""..a.."\"]={\n"..parse(b).."\t\t\t},"
   end
   what=what.."\n}"
   write(what)
   writeto()
end

function parseenv(user,env,bot)
   if env=="PM" then
      return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> "
   elseif env=="MAIN" then
      return "<"..bot.."> "
   end
end

function NewUserConnected(user)
   local washere=loadlist("washere.lst")
   if not washere then washere={} end
   if not washere[user.sName] then
      washere[user.sName]=1
      savefile(washere,"washere.lst")
   end
   if message[user.sName] then
      local count={[user.sName]=0}
      for a,b in message[user.sName] do
         if b["read"]==0 then
            count[user.sName]=count[user.sName]+1
         end
      end
      if count[user.sName]>0 then
         user:SendPM(Bot,"You have "..count[user.sName].." new messages. Type !inbox to see your inbox!")
      end
   end
end

function DataArrival(user,data)
   if strsub(data,1,1)=="<" then
      data=strsub(data,1,strlen(data)-1)
         local _,_,cmd = strfind(data,"%b<>%s+(%S+)")
         cmd=strlower(cmd)
         return parsecmds(user,data,cmd,"MAIN")
   elseif strsub(data, 1, 4) == "$To:" then
      data=strsub(data,1,strlen(data)-1)
      local _,_,whoTo = strfind(data,"$To:%s+(%S+)")
      if (whoTo == Bot) then
         local _,_,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
         cmd=strlower(cmd)
         return parsecmds(user,data,cmd,"PM")
      end
   end
end

function parsecmds(user,data,cmd,env)
   local returndata=0
   if cmd=="!postmsg" then
      postmsg(user,data,env) returndata=1
   elseif cmd=="!readmsg" then
      readmsg (user,data,env) returndata=1
   elseif cmd=="!inbox" then
      inbox(user,env) returndata=1
   elseif cmd=="!delmsg" then
      delmsg(user,data, env) returndata=1
   end return returndata
end

function UserDisconnected(user)
   local washere=loadlist("washere.lst")
   if not washere then washere={} end
   if not washere[user.sName] then
      washere[user.sName]=1
      savefile(washere,"washere.lst")
   end
end

function OnExit()
   savemsg()
end

OpDisconnected=UserDisconnected
OpConnected=NewUserConnected--------------------------------------------------------------------------------



me hope ive got this right now
Title:
Post by: bastya_elvtars on 06 September, 2004, 11:34:40
found no errors in it, you only changed the botname right? then see if its

Bot="=Pony_Express="

this line is the erroneous one...
Title:
Post by: REBEL on 06 September, 2004, 11:41:53
oh ok ....so i cant change bot name ?

not too worry . thanks anyway
Title:
Post by: bastya_elvtars on 06 September, 2004, 11:44:26
no, you can change, the above post was just an example. You can change the name of course, but avoid spaces.
Try again, maybe you have did a bad copy or whatever...
Title:
Post by: REBEL on 06 September, 2004, 13:27:31
yeh did as you suggested

code:---------------------------------------------------------------------------------- PostMan Bot 0.1 by bastya_elvtars (the rock n' roll doctor)
-- offline message system
-- you can set the inbox size and the bot name
-- code ripped from law maker bot
-- comands can be PMed or typed in main, the bot responds to them according to the environment (sometimes at least :D)
-- the commands are case insensitive, the parameters aren't :)
-- 0.2: added function so ppl cannot post 2 online users

------------- settings

Bot="PonyExpress" -- he he he

inboxsize=10 -- the maximum amount of messages users can have in their inbox

------------ end of settings

function Main()
   if not readfrom("offline.ini") then message={} else dofile("offline.ini") end
   frmHub:RegBot(Bot)
end

function loadlist(file) -- to see if the user was in the hub at all
   table=nil
   table={}
   readfrom(file)
   while 1 do
      local line = read()
      if line == nil then
         readfrom()
         break
      end
      table[line] = 1
   end
   readfrom()
   if table then
      return table
   else
      return {}
   end
end

function savefile(table,file) -- save users names who were in the hub
writeto(file)
   for a,b in table do
      write(a.."\n")
   end
writeto()
end

function postmsg(user,data,env)
   local _,_,nick,msg=strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
   if nick then
      if not GetItemByName[nick] then
         local washere=loadlist("washere.lst")
         if not washere then washere={} end
         if washere[nick] then
            if not message[nick] then
               message[nick]={[1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}}
               user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
               savemsg()
            else
               if checksize(nick)>=inboxsize then -- >= only for safety lol
                  user:SendData(parseenv(user,env,Bot).."Sorry, but "..nick.." has a full inbox. Try again later.")
               else
                  message[nick][checksize(nick)+1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}
                  user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
                  savemsg()
               end
            end
         else
            user:SendData(parseenv(user,env,Bot).."User "..nick.." has never been in the hub.")
         end
      else
         user:SendData(parseenv(user,env,Bot)..nick.." is online! PM would be simpler in this case...")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !postmsg ")
   end
end

function readmsg (user,data,env)
   if message[user.sName] then
      local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
      if args then
         gsub(args,"(%d+)",function(nmbr)
                        nmbr=tonumber(nmbr)
                        if message[%user.sName][nmbr] then
                           local msg="\r\n\r\n\t\t\t\t\t\t\tMessage #"..nmbr..& quot;\r\n==================================================================
 ===============================================================\r\n\r\nFrom
: "..message[%user.sName][nmbr]["who"].."\r\nTime of sending: "..message[%user.sName][nmbr]["when"]..
                           "\r\nMessage: "..message[%user.sName][nmbr]["message"]..& quot;\r\n\r\n==============================================================
==================================================================="
                           %user:SendPM(Bot,msg)
                           if message[%user.sName][nmbr]["read"]==0 then
                              message[%user.sName][nmbr]["read"]=1
                              savemsg()
                           end
                        else
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
                        end
                     end)
      else
         user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !showmsg . Multiple numbers can be added separated by spaces.")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
   end
end

function numess(nick,a)
   if message[nick][a]["read"]==0 then return "no"
   else return "yes" end
end

function inbox (user,env)
   local msg="\r\n\r\n\t\t\t\t\t\t\tHere is your  inbox:\r\n=================================================================
================================================================"..
            "\r\nMessage #\t\t\tSender\t\t\t\t\tTime of  sending\t\t\t\t\tRead\r\n==================================================
 ===========================================================================
===="
   if message[user.sName] then
      for a,b in message[user.sName] do
         msg=msg.."\r\n"..a.."\t\t\t\t"..b["who"].."\t\t\t"..b["when"].."\t\t\t\t"..numess(user.sName,a)..& quot;\r\n==================================================================
==============================================================="
      end
      user:SendPM(Bot,msg)
      user:SendPM(Bot,"Type !readmsg too see an individual message. Multiple numbers can be added separated by spaces.")
      if checksize(user.sName) >= inboxsize then
         user:SendPM(Bot,"Alert: Your inbox is full!")
      end
   else
      user:SendData(parseenv(user,env,Bot).."You have no messages.")
   end
end

function checksize(nick)
   local array={}
   for a,b in message[nick] do
      tinsert(array,a)
   end
   return getn(array)
end

function delmsg(user,data,env)
   if message[user.sName] then
      local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
      if args then
         gsub(args,"(%d+)",function (nmbr)
                        nmbr=tonumber(nmbr)
                        if message[%user.sName][nmbr] then
                           message[%user.sName][nmbr]=nil
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." has been successfully deleted!")
                        else
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
                        end
                     end)
         if checksize(user.sName)==0 then
            message[user.sName]=nil
            savemsg()
         else
            local array={}
            for a,b in message[user.sName] do
               tinsert(array,b)
            end
            for i=1,getn(array) do
               message[user.sName]=resort(array)
            end
            savemsg()
         end
      else
         user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !delmsg . Multiple numbers can be added separated by spaces.")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
   end
end

function resort(array)
   local tbl={}
   for i=1,getn(array) do
      tbl=array
   end
   return tbl
end
-- nmbr, who, when, message
function parse(tbl)
   local cnt=""
   for a,b in tbl do
      cnt=cnt.."\t\t\t\t\t\t\t\t\t["..a.."]=\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t[\"who\"]=\""..b["who"].."\",\n\t\t\t\t\t\t\t\t\t[\"when\"]=\""..b["when"]..
      "\",\n\t\t\t\t\t\t\t\t\t[\"message\"]=\""..b["message"].."\",\n\t\t\t\t\t\t\t\t\t},\n"
   end
   return cnt
end

function savemsg()
   writeto("offline.ini")
   local what="message=\n{"
   for a,b in message do
      what=what.."\n\t\t\t[\""..a.."\"]={\n"..parse(b).."\t\t\t},"
   end
   what=what.."\n}"
   write(what)
   writeto()
end

function parseenv(user,env,bot)
   if env=="PM" then
      return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> "
   elseif env=="MAIN" then
      return "<"..bot.."> "
   end
end

function NewUserConnected(user)
   local washere=loadlist("washere.lst")
   if not washere then washere={} end
   if not washere[user.sName] then
      washere[user.sName]=1
      savefile(washere,"washere.lst")
   end
   if message[user.sName] then
      local count={[user.sName]=0}
      for a,b in message[user.sName] do
         if b["read"]==0 then
            count[user.sName]=count[user.sName]+1
         end
      end
      if count[user.sName]>0 then
         user:SendPM(Bot,"You have "..count[user.sName].." new messages. Type !inbox to see your inbox!")
      end
   end
end

function DataArrival(user,data)
   if strsub(data,1,1)=="<" then
      data=strsub(data,1,strlen(data)-1)
         local _,_,cmd = strfind(data,"%b<>%s+(%S+)")
         cmd=strlower(cmd)
         return parsecmds(user,data,cmd,"MAIN")
   elseif strsub(data, 1, 4) == "$To:" then
      data=strsub(data,1,strlen(data)-1)
      local _,_,whoTo = strfind(data,"$To:%s+(%S+)")
      if (whoTo == Bot) then
         local _,_,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
         cmd=strlower(cmd)
         return parsecmds(user,data,cmd,"PM")
      end
   end
end

function parsecmds(user,data,cmd,env)
   local returndata=0
   if cmd=="!postmsg" then
      postmsg(user,data,env) returndata=1
   elseif cmd=="!readmsg" then
      readmsg (user,data,env) returndata=1
   elseif cmd=="!inbox" then
      inbox(user,env) returndata=1
   elseif cmd=="!delmsg" then
      delmsg(user,data, env) returndata=1
   end return returndata
end

function UserDisconnected(user)
   local washere=loadlist("washere.lst")
   if not washere then washere={} end
   if not washere[user.sName] then
      washere[user.sName]=1
      savefile(washere,"washere.lst")
   end
end

function OnExit()
   savemsg()
end

OpDisconnected=UserDisconnected
OpConnected=NewUserConnected--------------------------------------------------------------------------------

still got syntax error

Syntax Error: function arguments expected;
  last token read: `=' at line 11 in string "code:----------------------------------------------------------..."

me confused lol
sorry to be pain
Title:
Post by: bastya_elvtars on 06 September, 2004, 17:42:16
Really found an error. Ok, this is an update
---------------------------------------------------------------------------------- PostMan Bot 0.1 by bastya_elvtars (the rock n' roll doctor)
-- offline message system
-- you can set the inbox size and the bot name
-- code ripped from law maker bot
-- comands can be PMed or typed in main, the bot responds to them according to the environment (sometimes at least :D)
-- the commands are case insensitive, the parameters aren't :)
-- 0.2: added function so ppl cannot post 2 online users
-- 0.3: the above function now works ;)

------------- settings

Bot="PonyExpress" -- he he he

inboxsize=10 -- the maximum amount of messages users can have in their inbox

------------ end of settings

function Main()
if not readfrom("offline.ini") then message={} else dofile("offline.ini") end
frmHub:RegBot(Bot)
end

function loadlist(file) -- to see if the user was in the hub at all
table=nil
table={}
readfrom(file)
while 1 do
local line = read()
if line == nil then
readfrom()
break
end
table[line] = 1
end
readfrom()
if table then
return table
else
return {}
end
end

function savefile(table,file) -- save users names who were in the hub
writeto(file)
for a,b in table do
write(a.."\n")
end
writeto()
end

function postmsg(user,data,env)
local _,_,nick,msg=strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if nick then
if not GetItemByName(nick) then
local washere=loadlist("washere.lst")
if not washere then washere={} end
if washere[nick] then
if not message[nick] then
message[nick]={[1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}}
user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
savemsg()
else
if checksize(nick)>=inboxsize then -- >= only for safety lol
user:SendData(parseenv(user,env,Bot).."Sorry, but "..nick.." has a full inbox. Try again later.")
else
message[nick][checksize(nick)+1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}
user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
savemsg()
end
end
else
user:SendData(parseenv(user,env,Bot).."User "..nick.." has never been in the hub.")
end
else
user:SendData(parseenv(user,env,Bot)..nick.." is online! PM would be simpler in this case...")
end
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !postmsg ")
end
end

function readmsg (user,data,env)
if message[user.sName] then
local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
if args then
gsub(args,"(%d+)",
function(nmbr)
nmbr=tonumber(nmbr)
if message[%user.sName][nmbr] then
local msg="\r\n\r\n\t\t\t\t\t\t\tMessage #"..nmbr.."\r\n=================================================================================================================================\r\n\r\nFrom: "..message[%user.sName][nmbr]["who"].."\r\nTime of sending: "..message[%user.sName][nmbr]["when"].."\r\nMessage: "..message[%user.sName][nmbr]["message"].."\r\n\r\n================================================================================================================================="
%user:SendPM(Bot,msg)
if message[%user.sName][nmbr]["read"]==0 then
message[%user.sName][nmbr]["read"]=1
savemsg()
end
else
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
end
end)
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !showmsg . Multiple numbers can be added separated by spaces.")
end
else
user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
end
end

function numess(nick,a)
if message[nick][a]["read"]==0 then return "no"
else return "yes" end
end

function inbox (user,env)
local msg="\r\n\r\n\t\t\t\t\t\t\tHere is your inbox:\r\n================================================================================================================================="..
"\r\nMessage #\t\t\tSender\t\t\t\t\tTime of sending\t\t\t\t\tRead\r\n================================================================================================================================="
if message[user.sName] then
for a,b in message[user.sName] do
msg=msg.."\r\n"..a.."\t\t\t\t"..b["who"].."\t\t\t"..b["when"].."\t\t\t\t"..numess(user.sName,a).."\r\n================================================================================================================================="
end
user:SendPM(Bot,msg)
user:SendPM(Bot,"Type !readmsg too see an individual message. Multiple numbers can be added separated by spaces.")
if checksize(user.sName) >= inboxsize then
user:SendPM(Bot,"Alert: Your inbox is full!")
end
else
user:SendData(parseenv(user,env,Bot).."You have no messages.")
end
end

function checksize(nick)
local array={}
for a,b in message[nick] do
tinsert(array,a)
end
return getn(array)
end

function delmsg(user,data,env)
if message[user.sName] then
local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
if args then
gsub(args,"(%d+)",function (nmbr)
nmbr=tonumber(nmbr)
if message[%user.sName][nmbr] then
message[%user.sName][nmbr]=nil
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." has been successfully deleted!")
else
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
end
end)
if checksize(user.sName)==0 then
message[user.sName]=nil
savemsg()
else
local array={}
for a,b in message[user.sName] do
tinsert(array,b)
end
for i=1,getn(array) do
message[user.sName]=resort(array)
end
savemsg()
end
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !delmsg . Multiple numbers can be added separated by spaces.")
end
else
user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
end
end

function resort(array)
local tbl={}
for i=1,getn(array) do
tbl[i]=array[i]
end
return tbl
end
-- nmbr, who, when, message
function parse(tbl)
local cnt=""
for a,b in tbl do
cnt=cnt.."\t\t\t\t\t\t\t\t\t["..a.."]=\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t[\"who\"]=\""..b["who"].."\",\n\t\t\t\t\t\t\t\t\t[\"when\"]=\""..b["when"]..
"\",\n\t\t\t\t\t\t\t\t\t[\"message\"]=\""..b["message"].."\",\n\t\t\t\t\t\t\t\t\t},\n"
end
return cnt
end

function savemsg()
writeto("offline.ini")
local what="message=\n{"
for a,b in message do
what=what.."\n\t\t\t[\""..a.."\"]={\n"..parse(b).."\t\t\t},"
end
what=what.."\n}"
write(what)
writeto()
end

function parseenv(user,env,bot)
if env=="PM" then
return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> "
elseif env=="MAIN" then
return "<"..bot.."> "
end
end

function NewUserConnected(user)
local washere=loadlist("washere.lst")
if not washere then washere={} end
if not washere[user.sName] then
washere[user.sName]=1
savefile(washere,"washere.lst")
end
if message[user.sName] then
local count={[user.sName]=0}
for a,b in message[user.sName] do
if b["read"]==0 then
count[user.sName]=count[user.sName]+1
end
end
if count[user.sName]>0 then
user:SendPM(Bot,"You have "..count[user.sName].." new messages. Type !inbox to see your inbox!")
end
end
end

function DataArrival(user,data)
if strsub(data,1,1)=="<" then
data=strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind(data,"%b<>%s+(%S+)")
cmd=strlower(cmd)
return parsecmds(user,data,cmd,"MAIN")
elseif strsub(data, 1, 4) == "$To:" then
data=strsub(data,1,strlen(data)-1)
local _,_,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == Bot) then
local _,_,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
cmd=strlower(cmd)
return parsecmds(user,data,cmd,"PM")
end
end
end

function parsecmds(user,data,cmd,env)
local returndata=0
if cmd=="!postmsg" then
postmsg(user,data,env) returndata=1
elseif cmd=="!readmsg" then
readmsg (user,data,env) returndata=1
elseif cmd=="!inbox" then
inbox(user,env) returndata=1
elseif cmd=="!delmsg" then
delmsg(user,data, env) returndata=1
end return returndata
end

function UserDisconnected(user)
local washere=loadlist("washere.lst")
if not washere then washere={} end
if not washere[user.sName] then
washere[user.sName]=1
savefile(washere,"washere.lst")
end
end

function OnExit()
savemsg()
end

OpDisconnected=UserDisconnected
OpConnected=NewUserConnected

Hope you can get it 2 work
Title:
Post by: REBEL on 06 September, 2004, 19:25:25
hehehe im glad you found it,
i was almost thinking i was doing something wrong
Now i try new version ....cross fingers , legs that i dont have problem lol
cheers bud
Title:
Post by: REBEL on 06 September, 2004, 19:33:39
well you not going to believe this ....you uncrossed ya fingers and legs lol

copied exactly from post the script

code:------------------------------------------------------------------------------------------------------------------------------------------------------------------ PostMan Bot 0.1 by bastya_elvtars (the rock n' roll doctor)
-- offline message system
-- you can set the inbox size and the bot name
-- code ripped from law maker bot
-- comands can be PMed or typed in main, the bot responds to them according to the environment (sometimes at least :D)
-- the commands are case insensitive, the parameters aren't :)
-- 0.2: added function so ppl cannot post 2 online users
-- 0.3: the above function now works ;)

------------- settings

Bot="PonyExpress" -- he he he

inboxsize=10 -- the maximum amount of messages users can have in their inbox

------------ end of settings

function Main()
if not readfrom("offline.ini") then message={} else dofile("offline.ini") end
frmHub:RegBot(Bot)
end

function loadlist(file) -- to see if the user was in the hub at all
   table=nil
   table={}
   readfrom(file)
   while 1 do
      local line = read()
      if line == nil then
         readfrom()
         break
      end
      table[line] = 1
   end
   readfrom()
   if table then
      return table
   else
      return {}
   end
end

function savefile(table,file) -- save users names who were in the hub
   writeto(file)
   for a,b in table do
      write(a.."\n")
   end
   writeto()
end

function postmsg(user,data,env)
   local _,_,nick,msg=strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
   if nick then
      if not GetItemByName(nick) then
         local washere=loadlist("washere.lst")
         if not washere then washere={} end
         if washere[nick] then
         if not message[nick] then
            message[nick]={[1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}}
            user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
            savemsg()
         else
            if checksize(nick)>=inboxsize then -- >= only for safety lol
               user:SendData(parseenv(user,env,Bot).."Sorry, but "..nick.." has a full inbox. Try again later.")
            else
               message[nick][checksize(nick)+1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}
               user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
               savemsg()
            end
         end
         else
            user:SendData(parseenv(user,env,Bot).."User "..nick.." has never been in the hub.")
         end
      else
         user:SendData(parseenv(user,env,Bot)..nick.." is online! PM would be simpler in this case...")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !postmsg ")
   end
end

function readmsg (user,data,env)
   if message[user.sName] then
      local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
      if args then
         gsub(args,"(%d+)",
         function(nmbr)
            nmbr=tonumber(nmbr)
            if message[%user.sName][nmbr] then
               local msg="\r\n\r\n\t\t\t\t\t\t\tMessage #"..nmbr..& quot;\r\n==================================================================
 ===============================================================\r\n\r\nFrom
: "..message[%user.sName][nmbr]["who"].."\r\nTime of sending: "..message[%user.sName][nmbr]["when"].."\r\nMessage: "..message[%user.sName][nmbr]["message"]..& quot;\r\n\r\n==============================================================
==================================================================="
               %user:SendPM(Bot,msg)
               if message[%user.sName][nmbr]["read"]==0 then
                  message[%user.sName][nmbr]["read"]=1
                  savemsg()
               end
            else
               %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
            end
         end)
      else
         user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !showmsg . Multiple numbers can be added separated by spaces.")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
   end
end

function numess(nick,a)
   if message[nick][a]["read"]==0 then return "no"
   else return "yes" end
end

function inbox (user,env)
local msg="\r\n\r\n\t\t\t\t\t\t\tHere is your  inbox:\r\n=================================================================
================================================================"..
"\r\nMessage #\t\t\tSender\t\t\t\t\tTime of  sending\t\t\t\t\tRead\r\n==================================================
 ===========================================================================
===="
if message[user.sName] then
for a,b in message[user.sName] do
msg=msg.."\r\n"..a.."\t\t\t\t"..b["who"].."\t\t\t"..b["when"].."\t\t\t\t"..numess(user.sName,a)..& quot;\r\n==================================================================
==============================================================="
end
user:SendPM(Bot,msg)
user:SendPM(Bot,"Type !readmsg too see an individual message. Multiple numbers can be added separated by spaces.")
if checksize(user.sName) >= inboxsize then
user:SendPM(Bot,"Alert: Your inbox is full!")
end
else
user:SendData(parseenv(user,env,Bot).."You have no messages.")
end
end

function checksize(nick)
   local array={}
   for a,b in message[nick] do
      tinsert(array,a)
   end
   return getn(array)
end

function delmsg(user,data,env)
if message[user.sName] then
local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
if args then
gsub(args,"(%d+)",function (nmbr)
nmbr=tonumber(nmbr)
if message[%user.sName][nmbr] then
message[%user.sName][nmbr]=nil
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." has been successfully deleted!")
else
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
end
end)
if checksize(user.sName)==0 then
message[user.sName]=nil
savemsg()
else
local array={}
for a,b in message[user.sName] do
tinsert(array,b)
end
for i=1,getn(array) do
message[user.sName]=resort(array)
end
savemsg()
end
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !delmsg . Multiple numbers can be added separated by spaces.")
end
else
user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
end
end

function resort(array)
local tbl={}
for i=1,getn(array) do
tbl=array
end
return tbl
end
-- nmbr, who, when, message
function parse(tbl)
local cnt=""
for a,b in tbl do
cnt=cnt.."\t\t\t\t\t\t\t\t\t["..a.."]=\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t[\"who\"]=\""..b["who"].."\",\n\t\t\t\t\t\t\t\t\t[\"when\"]=\""..b["when"]..
"\",\n\t\t\t\t\t\t\t\t\t[\"message\"]=\""..b["message"].."\",\n\t\t\t\t\t\t\t\t\t},\n"
end
return cnt
end

function savemsg()
writeto("offline.ini")
local what="message=\n{"
for a,b in message do
what=what.."\n\t\t\t[\""..a.."\"]={\n"..parse(b).."\t\t\t},"
end
what=what.."\n}"
write(what)
writeto()
end

function parseenv(user,env,bot)
if env=="PM" then
return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> "
elseif env=="MAIN" then
return "<"..bot.."> "
end
end

function NewUserConnected(user)
local washere=loadlist("washere.lst")
if not washere then washere={} end
if not washere[user.sName] then
washere[user.sName]=1
savefile(washere,"washere.lst")
end
if message[user.sName] then
local count={[user.sName]=0}
for a,b in message[user.sName] do
if b["read"]==0 then
count[user.sName]=count[user.sName]+1
end
end
if count[user.sName]>0 then
user:SendPM(Bot,"You have "..count[user.sName].." new messages. Type !inbox to see your inbox!")
end
end
end

function DataArrival(user,data)
if strsub(data,1,1)=="<" then
data=strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind(data,"%b<>%s+(%S+)")
cmd=strlower(cmd)
return parsecmds(user,data,cmd,"MAIN")
elseif strsub(data, 1, 4) == "$To:" then
data=strsub(data,1,strlen(data)-1)
local _,_,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == Bot) then
local _,_,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
cmd=strlower(cmd)
return parsecmds(user,data,cmd,"PM")
end
end
end

function parsecmds(user,data,cmd,env)
local returndata=0
if cmd=="!postmsg" then
postmsg(user,data,env) returndata=1
elseif cmd=="!readmsg" then
readmsg (user,data,env) returndata=1
elseif cmd=="!inbox" then
inbox(user,env) returndata=1
elseif cmd=="!delmsg" then
delmsg(user,data, env) returndata=1
end return returndata
end

function UserDisconnected(user)
local washere=loadlist("washere.lst")
if not washere then washere={} end
if not washere[user.sName] then
washere[user.sName]=1
savefile(washere,"washere.lst")
end
end

function OnExit()
savemsg()
end

OpDisconnected=UserDisconnected
OpConnected=NewUserConnected--------------------------------------------------------------------------------



now got this error

Syntax Error: function arguments expected;
  last token read: `=' at line 12 in string "code:----------------------------------------------------------..."

i love it when a plan goes right lol
hope you have sence of humour
Title:
Post by: Herodes on 06 September, 2004, 20:10:45
I am so confident that you copy paste the script with some "addon" word from the board ... take a look at this ...
----------------------------------------------------------
and this ...
"code:----------------------------------------------------------..."
Title:
Post by: bastya_elvtars on 06 September, 2004, 20:12:22
EEEEEEEEerrrrrrrrm...

What ptokax are you using? This was tested on 330 15.25.
Title:
Post by: bastya_elvtars on 06 September, 2004, 20:15:59
omg really
i forgot that you should copy the code from between the 2 horizontal lines. Thx Herodes for the hint.
Title:
Post by: REBEL on 06 September, 2004, 20:20:37
ah now so is this not part of the script that i copied exactly as posted ?

ode:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


and this ...
"code:----------------------------------------------------------..."


and im useing PtokaX DC Hub 0.3.2.6 TestDrive 4


so if your testing the script on beta which ive not got ...it wont work then
Title:
Post by: bastya_elvtars on 06 September, 2004, 20:26:31
it should, it just wont  call the saving of table on exit, but it does not matter, thats just for security, so it should work properly.
Title:
Post by: Herodes on 06 September, 2004, 20:26:35
QuoteOriginally posted by REBEL
so if your testing the script on beta which ive not got ...it wont work then
It will not work on the 0.2.6 td4 or td4.99 because those versions dont have the OnExit() function I imagine bastya_elvtars can have a look into that .. :)

[*edit*] comment post-pile-up :)
Title:
Post by: bastya_elvtars on 06 September, 2004, 20:32:04
If OnExit() is not supported by td4, that if the file still contains it, means that i have declared a function that will never be called in td4, so its a useless part of the code, but cannot do any harm. The script must work properly on TD4.

---------- edit

i have tested it on 0.325 ashcan too, so its 1000% it works on td4
Title:
Post by: Herodes on 06 September, 2004, 20:47:57
QuoteOriginally posted by bastya_elvtars
If OnExit() is not supported by td4, that if the file still contains it, means that i have declared a function that will never be called in td4, so its a useless part of the code, but cannot do any harm. The script must work properly on TD4.

---------- edit

i have tested it on 0.325 ashcan too, so its 1000% it works on td4
okie sry I wasnt carefull in watching the code :)
Title:
Post by: REBEL on 06 September, 2004, 21:14:07
ahha me wait, me let you sort out
if at sometime it works on version im useing without syntex error would be pleased to know :)
Thanks guys
Title:
Post by: bastya_elvtars on 06 September, 2004, 21:19:52
it works on testdrive 4 rofl :P

and PLEASE give me feedback if you like it

oh!

USAGE:

!postmsg - post a message to the user. User has to be offline, and it goes 2 users who connected to the hub at least once.

!inbox - shows inbox

!readmsg -  displays the message with . Multiple numbers can be added separated by spaces.

!delmsg - deletes the the message with . Multiple numbers can be added separated by spaces.
Title:
Post by: REBEL on 06 September, 2004, 21:31:42
ok i will try it for you and ....just remember fingers and legs crossed and dont uncross till i get back lolol
Title:
Post by: REBEL on 06 September, 2004, 21:48:46
ermm correct i put it in the scripts just saved it and loaded restarted scripts it has not put the bot on the hub
i tried leaving a message by typing in main and was wondering do i need to put any folders for the msg to go into eg inbox txt
just wondered why it has not reg on hub or do i need to reboot hub ?
i hope my input is helping
Title:
Post by: bastya_elvtars on 06 September, 2004, 21:57:38
gave lua extension to it? (offline.lua for ex.)

no need 2 restart hub, only scripts.
Title:
Post by: REBEL on 06 September, 2004, 22:09:07
yeh i think ive missed something somewhere but not sure what
i used the one you corrected the error in
and sorry not sure what you mean by lua extension to it? (offline.lua for ex.)
or do i need to add this somwhere ?

okey dokey
Title:
Post by: bastya_elvtars on 06 September, 2004, 22:12:46
mcopy the error corrected version
paste into notepad
and save it as offline.lua for example
into ptokax scripts folder
and restart scripts
Title:
Post by: REBEL on 06 September, 2004, 22:17:05
arhhh now i got ya :)

ive been saving as ponyexpress
ok try again
dont move a inch
watch this space lol
Title:
Post by: REBEL on 06 September, 2004, 22:23:13
nope sorry got this error and no bot on hub

Syntax Error: function arguments expected;
  last token read: `=' at line 12 in file `C:\Program Files\PtokaX-CJ\scripts\offline.lua'

i am useing the one you corrected
Title:
Post by: bastya_elvtars on 06 September, 2004, 22:43:49
-- PostMan Bot 0.1 by bastya_elvtars (the rock n' roll doctor)
-- offline message system
-- you can set the inbox size and the bot name
-- code ripped from law maker bot
-- comands can be PMed or typed in main, the bot responds to them according to the environment (sometimes at least :D)
-- the commands are case insensitive, the parameters aren't :)
-- 0.2: added function so ppl cannot post 2 offline users

------------- settings

Bot="PostMan" -- he he he

inboxsize=10 -- the maximum amount of messages users can have in their inbox

------------ end of settings

function Main()
   if not readfrom("offline.ini") then message={} else dofile("offline.ini") end
   frmHub:RegBot(Bot)
end

function loadlist(file) -- to see if the user was in the hub at all
   table=nil
   table={}
   readfrom(file)
   while 1 do
      local line = read()
      if line == nil then
         readfrom()
         break
      end
      table[line] = 1
   end
   readfrom()
   if table then
      return table
   else
      return {}
   end
end

function savefile(table,file) -- save users names who were in the hub
writeto(file)
   for a,b in table do
      write(a.."\n")
   end
writeto()
end

function postmsg(user,data,env)
   local _,_,nick,msg=strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
   if nick then
      if not GetItemByName(nick) then
         local washere=loadlist("washere.lst")
         if not washere then washere={} end
         if washere[nick] then
            if not message[nick] then
               message[nick]={[1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}}
               user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
               savemsg()
            else
               if checksize(nick)>=inboxsize then -- >= only for safety lol
                  user:SendData(parseenv(user,env,Bot).."Sorry, but "..nick.." has a full inbox. Try again later.")
               else
                  message[nick][checksize(nick)+1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}
                  user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
                  savemsg()
               end
            end
         else
            user:SendData(parseenv(user,env,Bot).."User "..nick.." has never been in the hub.")
         end
      else
         user:SendData(parseenv(user,env,Bot)..nick.." is online! PM would be simpler in this case...")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !postmsg ")
   end
end

function readmsg (user,data,env)
   if message[user.sName] then
      local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
      if args then
         gsub(args,"(%d+)",function(nmbr)
                        nmbr=tonumber(nmbr)
                        if message[%user.sName][nmbr] then
                           local msg="\r\n\r\n\t\t\t\t\t\t\tMessage #"..nmbr.."\r\n=================================================================================================================================\r\n\r\nFrom: "..message[%user.sName][nmbr]["who"].."\r\nTime of sending: "..message[%user.sName][nmbr]["when"]..
                           "\r\nMessage: "..message[%user.sName][nmbr]["message"].."\r\n\r\n================================================================================================================================="
                           %user:SendPM(Bot,msg)
                           if message[%user.sName][nmbr]["read"]==0 then
                              message[%user.sName][nmbr]["read"]=1
                              savemsg()
                           end
                        else
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
                        end
                     end)
      else
         user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !showmsg . Multiple numbers can be added separated by spaces.")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
   end
end

function numess(nick,a)
   if message[nick][a]["read"]==0 then return "no"
   else return "yes" end
end

function inbox (user,env)
   local msg="\r\n\r\n\t\t\t\t\t\t\tHere is your inbox:\r\n================================================================================================================================="..
            "\r\nMessage #\t\t\tSender\t\t\t\t\tTime of sending\t\t\t\t\tRead\r\n================================================================================================================================="
   if message[user.sName] then
      for a,b in message[user.sName] do
         msg=msg.."\r\n"..a.."\t\t\t\t"..b["who"].."\t\t\t"..b["when"].."\t\t\t\t"..numess(user.sName,a).."\r\n================================================================================================================================="
      end
      user:SendPM(Bot,msg)
      user:SendPM(Bot,"Type !readmsg too see an individual message. Multiple numbers can be added separated by spaces.")
      if checksize(user.sName) >= inboxsize then
         user:SendPM(Bot,"Alert: Your inbox is full!")
      end
   else
      user:SendData(parseenv(user,env,Bot).."You have no messages.")
   end
end

function checksize(nick)
   local array={}
   for a,b in message[nick] do
      tinsert(array,a)
   end
   return getn(array)
end

function delmsg(user,data,env)
   if message[user.sName] then
      local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
      if args then
         gsub(args,"(%d+)",function (nmbr)
                        nmbr=tonumber(nmbr)
                        if message[%user.sName][nmbr] then
                           message[%user.sName][nmbr]=nil
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." has been successfully deleted!")
                        else
                           %user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
                        end
                     end)
         if checksize(user.sName)==0 then
            message[user.sName]=nil
            savemsg()
         else
            local array={}
            for a,b in message[user.sName] do
               tinsert(array,b)
            end
            for i=1,getn(array) do
               message[user.sName]=resort(array)
            end
            savemsg()
         end
      else
         user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !delmsg . Multiple numbers can be added separated by spaces.")
      end
   else
      user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
   end
end

function resort(array)
   local tbl={}
   for i=1,getn(array) do
      tbl=array
   end
   return tbl
end
-- nmbr, who, when, message
function parse(tbl)
   local cnt=""
   for a,b in tbl do
      cnt=cnt.."\t\t\t\t\t\t\t\t\t["..a.."]=\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t[\"who\"]=\""..b["who"].."\",\n\t\t\t\t\t\t\t\t\t[\"when\"]=\""..b["when"]..
      "\",\n\t\t\t\t\t\t\t\t\t[\"message\"]=\""..b["message"].."\",\n\t\t\t\t\t\t\t\t\t},\n"
   end
   return cnt
end

function savemsg()
   writeto("offline.ini")
   local what="message=\n{"
   for a,b in message do
      what=what.."\n\t\t\t[\""..a.."\"]={\n"..parse(b).."\t\t\t},"
   end
   what=what.."\n}"
   write(what)
   writeto()
end

function parseenv(user,env,bot)
   if env=="PM" then
      return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> "
   elseif env=="MAIN" then
      return "<"..bot.."> "
   end
end

function NewUserConnected(user)
   local washere=loadlist("washere.lst")
   if not washere then washere={} end
   if not washere[user.sName] then
      washere[user.sName]=1
      savefile(washere,"washere.lst")
   end
   if message[user.sName] then
      local count={[user.sName]=0}
      for a,b in message[user.sName] do
         if b["read"]==0 then
            count[user.sName]=count[user.sName]+1
         end
      end
      if count[user.sName]>0 then
         user:SendPM(Bot,"You have "..count[user.sName].." new messages. Type !inbox to see your inbox!")
      end
   end
end

function DataArrival(user,data)
   if strsub(data,1,1)=="<" then
      data=strsub(data,1,strlen(data)-1)
         local _,_,cmd = strfind(data,"%b<>%s+(%S+)")
         cmd=strlower(cmd)
         return parsecmds(user,data,cmd,"MAIN")
   elseif strsub(data, 1, 4) == "$To:" then
      data=strsub(data,1,strlen(data)-1)
      local _,_,whoTo = strfind(data,"$To:%s+(%S+)")
      if (whoTo == Bot) then
         local _,_,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
         cmd=strlower(cmd)
         return parsecmds(user,data,cmd,"PM")
      end
   end
end

function parsecmds(user,data,cmd,env)
   local returndata=0
   if cmd=="!postmsg" then
      postmsg(user,data,env) returndata=1
   elseif cmd=="!readmsg" then
      readmsg (user,data,env) returndata=1
   elseif cmd=="!inbox" then
      inbox(user,env) returndata=1
   elseif cmd=="!delmsg" then
      delmsg(user,data, env) returndata=1
   end return returndata
end

function UserDisconnected(user)
   local washere=loadlist("washere.lst")
   if not washere then washere={} end
   if not washere[user.sName] then
      washere[user.sName]=1
      savefile(washere,"washere.lst")
   end
end

function OnExit()
   savemsg()
end

OpDisconnected=UserDisconnected
OpConnected=NewUserConnected
Title:
Post by: Herodes on 06 September, 2004, 22:49:43
QuoteOriginally posted by REBEL
ahha me wait, me let you sort out
if at sometime it works on version im useing without syntex error would be pleased to know :)
Thanks guys
Its works .. just read our dialog through ....
Title:
Post by: bastya_elvtars on 06 September, 2004, 23:18:32
it might work, cause rebel is in silence lol
Title:
Post by: REBEL on 06 September, 2004, 23:24:50
haha just when you thought it was quiet ....Wrong lol

no seriously guys it didnt work
got another one of these for ya

Syntax Error: expected;
  last token read: `&' at line 88 in file `C:\Program Files\PtokaX-CJ\scripts\Offline.lua'


joking apart ....i hope my input is helping you
as i have enjoyed trying this out
Title:
Post by: bastya_elvtars on 06 September, 2004, 23:27:24
yep if i dont send it as monospaced
wait heres a link

http://www.plop.nl/ptokaxbots/bastya_elvtars/offlinepost.lua

get it from here, and thx plop for hosting my scripts, will be reversed someday :PPPP
Title:
Post by: REBEL on 06 September, 2004, 23:33:28
ahha but will it work ....i hope so

this has been really a education lol
Title:
Post by: REBEL on 06 September, 2004, 23:56:03
Well ....what can i say now .

I LIKE IT ....WORKS GREAT

Really nice work bastya_elvtars

i guess i'll have to find something else to play with now lol

give ya self a gold star lol
hope more try it
a very pleased REBEL
Title:
Post by: bastya_elvtars on 06 September, 2004, 23:58:50
QuoteOriginally posted by REBEL
Well ....what can i say now .

I LIKE IT ....WORKS GREAT

Really nice work bastya_elvtars

i guess i'll have to find something else to play with now lol

give ya self a gold star lol
hope more try it
a very pleased REBEL

well i am happy that at least one guy likes my first released script. This gives me the power to continue ^^.

----------------------------------------------------

try lawmaker please, need suggestions, my ideas are in it
Title:
Post by: Herodes on 07 September, 2004, 01:24:07
Oleee Finally ;)
Title:
Post by: [PT]CableGuy on 07 September, 2004, 02:10:37
QuoteOriginally posted by bastya_elvtars
...This gives me the power to continue...
Please , do continue !!!
I love this script also !!! Excelent job over here. :]
Title:
Post by: kEwL on 14 July, 2005, 14:41:07
i get this error pls help me
[18:10] Syntax C:\ptokax\scripts\offline.lua:87: unexpected symbol near `%'
Title:
Post by: Dessamator on 14 July, 2005, 16:27:23
this script was written for lua4, it wont work on lua 5, and i think it has already been converted, somewhere !
Title: lua 5
Post by: ?Tr??T_???? on 08 August, 2005, 11:50:01
can someone give me this script in lua 5? :D
Title:
Post by: HillyBilly on 08 August, 2005, 12:51:51
QuoteOriginally posted by ?Tr??T_????
can someone give me this script in lua 5? :D

Look at this thread Postman lua5 (http://board.univ-angers.fr/thread.php?threadid=3877&boardid=26&sid=14dd0bf2e6082830c5af0e7134df0777&page=2)

Cheers HB
Title: thnx
Post by: ?Tr??T_???? on 08 August, 2005, 13:41:30
oh yeah thats what i was lookin for hnk u one more time :P  :P  :)