PostMan by bastya_elvtars (the rock n' roll doctor)
 

PostMan by bastya_elvtars (the rock n' roll doctor)

Started by bastya_elvtars, 06 September, 2004, 09:25:01

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bastya_elvtars

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
Everything could have been anything else and it would have just as much meaning.

REBEL

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

bastya_elvtars

please send it again using the code function,or disable smilies in your post, cause it stuffs up the scripts, removing every brackets
Everything could have been anything else and it would have just as much meaning.

REBEL

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

bastya_elvtars

found no errors in it, you only changed the botname right? then see if its

Bot="=Pony_Express="


this line is the erroneous one...
Everything could have been anything else and it would have just as much meaning.

REBEL

oh ok ....so i cant change bot name ?

not too worry . thanks anyway

bastya_elvtars

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...
Everything could have been anything else and it would have just as much meaning.

REBEL

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

bastya_elvtars

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
Everything could have been anything else and it would have just as much meaning.

REBEL

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

REBEL

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

Herodes

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:----------------------------------------------------------..."

bastya_elvtars

EEEEEEEEerrrrrrrrm...

What ptokax are you using? This was tested on 330 15.25.
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

omg really
i forgot that you should copy the code from between the 2 horizontal lines. Thx Herodes for the hint.
Everything could have been anything else and it would have just as much meaning.

REBEL

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

bastya_elvtars

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.
Everything could have been anything else and it would have just as much meaning.

Herodes

#16
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 :)

bastya_elvtars

#17
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
Everything could have been anything else and it would have just as much meaning.

Herodes

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 :)

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

bastya_elvtars

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.
Everything could have been anything else and it would have just as much meaning.

REBEL

ok i will try it for you and ....just remember fingers and legs crossed and dont uncross till i get back lolol

REBEL

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

bastya_elvtars

gave lua extension to it? (offline.lua for ex.)

no need 2 restart hub, only scripts.
Everything could have been anything else and it would have just as much meaning.

REBEL

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

SMF spam blocked by CleanTalk