This is basically the Lua 5.1.1 version. I am planning to add enhanced message encoding with a master passkey and do further optimization to the message encoding routine. Please test this releae thoroughly and report bugs here, thank you.
Looks Ok !! Thanks bastya i need it ;)
Hello, Bastya...
Gratefulness for the beautiful work in this script... It is one of scripts more useful than I used in my HUB, when it was LUA 5.
In my first test here, the scripts works fine, although not to show the commands to me for the menu of the right button of mouse.
Well... I tried then to change the name of the Script, for the name standard of main mine script (Robocop)... and the problems had started.
After one reboot in the HUB of tests, script soon already initiated with this error:
[22:00] Sintaxe offline.dat:5: table index is nil
This error only started after to change the name of the Script. Returning the name for ?Postman?, the error disappears. I made diverse tests and modifications, but nothing it gave good result. Also I tried to translate into my language the dialogues of it, and other errors had started to appear.
Would be some error in its script, ineptitude mine, or some characteristic of the environment of my Ptokax server, here?
Please, it could see this for us? Anticipatedly I am thankful !
Respectfully,
7P-Darkman
I don't think it should be the name that causes this. I'll investigate tonight.
OK, I have fixed that - please refetch the attachment from the first post.
Added base64 en-/decoding of messages. Passkey is a bad idea, since the mesage file has to be stored on the same server as postman.lua, so the passkey may be trivial to get, so I chose a base64 routine found by Google. I am waiting on 7P-Darkman to confirm that the bug is fixed, then I'll release that beta2.
Hello Bastya...
Yes... really, the bug is fixed... but the menu on right click not yet it functions here? perhaps because I do not call it for generic name ?RC?... I believe.
I will make more tests, and I will try to again translate it? if something of made a mistake to happen, will inform to you, ok?
Respectfully,
7P-Darkman
local RC={"$UserCommand 1 3 :PostMan:\\INBOX$<%[mynick]> !inbox|","$UserCommand 1 3 :PostMan:\\Post a Message$<%[mynick]> !postmsg %[line:Target user:] %[line:Message:]|",
"$UserCommand 1 3 :PostMan:\\Read a Message$<%[mynick]> !readmsg %[line:Enter Nr(s) of Post(s) you would like to read:]|",
"$UserCommand 1 3 :PostMan:\\Delete a Message$<%[mynick]> !delmsg %[line:Enter Nr(s) of Post(s) you would like to delete:]|"}
user:SendData(table.concat(RC,"|"))
This is the only chunk where it occurs, feel free to rename.
Attached is the new version:
Your washere.lst should go to the postman folder. Your offline.dat from older versions has to be deleted. It can no longer be used due to changes in the encoding/decoding routine.
Changelog follows:
added: message encoding done by base64 encoder/decoder (c) 2006 by Alex Kloss
(http://lua-users.org/wiki/BaseSixtyFour) - sorry Herodes
changed: messages are encoded upon sending, thus we prevent decoding/encoding flaws when user comes
online before the first script restart
fixed: corrected some rightclick typos, lingos and made message sending through rightclick a bit more 'intelligent'
changed: created a separate postman folder, not to pollute the scripts dir with washere.lst and offline.dat
If no objection comes, I will make this the final release in 1 week.
Hello Bastya...
Greath job, man!... Right-Click menu works fine here.... but have only one another Bug.
To if trying to read multiple messages, script gives the error:
Comand:
[19:54:21] <7P-Darkman> !readmsg 1 2 3 4 5
Error:
[19:54] Sintaxe C:\Ptokax\scripts\postman_0.7.lua:187: attempt to concatenate local 'num' (a nil value)
A one sugestion:
I find more convenient to order the alert of new message in main chat. I created a new function, and I made tests successfully here... see:
function SendFront( user, msg, who, pm )
if pm then user:SendData( who, msg ); end
end
.
.
.
if (cnt > 0) then SendFront( user, "A T T E N T I O N... You have "..cnt.." new messages. Type !"..cmdibox.." to see your inbox!"", Bot, true ); end
I wait to be collaborating with the improvement of this excellent script
Respectfully,
7P-Darkman
Stupid errors of mine, here is the updated lua file. Fixed, and here is an addition:
added: option for new message alert (PM or main)
Hello Bastya...
Everything is functioning perfectly well now, Bastya? congratulations!
I wait to leave the final version, to prepare a translation for my language, and to become it public.
Respectfully,
7P-Darkman
I will make it multilanguage, just to test that feature as well.
Hello Bastya...
Excellent notice, Bastya... it takes that more Scripters follows its example... congratulations!
I will have much pleasure in making tests, and collaborating in the translation for my language.
Respectfully,
7P-Darkman
thnx
Hello Bastya...
It is possible to restrict the access to the commands, based in profile of user? For example, it would not like that users not-registered had access to the commands of this script.
Respectfully,
7P-Darkman
Hey bastya,
Would like a few additions in this cool script.
1) Is it possible to send same message to more than one user at a time??
If i want to send message to bastya speedx and 7P-darkman, thn the command would be something like this
!postmsg bastya,speedx,7P-darkman <message>
2) Is it possible to make this script in lower case also??
I need lower case bcoz, if an online user is sending a message to an offline user...and the nick of the offline user is "X", and if the online user types "x" thn he gets an error i.e User x has never been in the hub.....
Hope I was clear with my second request....
Thanx in advance
ZZZzzzZZZzzzZZZzzz...
Quote from: speedX on 20 February, 2007, 14:46:50
Would like a few additions in this cool script.
1) Is it possible to send same message to more than one user at a time??
If i want to send message to bastya speedx and 7P-darkman, thn the command would be something like this
!postmsg bastya,speedx,7P-darkman <message>
Not too hard to implement, need to maximize the nuber of such users, though.
Quote from: speedX on 20 February, 2007, 14:46:502) Is it possible to make this script in lower case also??
I need lower case bcoz, if an online user is sending a message to an offline user...and the nick of the offline user is "X", and if the online user types "x" thn he gets an error i.e User x has never been in the hub.....
I'll fix this.
Quote from: 7P-Darkman on 05 March, 2007, 05:07:11
ZZZzzzZZZzzzZZZzzz...
This week. :)
Here comes 0.8 beta. Changelog:
added: mass offline message. Usage: !masspost nick1 nick2 nick3 $message // The trailing dollar sign is important!!!
added: case insensivity for nicks
changed: using chill's extremely handy table.save and table.load routines
changed: checknsend is a separate function for checking and sending
Get it from the download page (http://lawmaker.no-ip.org/pages/downloads.php?dgp=3).
Please report all bugs in the PostMan board (http://lawmaker.no-ip.org/forum/forum.php?id=16&usebb_sid=b63449b728044ac3137ff609b815b8f6).
Hey bastya,
This message "You have 1 new message....." used to come in PM in the previous version.
But in this it comes in Mainchat.
Could you plzz make it come in PM only?
You should REALLY open the postman.lua file and edit the configuration values after reading the comments belonging to them.
Set this:
newalertPM=true
Note that rightclicks are a bit b0rked. I already have them fixed, but I don't think it's worh a new zip. Test first by hand. :P
Quote from: bastya_elvtars on 25 March, 2007, 00:56:30
You should REALLY open the postman.lua file and edit the configuration values after reading the comments belonging to them.
Set this:
newalertPM=true
Oh yes, silly me :P
Hey bastya,
This case insensivity doesnt seem to be working.
Quote
[10:25] <HOPS> You have 1 new messages. Type !inbox to see your inbox!
[10:25] <AloK> !inbox
[10:25] <HOPS> You have no messages.
but when i login with nick "alok", it shows me the message...
Quote
[10:28] <HOPS> You have 1 new messages. Type !inbox to see your inbox!
[10:28] <alok> !inbox
[10:28] <HOPS>
Here is your inbox:
===========================================================================
Msg# Sender Time of sending Read
===========================================================================
1 speedx 2007. 03. 25. 10:25:02 no
===========================================================================
[10:28] <HOPS> Type !readmsg <number> too see an individual message. Multiple numbers can be added separated by spaces.
Please test this code.
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
mass_max_users=5 -- When sending a mass offline mail, how many recipients may be specified at once?
-- Where should the 'new message' alert appear? If true then PM, if false then main.
newalertPM=false
cmdpost = "postmsg" -- Post
cmdmass = "masspost" -- Mass post, i. e. post the same message to more recipients
cmdread = "readmsg" -- Read
cmdibox = "inbox" -- Inbox
cmddbox = "delmsg" -- Delete
----------------------END OF SETTINGS-------------------------------------------
-- Load the base64 library (argh I keep wondering why package.cpath is the Px folder, but I live with it)
require "scripts.postman.base64"
require "scripts.postman.tables"
-------------------------------------- Utility Functions
function cls()
collectgarbage("collect")
io.flush()
end
function Main()
local function load()
local t = {}; local f = io.open("postman/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("postman/offline.dat") then
message=table.load("postman/offline.dat")
else -- replace corrupted offline.dat
table.save(message,"postman/offline.dat")
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 = data:match("%b<>%s+%S+%s+(%S+)%s+(.+)")
if nick then
checknsend (user,nick,msg)
else
SendBack( user, "Bad syntax! Usage: !"..cmdpost.." <nick> <message>", Bot, how )
end
cls(); return 1;
end
function checknsend (user,nick,msg)
nick=nick:lower()
if not GetItemByName(nick) then
if washere[nick] then
local function checksize(n) local cnt = 0; for a,b in pairs(message[n]) do cnt = cnt + 1; end return cnt; end
message[nick] = message[nick] or {}
if (checksize(nick) < inboxsize) then
table.insert( message[nick], { ["message"] = encode(msg), ["who"] = encode(user.sName), ["when"] = os.date("%Y. %m. %d. %X"), ["read"] = 0, } )
SendBack( user, "Successfully sent the message!", Bot, how )
table.save(message,"postman/offline.dat")
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
end
function masspost ( user, data, how)
local nicks,msg=data:match("%b<>%s+%S+%s+([^%$]+)%$(.+)")
if nicks then
local _,no_args = string.gsub(nicks,"(%S+)","")
if no_args > mass_max_users then
SendBack( user, "Too many nicks specified, maximum number of nicks you can specify is "..mass_max_users.." and you specified "..no_args..".", Bot, how )
return
end
for nick in string.gmatch(nicks,"(%S+)") do
checknsend (user,nick:lower(),msg)
end
end
end
function delmsg( user, data, how )
if message[user.sName:lower()] then
local args = data:match("%b<>%s+%S+%s+(.+)")
if args then
local function checksize(n) local cnt = 0; for a,b in pairs(message[n]) do cnt = cnt + 1; end return cnt; end
local function resort(t) local r ={}; for i,v in pairs(t) do table.insert(r, v); end; return r; end
local bDeleted=false
for num in args:gmatch( "(%d+)" ) do
num = tonumber(num);
if message[user.sName:lower()][num] then
message[user.sName:lower()][num] = nil
SendBack( user, "Message #"..num.." has been successfully deleted!", Bot, how )
bDeleted=true
else
SendBack( user, "Message #"..num.." does not exist!", Bot, how )
end
end
message[user.sName:lower()] = resort(message[user.sName:lower()]);
if checksize(user.sName:lower()) == 0 then message[user.sName:lower()] = nil; end
if bDeleted then table.save(message,"postman/offline.dat") end
else
SendBack( user, "Bad syntax! Usage: !"..cmddbox.." <msgnumber>. 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 = ( "="):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:lower()] 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 pairs(message[n]) do cnt = cnt + 1; end return cnt; end
for num, t in pairs(message[user.sName:lower()]) do
msg=msg.."\r\n "..num.."\t"..decode(t.who).."\t"..t.when.."\t"..numess(t.read).."\r\n"..sep
end
SendBack( user, msg, Bot, true )
SendBack( user, "Type !"..cmdread.." <number> too see an individual message. Multiple numbers can be added separated by spaces.", Bot, true )
if checksize(user.sName:lower()) >= 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:lower()] then
local args=data:match("%b<>%s+%S+%s+(.+)")
if args then
for num in args:gmatch( "(%d+)" ) do
if num then num = tonumber(num) end
if num and message[user.sName:lower()][num] then
local t = message[user.sName:lower()][num]
local msg, sep,set = "\r\n\r\n\t\t\t\t\t\t\tMessage #"..num.."\r\n", ("="):rep( 100 ), ("- "):rep(85)
msg = msg..sep.."\r\n\r\nFrom: "..decode(t.who).."\tTime: "..t.when.."\t\tMessage follows\r\n"..set.."[Message start]\r\n"..decode(t.message).."\r\n"..set.."[Message end]\r\n"..sep
SendBack( user, msg, Bot, true )
if t.read == 0 then t.read = 1; table.save(message,"postman/offline.dat"); end
else
SendBack( user, "Message #"..num.." does not exist!", Bot, how )
end
end
else
SendBack( user, "Bad syntax! Usage: !"..cmdread.." <msgnumber>. 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 SendBack( user, msg, who, pm )
if pm then user:SendPM ( who, msg ); else user:SendData( who, msg ); end
end
function NewUserConnected(user)
local RC={"$UserCommand 1 3 :PostMan:\\INBOX$<%[mynick]> !"..cmdibox.."|","$UserCommand 1 3 :PostMan:\\Post a Message$<%[mynick]> "..cmdpost.." %[line:Target user:] %[line:Message:]|",
"$UserCommand 1 3 :PostMan:\\Read a Message$<%[mynick]> !"..cmdread.." %[line:Enter Nr(s) of Post(s) you would like to read:]|",
"$UserCommand 1 3 :PostMan:\\Delete a Message$<%[mynick]> !"..cmddbox.." %[line:Enter Nr(s) of Post(s) you would like to delete:]|",
"$UserCommand 1 3 :PostMan:\\Post the same message to more users$<%[mynick]> !"..cmdmass.." %[line:Enter usernames separated by spaces:] $%[line:Enter the message:]|"}
user:SendData(table.concat(RC,"|"))
user:SendData(":PostMan:", "New Right-Click for Postman is Available..")
if not washere[user.sName:lower()] then washere[user.sName:lower()] = 1 end
if message[user.sName:lower()] then
local cnt=0
for a,b in pairs(message[user.sName:lower()]) 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, newalertPM ); end
end
end
function ChatArrival(user,data)
local data = data:sub(1,-2)
local cmd = data:match("%b<>%s+[!+.#?](%S+)")
if cmd then return parsecmds( user, data, cmd:lower() ); end
end
function ToArrival(user,data)
if (data:sub( 1, Bot:len()+5) == "$To: "..Bot) then
local data = data:sub(1,-2)
local cmd = data:match("%$%b<>%s+[!+.#?](%S+)")
if cmd then return parsecmds( user, data, cmd:lower(), 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 } },
[cmdmass] = { masspost, { user, data, how } },
}
local c=t[cmd]
if c then
c[1]( unpack(c[2]))
return 1
end
end
function UserDisconnected(user)
if not washere[user.sName:lower()] and user.bConnected then washere[user.sName:lower()] = 1; end
end
function OnExit()
table.save(message,"postman/offline.dat")
cls()
local f = io.open( "postman/washere.lst", "w+")
f:setvbuf("line")
for a,b in pairs(washere) do f:write(a.."\n"); end
f:close()
end
OpDisconnected=UserDisconnected
OpConnected=NewUserConnected
Quote from: bastya_elvtars on 24 March, 2007, 18:10:18
Here comes 0.8 beta. Changelog:
added: mass offline message. Usage: !masspost nick1 nick2 nick3 $message // The trailing dollar sign is important!!!
added: case insensivity for nicks
changed: using chill's extremely handy table.save and table.load routines
changed: checknsend is a separate function for checking and sending
Get it from the download page (http://lawmaker.no-ip.org/pages/downloads.php?dgp=3).
Please report all bugs in the PostMan board (http://lawmaker.no-ip.org/forum/forum.php?id=16&usebb_sid=b63449b728044ac3137ff609b815b8f6).
Link doesnt work :(