PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: Thor on 24 June, 2006, 16:49:33

Title: vicarious
Post by: Thor on 24 June, 2006, 16:49:33
This is an offline messanger script, but different from the existing scripts: if the script is enabled to the operator (just operators can use), the hub will register a bot in the hub with the op's name, and with the given prefix (optionally). If you don't use prefix on the hub, set the originalprefix and offprefix in the start of the script to "". So, the script register a bot on the hub, while the op is offline, and it recieves the private messages. When the op log in to the hub, script will inform him/her, if he/she has new messages, and he/she can read it with the !or command. After reading, the message(s) easily can delete with the !od command. The script contains an e-mail part (stripped from TTB-s Hub-backup script, thanks to him ;)) which will send an e-mail to the given e-mail adress when the maximum number of messages reached. The e-mail adress and the maximum number of messages can set up with commands, just check the help of the script (with !oh command,when script started, it will be send to the ops). And, optionally, you can set up an away message, that will send to the users, when they write to the "clone-op" bot. Because the e-mail sending part, scripts needs some external file (blat files), so please download the attachment, or download it from the script database: http://ptxscriptdb.psycho-chihuahua.net/download.php?view.260 If you get it, just unpack it to the scripts folder, start it and enjoy. This script works with LUA 5.02 and with LUA 5.1.1 also. If you have some problem, write here ;)
Title: Re: vicarious
Post by: Markitos on 24 June, 2006, 18:18:22
Hi m8!
Your script does not seem to work. It shows me 0 messages when i log on but i already wrote something in the "Clone-OP".
I got some requests,opinions and doubts:

local line = file:read()
curUser:SendPM(bot,"\r\n"..border.."\r\n\t\t\tNEW MESSAGES WHILE YOU WERE OFFLINE: (TOTALLY: "..offlineops[curUser.sName]["settings"]["msgs"]..")\r\n"..border.."\r\n")
while line do
curUser:SendPM(bot,line)
line = file:read()
end


Why are you reading 2 times the file? Is it the correct form ???
function OpDisconnected(curUser)
if offlineops[curUser.sName] ~= nil then
if offlineops[curUser.sName] ~= nil then
  ;D
bot = frmHub:GetHubBotName()
offprefix = "[OP]"
originalprefix = "[OP]"

This could be in a table + that border locals could be in the "table" as globals assuming that you are using several times in the script.

local _,_,sPrefix,sComd,sParam = string.find(msg,"([%!%+%#%?%-])(%S+)%s*(.*)") Could be changed to %p

Commands in a table wouldn't be better too?Less mem usage   ::)

I saw too that the changes that a user make in his settings are only saved to the file on PX exit...Maybe you could use a serialize func. (i HATE file handling)

And to finish NICE IDEAS!!! BTW this are only requests, opinions and doubts  ;) :D

Title: Re: vicarious
Post by: Thor on 24 June, 2006, 18:27:57
Ehh, you've right... Before i ended the script there was an other value in the table: on with value true or false bool. I removed it, because that was unnecessary, but on the code other parts i was careless, and i didn't remove all. I will correct it a.s.a.p., thanks the report. The serialize function is really unknown for me, and this version works well enough to me. So, you want to change the prefix while script running? That's possible, easy to do. And why i have to put the commands into a table? Why this not good? :o
Title: Re: vicarious
Post by: Markitos on 24 June, 2006, 18:47:51
Quote from: Hungarista on 24 June, 2006, 18:27:57
Ehh, you've right... Before i ended the script there was an other value in the table: on with value true or false bool. I removed it, because that was unnecessary, but on the code other parts i was careless, and i didn't remove all. I will correct it a.s.a.p., thanks the report. The serialize function is really unknown for me, and this version works well enough to me. So, you want to change the prefix while script running? That's possible, easy to do. And why i have to put the commands into a table? Why this not good? :o
Commands in a table wouldn't be better too?Less mem usage Roll Eyes

Ill keep wating 4 your progress...
Title: Re: vicarious
Post by: Thor on 25 June, 2006, 09:41:31
Less memory ??? I made all command to local vars, and not global... If i make a global table, it will use more memory ;D
Title: Re: vicarious
Post by: Thor on 25 June, 2006, 10:37:03
By the way could you say me what this serialize function is doing? I looked for that, and it handle files also... Please say me more about this, and i will build in it to my script. Thanks
Title: Re: vicarious
Post by: Markitos on 25 June, 2006, 11:50:02
Quote from: Hungarista on 25 June, 2006, 09:41:31
Less memory ??? I made all command to local vars, and not global... If i make a global table, it will use more memory ;D
You can make a local table inside the chatarrival func check this http://forum.ptokax.org/index.php?topic=5206#new
Quote from: Hungarista on 25 June, 2006, 10:37:03
By the way could you say me what this serialize function is doing? I looked for that, and it handle files also... Please say me more about this, and i will build in it to my script. Thanks
You could format format the user settings file in a more formal way like
tOffline = {
[Nick Name] = {
[email] = user.sEmail
[description] = user.sDescription
[awaymsg] = message
}
}

instead of Estranho_para_ti?y@blabla.com?0?15?Ba Bye
Title: Re: vicarious
Post by: Madman on 25 June, 2006, 11:54:13
Quote from: Markitos on 24 June, 2006, 18:18:22
Commands in a table wouldn't be better too?Less mem usage ? ::)

