PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: bastya_elvtars on 09 March, 2005, 14:06:02

Title: PostMan 0.3 LUA5
Post by: bastya_elvtars on 09 March, 2005, 14:06:02
Many requested an offline post script. As they don't want to use LawMaker X( , converted this instead. Enjoy!

Download here. (http://www.aokol.u-szeged.hu/postman03.lua)
Title: Error
Post by: XPMAN on 15 March, 2005, 07:00:00
Tried this awesome script......but got this error:

  Syntax C:\MASTER TEST HUB\0.3.3.0.b16.06.nt.rls\scripts\POSTMAN.lua:169: unexpected symbol near `&'

Any ideas?  This seems to be cool script, maybe something simple.......hopefully :)


Regards
Title: just a little html blabla
Post by: UwV on 15 March, 2005, 10:15:41
only need to change
this ->
 local msg="\r\n\r\n\t\t\t\t\t\t\tMessage #"..nmbr.. & qout;\r\n
to this ->
 local msg="\r\n\r\n\t\t\t\t\t\t\tMessage #"..nmbr.."\r\n

there is two more .. in my linecount they are in:
 line 94 and in line 122.
so.
..
              -> & quot; <-  
 should just be be replaced with a
                 ->  "  <-
Title:
Post by: bolamix on 15 March, 2005, 18:11:53
Wow.... truly impressive bast, even if it's way too complicated for my simple tastes ;)

Just one more thing on top of the " : you have to replace date with os.date at lines 52 and 59 (in my linecount at least)
Title:
Post by: bastya_elvtars on 15 March, 2005, 22:43:27
Heh, yes, thx, forgot the date. (Haunted by manual conversion... :P)

Also, replaced the " to ".

Edited my above post.
Title: Thank u
Post by: XPMAN on 16 March, 2005, 07:38:38
Thanx for the help fixing :) Awesome script, very usefull !!

X
Title:
Post by: Oz on 24 March, 2005, 13:53:04
too bastya_elvtars, can u add the new function to the script?

auto send offline message when the user back to online?
Title:
Post by: bastya_elvtars on 28 March, 2005, 22:56:48
So show the messages, not just the notification? Would be easy to do, but if user forgets to prune his/her inbox, there can be looooooooooong PM's. That's why I decided to add the inbox.
Title:
Post by: Herodes on 30 March, 2005, 21:24:00
smth new :)
-- PostMan Bot 0.3 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:
-- converted to lua5
-- washere is now global, no more CPU spikes

------- 0.4:
-- touched by Herodes (optimisation tsunami)
-- added : more details on the bot
-- added : message privacy ;)
-- changed : better way to parseenv ;)
-- changed : better way to display messages and inbox
-- changed : better way to parsecmds ( thx bastya_elvtars ;)

------------- settings
Bot = {
name = "PostMan" , -- bot's name
email = "postman@mail.me", -- bot's email
desc = "Post messages to other users here..", -- bot's desc
}
inboxsize=10 -- the maximum amount of messages users can have in their inbox

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


-------------------------------------- Utility Functions
function cls()
collectgarbage()
io.flush()
end

function Main()
local function load()
local t = {}; local f = io.open("washere.lst", "r")
if f then for l in f:lines() do t[l] = 1; end; f:close(); end
return t;
end
washere = load()
message = {}
assert(dofile("offline.dat"), "Please restart your scripts, offline.dat will appear in the scripts folder..")
frmHub:RegBot(Bot.name, 1, Bot.desc, Bot.email )
Bot = Bot.name
end

-------------------------------------- Command Functions
--- post msg
function postmsg( user, data, how )
local _,_,nick,msg = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if nick then
if not GetItemByName(nick) then
if washere[nick] then
local function checksize(n) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
if not message[nick] then message[nick] = {}; end
if (checksize(nick) < inboxsize) then
table.insert( message[nick], { ["message"] = msg, ["who"] = user.sName, ["when"] = os.date("%Y. %m. %d. %X"), ["read"] = 0, } )
SendBack( user, "Successfully sent the message!", Bot, how )
savemsg()
else
SendBack( user, "Sorry, but "..nick.." has a full inbox. Try again later.", Bot, how )
end
else
SendBack( user, "User "..nick.." has never been in the hub.", Bot, how )
end
else
SendBack( user, nick.." is online! PM would be simpler in this case...", Bot, how )
end
else
SendBack( user, "Bad syntax! Usage: !postmsg ", Bot, how )
end
cls(); return 1;
end

function delmsg( user, data, how )
if message[user.sName] then
local _,_,args = string.find(data,"%b<>%s+%S+%s+(.+)")
if args then
local function checksize(n) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
local function resort(t) local r ={}; for i,v in t do table.insert(r, v); end; return r; end
for num in string.gfind( args, "%s-(%d+)%s-" ) do
if num then
num = tonumber(num);
if message[user.sName][num] then
message[user.sName][num] = nil
SendBack( user, "Message #"..num.." has been successfully deleted!", Bot, how )
else
SendBack( user, "Message #"..num.." does not exist!", Bot, how )
end
end
end
message[user.sName] = resort(message[user.sName]);
if checksize(user.sName) == 0 then message[user.sName] = nil; end
savemsg()
else
SendBack( user, "Bad syntax! Usage: !delmsg . Multiple numbers can be added separated by spaces.", Bot, how )
end
else
SendBack( user, "Your inbox is empty.", Bot, how )
end
cls(); return 1;
end

--- show inbox
function inbox( user, how )
local sep, msg = string.rep( "=", 75 ), "\r\n\r\n\t\t\t\t\t\t\tHere is your inbox:\r\n"
msg = msg..sep.."\r\n Msg#\tSender\tTime of sending\t\tRead\r\n"..sep
if message[user.sName] then
local function numess ( r ) if r == 0 then return "no"; end return "yes"; end
local function checksize ( n ) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
local function dcode ( s ) if (string.sub(s,1,3) == "-n#") then s=string.sub(s,4,-1); local res = ""; for num in string.gfind( s, "#?(%d+)") do res = res..string.char(tonumber(num));end;return res;end;return s;end
for num, t in message[user.sName] do
msg=msg.."\r\n "..num.."\t"..dcode(t.who).."\t"..t.when.."\t"..numess(t.read).."\r\n"..sep
end
SendBack( user, msg, Bot, true )
SendBack( user, "Type !readmsg too see an individual message. Multiple numbers can be added separated by spaces.", Bot, true )
if checksize(user.sName) >= inboxsize then SendBack( user, "Alert: Your inbox is full!", Bot, true ); end
else
SendBack( user, "You have no messages.", Bot, how )
end
cls(); return 1;
end

--- read msg(s)
function readmsg( user, data, how )
if message[user.sName] then
local _,_,args=string.find(data,"%b<>%s+%S+%s+(.+)")
if args then
local function dcode(s) if (string.sub(s,1,3) == "-n#") then s = string.sub(s,4,-1);local res = ""; for num in string.gfind( s, "#?(%d+)") do res = res..string.char(tonumber(num));end;return res;end;return s;
end
for num in string.gfind( args, "%s-(%d+)%s-" ) do
if num then num = tonumber(num) end
if num and message[user.sName][num] then
local t = message[user.sName][num]
local msg, sep,set = "\r\n\r\n\t\t\t\t\t\t\tMessage #"..num.."\r\n", string.rep( "=", 100 ), string.rep("- ", 85)
msg = msg..sep.."\r\n\r\nFrom: "..dcode(t.who).."\tTime: "..t.when.."\t\tMessage follows\r\n"..set.."[Message start]\r\n"..dcode(t.message).."\r\n"..set.."[Message end]\r\n"..sep
SendBack( user, msg, Bot, true )
if t.read == 0 then t.read = 1; savemsg(); end
else
SendBack( user, "Message #"..num.." does not exist!", Bot, how )
end
end
else
SendBack( user, "Bad syntax! Usage: !showmsg . Multiple numbers can be added separated by spaces.", Bot, how )
end
else
SendBack( user, "Your inbox is empty.", Bot, how )
end
cls(); return 1;
end

function savemsg()
local function parse(tbl)
local str, tab ="", string.rep( "\t", 9)
local function fquot(s) return string.format( "%q", s) end
local function ncode( s ) if (s ~= "") and (string.sub(s,1,3) ~= "-n#") then local t = {}; for i = 1, string.len(s) do t[i] = string.byte(string.sub(s,i,i)); end; return "-n#"..table.concat(t, "#"); end; return s; end
for a, t in tbl do
str = str.."\t\t{ ["..fquot("read").."] = "..t.read..", ["..fquot("who").."] = "..fquot(ncode(t.who))..", ["..fquot("when").."] = "..fquot(t.when)..",\n\t\t["..fquot("message").."] = "..fquot(ncode(t.message)).." },\n"
end
return str
end
local f = io.open ( "offline.dat", "w+" )
local s = "message = {"
for name, t in message do
s = s.."\n\t["..string.format( "%q", string.gsub( name, "\"", "\"")).."] = {\n"..parse(t).."\t},"
end;
f:write(s.."\n}")
f:close()
end

function SendBack( user, msg, who, pm )
if pm then user:SendPM ( who, msg ); else user:SendData( who, msg ); end
end

function NewUserConnected(user)
if not washere[user.sName] then washere[user.sName] = 1 end
if message[user.sName] then
local cnt=0
for a,b in message[user.sName] do if (b.read == 0) then cnt = cnt+1; end end
if (cnt > 0) then SendBack( user, "You have "..cnt.." new messages. Type !inbox to see your inbox!", Bot, true ); end
end
end

function ChatArrival(user,data)
local data = string.sub( data, 1, -2 )
local _,_,cmd = string.find(data,"%b<>%s+[!+.#?](%S+)")
if cmd then return parsecmds( user, data, string.lower(cmd) ); end
end

function ToArrival(user,data)
if (string.sub( data, 1, string.len(Bot)+5) == "$To: "..Bot) then
local data = string.sub( data, 1, -2 )
local _,_,cmd = string.find(data,"%$%b<>%s+[!+.#?](%S+)")
if cmd then return parsecmds( user, data, string.lower(cmd), true ) end
return 1
end
end


function parsecmds( user, data, cmd, how )
local t = {
postmsg = { postmsg, { user, data, how } },
readmsg = { readmsg, { user, data, how } },
inbox = { inbox, { user, how } },
delmsg = { delmsg, { user, data, how } },
}
if t[cmd] then
return t[cmd][1]( unpack(t[cmd][2]) )
end
end

function UserDisconnected(user)
if not washere[user.sName] then washere[user.sName] = 1; end
end

function OnExit()
savemsg()
local f = io.open( "washere.lst", "w+")
for a,b in washere do f:write(a.."\n"); end
f:close()
end

OpDisconnected=UserDisconnected
OpConnected=NewUserConnected
Title:
Post by: bastya_elvtars on 31 March, 2005, 02:16:36
You have done quite a nice job on this. I always keep learning from others, and you know: good priests learn till they die, good pathologists do some even afterwards. ;)

Thx for this! :)
Title: problem with postman 0.4
Post by: Skippy84 on 04 April, 2005, 02:33:52
the script stops at this line  (line95)

   assert(dofile("offline.dat"), "Please restart your scripts, offline.dat will appear in the scripts folder..")


inptokax script editor is this massage shown but after restart of scripts and hub the message is already diplay again
Title:
Post by: Herodes on 04 April, 2005, 09:30:51
yep my bad.. creating a new file and renaming it to 'offline.dat' should go past it .. sry for the confusion
Title:
Post by: Skippy84 on 04 April, 2005, 10:17:05
the file you mean was in scripts
i delete the file
and make new one restart ptokax and the error message is the same

(i use ptokax 16.09)
Title:
Post by: Skippy84 on 04 April, 2005, 19:06:14
for my first error this is a workaround
-- assert(dofile("offline.dat"), "Please restart your scripts, offline.dat will appear in the scripts folder..") commend line 95 out

why  this helps? anyone can help fix this error


and the second error is the syntax for read message is not
!showmsg  

the syntax is !readmsg
Title:
Post by: Herodes on 04 April, 2005, 22:01:29
QuoteOriginally posted by Skippy84
for my first error this is a workaround
-- assert(dofile("offline.dat"), "Please restart your scripts, offline.dat will appear in the scripts folder..") commend line 95 out

why  this helps? anyone can help fix this error


and the second error is the syntax for read message is not
!showmsg  

the syntax is !readmsg
try replacing this
assert(dofile("offline.dat"), "Please restart your scripts, offline.dat will appear in the scripts folder..") with this .. ( see what happens ;)dofile("offline.dat")thx for reporting the other buggie ..
Title: Postman version change to 0.5
Post by: Skippy84 on 04 April, 2005, 23:02:48
-- PostMan Bot 0.3 by bastya_elvtars (the rock n' roll doctor)
-- offline message system
-- 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:
-- converted to lua5
-- washere is now global, no more CPU spikes



------- 0.4:
-- touched by Herodes (optimisation tsunami)
-- added : more details on the bot
-- added : message privacy ;)
-- changed : better way to parseenv ;)
-- changed : better way to display messages and inbox
-- changed : better way to parsecmds ( thx bastya_elvtars ;)

------- 0.5:
-- touched by Skippy84
-- fix error: make offline.dat  thx goto Herodes for the idea to fix the problem
-- fix error: false command !showmsg
-- added: commands can edit at the Settings section
-- added: shown commands linked to the editable commands (so ther change on the fly)



--------------------------------SETTINGS----------------------------------------

Bot = {
name = "PostMan" , -- bot's name
email = "postman@mail.me", -- bot's email
desc = "Post messages to other users here..", -- bot's desc
}

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

cmdpost = "postmsg" -- Shows the Hub Stats
cmdread = "readmsg" -- Shows the Hub Stats
cmdibox = "inbox" -- Shows the Hub Stats
cmddbox = "delmsg" -- Shows the Hub Stats



----------------------END OF SETTINGS-------------------------------------------





-------------------------------------- Utility Functions

function cls()
collectgarbage()
io.flush()
end



function Main()
local function load()
local t = {}; local f = io.open("washere.lst", "r")
if f then for l in f:lines() do t[l] = 1; end; f:close(); end
return t;
end
washere = load()
message = {}
dofile("offline.dat")
frmHub:RegBot(Bot.name, 1, Bot.desc, Bot.email )
Bot = Bot.name
end



-------------------------------------- Command Functions

--- post msg

function postmsg( user, data, how )
local _,_,nick,msg = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if nick then
if not GetItemByName(nick) then
if washere[nick] then
local function checksize(n) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
if not message[nick] then message[nick] = {}; end
if (checksize(nick) < inboxsize) then
table.insert( message[nick], { ["message"] = msg, ["who"] = user.sName, ["when"] = os.date("%Y. %m. %d. %X"), ["read"] = 0, } )
SendBack( user, "Successfully sent the message!", Bot, how )
savemsg()
else
SendBack( user, "Sorry, but "..nick.." has a full inbox. Try again later.", Bot, how )
end
else
SendBack( user, "User "..nick.." has never been in the hub.", Bot, how )
end
else
SendBack( user, nick.." is online! PM would be simpler in this case...", Bot, how )
end
else
SendBack( user, "Bad syntax! Usage: !"..cmdpost.." ", Bot, how )
end
cls(); return 1;
end



function delmsg( user, data, how )
if message[user.sName] then
local _,_,args = string.find(data,"%b<>%s+%S+%s+(.+)")
if args then
local function checksize(n) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
local function resort(t) local r ={}; for i,v in t do table.insert(r, v); end; return r; end
for num in string.gfind( args, "%s-(%d+)%s-" ) do
if num then
num = tonumber(num);
if message[user.sName][num] then
message[user.sName][num] = nil
SendBack( user, "Message #"..num.." has been successfully deleted!", Bot, how )
else
SendBack( user, "Message #"..num.." does not exist!", Bot, how )
end
end
end
message[user.sName] = resort(message[user.sName]);
if checksize(user.sName) == 0 then message[user.sName] = nil; end
savemsg()
else
SendBack( user, "Bad syntax! Usage: !"..cmddbox.." . Multiple numbers can be added separated by spaces.", Bot, how )
end
else
SendBack( user, "Your inbox is empty.", Bot, how )
end
cls(); return 1;
end

----------------------------------------------------------------------------------
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------- show inbox

function inbox( user, how )
local sep, msg = string.rep( "=", 75 ), "\r\n\r\n\t\t\t\t\t\t\tHere is your inbox:\r\n"
msg = msg..sep.."\r\n Msg#\tSender\tTime of sending\t\tRead\r\n"..sep
if message[user.sName] then
local function numess ( r ) if r == 0 then return "no"; end return "yes"; end
local function checksize ( n ) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
local function dcode ( s ) if (string.sub(s,1,3) == "-n#") then s=string.sub(s,4,-1); local res = ""; for num in string.gfind( s, "#?(%d+)") do res = res..string.char(tonumber(num));end;return res;end;return s;end
for num, t in message[user.sName] do
msg=msg.."\r\n "..num.."\t"..dcode(t.who).."\t"..t.when.."\t"..numess(t.read).."\r\n"..sep
end
SendBack( user, msg, Bot, true )
SendBack( user, "Type !"..cmdread.." too see an individual message. Multiple numbers can be added separated by spaces.", Bot, true )
if checksize(user.sName) >= inboxsize then SendBack( user, "Alert: Your inbox is full!", Bot, true ); end
else
SendBack( user, "You have no messages.", Bot, how )
end
cls(); return 1;
end



--- read msg(s)

function readmsg( user, data, how )
if message[user.sName] then
local _,_,args=string.find(data,"%b<>%s+%S+%s+(.+)")
if args then
local function dcode(s) if (string.sub(s,1,3) == "-n#") then s = string.sub(s,4,-1);local res = ""; for num in string.gfind( s, "#?(%d+)") do res = res..string.char(tonumber(num));end;return res;end;return s;
end
for num in string.gfind( args, "%s-(%d+)%s-" ) do
if num then num = tonumber(num) end
if num and message[user.sName][num] then
local t = message[user.sName][num]
local msg, sep,set = "\r\n\r\n\t\t\t\t\t\t\tMessage #"..num.."\r\n", string.rep( "=", 100 ), string.rep("- ", 85)
msg = msg..sep.."\r\n\r\nFrom: "..dcode(t.who).."\tTime: "..t.when.."\t\tMessage follows\r\n"..set.."[Message start]\r\n"..dcode(t.message).."\r\n"..set.."[Message end]\r\n"..sep
SendBack( user, msg, Bot, true )
if t.read == 0 then t.read = 1; savemsg(); end
else
SendBack( user, "Message #"..num.." does not exist!", Bot, how )
end
end
else
SendBack( user, "Bad syntax! Usage: !"..cmdread.." . Multiple numbers can be added separated by spaces.", Bot, how )
end
else
SendBack( user, "Your inbox is empty.", Bot, how )
end
cls(); return 1;
end



function savemsg()
local function parse(tbl)
local str, tab ="", string.rep( "\t", 9)
local function fquot(s) return string.format( "%q", s) end
local function ncode( s ) if (s ~= "") and (string.sub(s,1,3) ~= "-n#") then local t = {}; for i = 1, string.len(s) do t[i] = string.byte(string.sub(s,i,i)); end; return "-n#"..table.concat(t, "#"); end; return s; end
for a, t in tbl do
str = str.."\t\t{ ["..fquot("read").."] = "..t.read..", ["..fquot("who").."] = "..fquot(ncode(t.who))..", ["..fquot("when").."] = "..fquot(t.when)..",\n\t\t["..fquot("message").."] = "..fquot(ncode(t.message)).." },\n"
end
return str
end
local f = io.open ( "offline.dat", "w+" )
local s = "message = {"
for name, t in message do
s = s.."\n\t["..string.format( "%q", string.gsub( name, "\"", "\"")).."] = {\n"..parse(t).."\t},"
end;
f:write(s.."\n}")
f:close()
end



function SendBack( user, msg, who, pm )
if pm then user:SendPM ( who, msg ); else user:SendData( who, msg ); end
end



function NewUserConnected(user)
if not washere[user.sName] then washere[user.sName] = 1 end
if message[user.sName] then
local cnt=0
for a,b in message[user.sName] do if (b.read == 0) then cnt = cnt+1; end end
if (cnt > 0) then SendBack( user, "You have "..cnt.." new messages. Type !"..cmdibox.." to see your inbox!", Bot, true ); end
end
end



function ChatArrival(user,data)
local data = string.sub( data, 1, -2 )
local _,_,cmd = string.find(data,"%b<>%s+[!+.#?](%S+)")
if cmd then return parsecmds( user, data, string.lower(cmd) ); end
end



function ToArrival(user,data)
if (string.sub( data, 1, string.len(Bot)+5) == "$To: "..Bot) then
local data = string.sub( data, 1, -2 )
local _,_,cmd = string.find(data,"%$%b<>%s+[!+.#?](%S+)")
if cmd then return parsecmds( user, data, string.lower(cmd), true ) end
return 1
end
end




function parsecmds( user, data, cmd, how )
local t = {
[cmdpost] = { postmsg, { user, data, how } },
[cmdread] = { readmsg, { user, data, how } },
[cmdibox] = { inbox, { user, how } },
[cmddbox] = { delmsg, { user, data, how } },
}
if t[cmd] then
return t[cmd][1]( unpack(t[cmd][2]) )
end
end



function UserDisconnected(user)
if not washere[user.sName] then washere[user.sName] = 1; end
end


function OnExit()
savemsg()
local f = io.open( "washere.lst", "w+")
for a,b in washere do f:write(a.."\n"); end
f:close()
end


OpDisconnected=UserDisconnected
OpConnected=NewUserConnected






Thx to Herodes i hope the error is absolutly fixes


for the German Version of this script see skippy.dyndns.ws
Title:
Post by: kash? on 27 May, 2005, 20:00:24
gr8 script !!!
Is it possible when a user sends mail to
another user the other user should get
alert on start that u have mail in inbox
(alert for only unread messages)

waiting for reply...
Title:
Post by: dkt on 30 May, 2005, 22:17:29
i want An alert in pm when a user connects instead of in main chat  as it shows private message from nick and message in main chat but above motd :(
Title:
Post by: Skippy84 on 30 May, 2005, 22:36:03

function NewUserConnected(user)

if not washere[user.sName] then washere[user.sName] = 1 end

if message[user.sName] then

local cnt=0

for a,b in message[user.sName] do if (b.read == 0) then cnt = cnt+1; end end

if (cnt > 0) then SendBack( user, "You have "..cnt.." new messages. Type !"..cmdibox.." to see your inbox!", Bot, true ); end

end

end



Replace with follow code




function NewUserConnected(user)

if not washere[user.sName] then washere[user.sName] = 1 end

if message[user.sName] then

local cnt=0

for a,b in message[user.sName] do if (b.read == 0) then cnt = cnt+1; end end

if (cnt > 0) then user:SendPM(botname, "You have "..cnt.." new messages. Type !"..cmdibox.." to see your inbox!", Bot, true ); end

end

end
Title:
Post by: dkt on 30 May, 2005, 23:10:02
QuoteOriginally posted by Skippy84




probier das mal hoffe das funktioniert




What does this mean ??
Title:
Post by: Skippy84 on 30 May, 2005, 23:25:50
it means i hope the code changes will work


i forgot the info that to do



i edit the upper post



(replace the 1 code with the second)
Title:
Post by: yoonohoo on 30 May, 2005, 23:52:24
Can some1 tell me (and others Ptokax users) which script has been updated and final... for the moment!

I would like to take it for a spin. ;)

Thanks
Title:
Post by: Skippy84 on 31 May, 2005, 00:02:20
have a look at an upper post from me
it was the last version that released here (version0.5)
Title:
Post by: bastya_elvtars on 31 May, 2005, 00:10:44
QuoteOriginally posted by yoonohoo
Can some1 tell me (and others Ptokax users) which script has been updated and final... for the moment!

I would like to take it for a spin. ;)

Thanks

I recommend the one Herodes posted.
Title:
Post by: yoonohoo on 31 May, 2005, 00:47:09
Thank you both.
QuoteI recommend the one Herodes posted.
Because... :D More features, better optimized???
Title:
Post by: bastya_elvtars on 01 June, 2005, 15:52:17
0.51


I recommend this. :P

   -- PostMan Bot 0.3 by bastya_elvtars (the rock n' roll doctor)
    -- offline message system
    -- 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:
    -- converted to lua5
    -- washere is now global, no more CPU spikes



    ------- 0.4:
    -- touched by Herodes (optimisation tsunami)
    -- added : more details on the bot
    -- added : message privacy ;)
    -- changed : better way to parseenv ;)
    -- changed : better way to display messages and inbox
    -- changed : better way to parsecmds ( thx bastya_elvtars ;)

    ------- 0.5:
    -- touched by Skippy84
    -- fix error: make offline.dat thx goto Herodes for the idea to fix the problem
    -- fix error: false command !showmsg
    -- added: commands can edit at the Settings section
    -- added: shown commands linked to the editable commands (so ther change on the fly)

    ------- 0.5:
    -- bastya_elvtars put his hands back on this
    -- script now creates an empty offline.dat if does not exist... you guys keep ignoring new Lua5 features :P
    -- thx guys for the features you added, they are really eye-candy



    --------------------------------SETTINGS----------------------------------------

    Bot = {
    name = "PostMan" , -- bot's name
    email = "postman@mail.me", -- bot's email
    desc = "Post messages to other users here..", -- bot's desc
    }

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

    cmdpost = "postmsg" -- Shows the Hub Stats
    cmdread = "readmsg" -- Shows the Hub Stats
    cmdibox = "inbox" -- Shows the Hub Stats
    cmddbox = "delmsg" -- Shows the Hub Stats



    ----------------------END OF SETTINGS-------------------------------------------





    -------------------------------------- Utility Functions

    function cls()
    collectgarbage()
    io.flush()
    end



    function Main()
    local function load()
    local t = {}; local f = io.open("washere.lst", "r")
    if f then for l in f:lines() do t[l] = 1; end; f:close(); end
    return t;
    end
    washere = load()
    message = {}
if loadfile("offline.dat") then
dofile("offline.dat")
else
io.output("offline.dat")
io.write("")
io.output()
end
    frmHub:RegBot(Bot.name, 1, Bot.desc, Bot.email )
    Bot = Bot.name
    end



    -------------------------------------- Command Functions

    --- post msg

    function postmsg( user, data, how )
    local _,_,nick,msg = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
    if nick then
    if not GetItemByName(nick) then
    if washere[nick] then
    local function checksize(n) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
    if not message[nick] then message[nick] = {}; end
    if (checksize(nick) < inboxsize) then
    table.insert( message[nick], { ["message"] = msg, ["who"] = user.sName, ["when"] = os.date("%Y. %m. %d. %X"), ["read"] = 0, } )
    SendBack( user, "Successfully sent the message!", Bot, how )
    savemsg()
    else
    SendBack( user, "Sorry, but "..nick.." has a full inbox. Try again later.", Bot, how )
    end
    else
    SendBack( user, "User "..nick.." has never been in the hub.", Bot, how )
    end
    else
    SendBack( user, nick.." is online! PM would be simpler in this case...", Bot, how )
    end
    else
    SendBack( user, "Bad syntax! Usage: !"..cmdpost.." ", Bot, how )
    end
    cls(); return 1;
    end



    function delmsg( user, data, how )
    if message[user.sName] then
    local _,_,args = string.find(data,"%b<>%s+%S+%s+(.+)")
    if args then
    local function checksize(n) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
    local function resort(t) local r ={}; for i,v in t do table.insert(r, v); end; return r; end
    for num in string.gfind( args, "%s-(%d+)%s-" ) do
    if num then
    num = tonumber(num);
    if message[user.sName][num] then
    message[user.sName][num] = nil
    SendBack( user, "Message #"..num.." has been successfully deleted!", Bot, how )
    else
    SendBack( user, "Message #"..num.." does not exist!", Bot, how )
    end
    end
    end
    message[user.sName] = resort(message[user.sName]);
    if checksize(user.sName) == 0 then message[user.sName] = nil; end
    savemsg()
    else
    SendBack( user, "Bad syntax! Usage: !"..cmddbox.." . Multiple numbers can be added separated by spaces.", Bot, how )
    end
    else
    SendBack( user, "Your inbox is empty.", Bot, how )
    end
    cls(); return 1;
    end

    ----------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------- show inbox

    function inbox( user, how )
    local sep, msg = string.rep( "=", 75 ), "\r\n\r\n\t\t\t\t\t\t\tHere is your inbox:\r\n"
    msg = msg..sep.."\r\n Msg#\tSender\tTime of sending\t\tRead\r\n"..sep
    if message[user.sName] then
    local function numess ( r ) if r == 0 then return "no"; end return "yes"; end
    local function checksize ( n ) local cnt = 0; for a,b in message[n] do cnt = cnt + 1; end return cnt; end
    local function dcode ( s ) if (string.sub(s,1,3) == "-n#") then s=string.sub(s,4,-1); local res = ""; for num in string.gfind( s, "#?(%d+)") do res = res..string.char(tonumber(num));end;return res;end;return s;end
    for num, t in message[user.sName] do
    msg=msg.."\r\n "..num.."\t"..dcode(t.who).."\t"..t.when.."\t"..numess(t.read).."\r\n"..sep
    end
    SendBack( user, msg, Bot, true )
    SendBack( user, "Type !"..cmdread.." too see an individual message. Multiple numbers can be added separated by spaces.", Bot, true )
    if checksize(user.sName) >= inboxsize then SendBack( user, "Alert: Your inbox is full!", Bot, true ); end
    else
    SendBack( user, "You have no messages.", Bot, how )
    end
    cls(); return 1;
    end



    --- read msg(s)

    function readmsg( user, data, how )
    if message[user.sName] then
    local _,_,args=string.find(data,"%b<>%s+%S+%s+(.+)")
    if args then
    local function dcode(s) if (string.sub(s,1,3) == "-n#") then s = string.sub(s,4,-1);local res = ""; for num in string.gfind( s, "#?(%d+)") do res = res..string.char(tonumber(num));end;return res;end;return s;
    end
    for num in string.gfind( args, "%s-(%d+)%s-" ) do
    if num then num = tonumber(num) end
    if num and message[user.sName][num] then
    local t = message[user.sName][num]
    local msg, sep,set = "\r\n\r\n\t\t\t\t\t\t\tMessage #"..num.."\r\n", string.rep( "=", 100 ), string.rep("- ", 85)
    msg = msg..sep.."\r\n\r\nFrom: "..dcode(t.who).."\tTime: "..t.when.."\t\tMessage follows\r\n"..set.."[Message start]\r\n"..dcode(t.message).."\r\n"..set.."[Message end]\r\n"..sep
    SendBack( user, msg, Bot, true )
    if t.read == 0 then t.read = 1; savemsg(); end
    else
    SendBack( user, "Message #"..num.." does not exist!", Bot, how )
    end
    end
    else
    SendBack( user, "Bad syntax! Usage: !"..cmdread.." . Multiple numbers can be added separated by spaces.", Bot, how )
    end
    else
    SendBack( user, "Your inbox is empty.", Bot, how )
    end
    cls(); return 1;
    end



    function savemsg()
    local function parse(tbl)
    local str, tab ="", string.rep( "\t", 9)
    local function fquot(s) return string.format( "%q", s) end
    local function ncode( s ) if (s ~= "") and (string.sub(s,1,3) ~= "-n#") then local t = {}; for i = 1, string.len(s) do t[i] = string.byte(string.sub(s,i,i)); end; return "-n#"..table.concat(t, "#"); end; return s; end
    for a, t in tbl do
    str = str.."\t\t{ ["..fquot("read").."] = "..t.read..", ["..fquot("who").."] = "..fquot(ncode(t.who))..", ["..fquot("when").."] = "..fquot(t.when)..",\n\t\t["..fquot("message").."] = "..fquot(ncode(t.message)).." },\n"
    end
    return str
    end
    local f = io.open ( "offline.dat", "w+" )
    local s = "message = {"
    for name, t in message do
    s = s.."\n\t["..string.format( "%q", string.gsub( name, "\"", "\"")).."] = {\n"..parse(t).."\t},"
    end;
    f:write(s.."\n}")
    f:close()
    end



    function SendBack( user, msg, who, pm )
    if pm then user:SendPM ( who, msg ); else user:SendData( who, msg ); end
    end



    function NewUserConnected(user)
    if not washere[user.sName] then washere[user.sName] = 1 end
    if message[user.sName] then
    local cnt=0
    for a,b in message[user.sName] do if (b.read == 0) then cnt = cnt+1; end end
    if (cnt > 0) then SendBack( user, "You have "..cnt.." new messages. Type !"..cmdibox.." to see your inbox!", Bot, true ); end
    end
    end



    function ChatArrival(user,data)
    local data = string.sub( data, 1, -2 )
    local _,_,cmd = string.find(data,"%b<>%s+[!+.#?](%S+)")
    if cmd then return parsecmds( user, data, string.lower(cmd) ); end
    end



    function ToArrival(user,data)
    if (string.sub( data, 1, string.len(Bot)+5) == "$To: "..Bot) then
    local data = string.sub( data, 1, -2 )
    local _,_,cmd = string.find(data,"%$%b<>%s+[!+.#?](%S+)")
    if cmd then return parsecmds( user, data, string.lower(cmd), true ) end
    return 1
    end
    end




    function parsecmds( user, data, cmd, how )
    local t = {
    [cmdpost] = { postmsg, { user, data, how } },
    [cmdread] = { readmsg, { user, data, how } },
    [cmdibox] = { inbox, { user, how } },
    [cmddbox] = { delmsg, { user, data, how } },
    }
    if t[cmd] then
    return t[cmd][1]( unpack(t[cmd][2]) )
    end
    end



    function UserDisconnected(user)
    if not washere[user.sName] then washere[user.sName] = 1; end
    end


    function OnExit()
    savemsg()
    local f = io.open( "washere.lst", "w+")
    for a,b in washere do f:write(a.."\n"); end
    f:close()
    end


    OpDisconnected=UserDisconnected
    OpConnected=NewUserConnected