What he means is that he thinks you should do like this,


function ChatArrival(curUser, data)
local data = string.sub(data, 1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+](%S+)") -- Find commands
if cmd then -- Found command
cmd = string.lower(cmd)
local tCmds = { -- Here is all commands
["help"] = function(curUser, data)
local Profile = GetProfileName(curUser.iProfile)
if curUser.iProfile == -1 then Profile = "User" end
local f = io.input("MadSecurity/Txt/Help" ..Profile.. ".txt")
local line = string.gsub(f:read("*all"), "\n", "\r\n")f:close()
curUser:SendPM(tConfig.Bot.Name, line) return 1
end,
["rules"] = function(curUser, data)
local f = io.input("MadSecurity/Txt/Rules.txt")
local line = string.gsub(f:read("*all"), "\n", "\r\n")f:close()
curUser:SendPM(tConfig.Bot.Name, line) return 1
end,
}
if tCmds[cmd] then -- If the command was in table
return tCmds[cmd](curUser, data) -- Then execute it...
end
Title: Re: vicarious
Post by: Markitos on 25 June, 2006, 11:58:26
Quote from: Madman on 25 June, 2006, 11:54:13
Quote from: Markitos on 24 June, 2006, 18:18:22
Commands in a table wouldn't be better too?Less mem usage   ::)

What he means is that he thinks you should do like this,


function ChatArrival(curUser, data)
local data = string.sub(data, 1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+](%S+)") -- Find commands
if cmd then -- Found command
cmd = string.lower(cmd)
local tCmds = { -- Here is all commands
["help"] = function(curUser, data)
local Profile = GetProfileName(curUser.iProfile)
if curUser.iProfile == -1 then Profile = "User" end
local f = io.input("MadSecurity/Txt/Help" ..Profile.. ".txt")
local line = string.gsub(f:read("*all"), "\n", "\r\n")f:close()
curUser:SendPM(tConfig.Bot.Name, line) return 1
end,
["rules"] = function(curUser, data)
local f = io.input("MadSecurity/Txt/Rules.txt")
local line = string.gsub(f:read("*all"), "\n", "\r\n")f:close()
curUser:SendPM(tConfig.Bot.Name, line) return 1
end,
}
if tCmds[cmd] then -- If the command was in table
return tCmds[cmd](curUser, data) -- Then execute it...
end

Indeed, but this local s,e,cmd = string.find(data, "%b<>%s+[%!%+](%S+)") could be changed to
local s,e,cmd = string.find(data, "%b<>%s*%p(%w+)") (Whatever there are many ways aight?)
return tCmds[cmd](curUser, data),1 returning 1 here would avoid many inside the table
Title: Re: vicarious
Post by: jiten on 25 June, 2006, 18:55:11
Quote from: Markitos on 25 June, 2006, 11:50:02
You could format format the user settings file in a more formal way like
tOffline = {
[Nick Name] = {
[email] = user.sEmail
[description] = user.sDescription
[awaymsg] = message
}
}

instead of Estranho_para_ti?y@blabla.com?0?15?Ba Bye

Hint:

If you expect a huge database, it's better to leave as it is (Hungarista's structure), so that it won't grow [file size] massively.
If not, you could use the Serialize or other custom function.
Title: Re: vicarious
Post by: Thor on 12 July, 2006, 17:06:00
The working version is avaible now. I tried to modifiy as Markitos asked, but in ToArrival is impossible to find out, what was the users originally prefix... So now the bot will use the same nickname as the op has, and if you want to say to the users, that this is a bot, write it to the away message. This serialize function also strange for me yet, and this way works also, so i don't know why that way better.. I dont except big databases, maybe on ophubs, but this works as it has to. You can brave to call me lazy, but i dont want to complicate it. (the code is opened, feel free to modify, just don't forget my name ;D)
Title: Re: vicarious
Post by: speedX on 13 October, 2006, 21:40:20
When a user enable's this script for himself and goes offline, he get's the messages. But when he comes online and the script is still enabled, and if some one PM's him thn he doesn't get those PM's.

Is it possible tht when tht user come's online, the script is auto-disabled only while he is online and again auto-enabed when he goes offline ??

(if possible plzz convert this to Lua 5.1)
Title: Re: vicarious
Post by: dougvcd on 07 January, 2007, 22:51:24
please please need some help with this prog
the prob i have is i enable the offline prog thengo off line
when i try to log back on it wont let me says nick is being used
please what do i have to do
very urgent
cheers
Doug uk
Title: Re: vicarious
Post by: Thor on 07 January, 2007, 23:52:24
Yes, old versions never works more on newer PtokaX (0.3.5.2. and after), because:
Fixed: Few bugs related to reserved nicks (thx -RICK- for report).
New version is avaible, not tested, but it has to work :)
-> CLICK <- (http://forum.ptokax.org/index.php?topic=6704.0)
Title: Re: vicarious
Post by: dougvcd on 08 January, 2007, 14:48:32
a big thank you worked fine
cheers
Doug uk
Title: Re: vicarious
Post by: Thor on 08 January, 2007, 16:24:08
Nice to hear, if you have problem with it, please post there.