PtokaX forum

Development Section => Your Developing Problems => Topic started by: Markitos on 10 May, 2006, 09:37:23

Title: Is this function correct?
Post by: Markitos on 10 May, 2006, 09:37:23
[ban] = {
tFunc = function(user,data)
if user.bOperator then
local who,reason = string.find(data,"%s(%S+)%s(%S+)")
if who and reason then
local victim = GetItemByName(who)
if not victim.bRegistered then
SendPmToOps(Bot, "*** The user: "..who.." has been timebanned by "..user.sName.."")
SendToAll(Bot, curUser.sName.." timebanned user "..who.." for: "..timeban.." mins")
victim:SendPM(Bot, "You are timebanned for "..timeban.." minutes by "..user.sName..")
victim:Ban(timeban)
end
end
end
end,
},
Title: Re: Is this function correct?
Post by: Herodes on 10 May, 2006, 13:35:06
[ban] = {
tFunc = function(user,data)
if user.bOperator then
local who,reason = string.find(data,"%s(%S+)%s(%S+)")
if who and reason then
local victim = GetItemByName(who)
if victim and not victim.bRegistered then
SendPmToOps(Bot, "*** The user: "..who.." has been timebanned by "..user.sName)
SendToAll(Bot, user.sName.." timebanned user "..who.." for: "..timeban.." mins")
victim:SendPM(Bot, "You are timebanned for "..timeban.." minutes by "..user.sName)
victim:Ban(timeban)
end
end
end
end,
},
Problems with the quotes ...
*** [edited] 12/5@12:33
Title: Re: Is this function correct?
Post by: Markitos on 12 May, 2006, 09:59:16
anyone???
Title: Re: Is this function correct?
Post by: Herodes on 12 May, 2006, 10:37:01
Go on test it now ... and when scripting please make breaks :)

There were some problems with quoting strings and you had a mis-pasted 'curUser' instead of 'user' object
Title: Re: Is this function correct?
Post by: Markitos on 12 May, 2006, 10:56:30
Quote from: Herodes on 12 May, 2006, 10:37:01
Go on test it now ... and when scripting please make breaks :)

There were some problems with quoting strings and you had a mis-pasted 'curUser' instead of 'user' object
The script doesnt report any err but dont work either...
I do make brakes...and about that object i did fix it :-)
Title: Re: Is this function correct?
Post by: Herodes on 12 May, 2006, 11:11:54
Make sure that there are values assigned when doing : local who,reason = string.find(data,"%s(%S+)%s(%S+)")

try posting a sample of the values you expect with the 'data' variable ...
Title: Re: Is this function correct?
Post by: Markitos on 13 May, 2006, 10:37:28
Quote from: Herodes on 12 May, 2006, 11:11:54
Make sure that there are values assigned when doing : local who,reason = string.find(data,"%s(%S+)%s(%S+)")

try posting a sample of the values you expect with the 'data' variable ...
1st the <> between the nick
2nd a space
3rd a pontuation char (prefix)
4th alphanumeric char (command) + repetitions
local s,e,cmd = string.find(data,"%b<>%s%p(%w+)")
5th non-spac char(victim to ban) + rep.
6th space
7th non- space char (reason) - on or more rep.
but in my script commands are in a table so...
if tCommands[cmd] then
return tCommands[cmd].tFunc(user, data), 1
Title: Re: Is this function correct?
Post by: Herodes on 13 May, 2006, 12:00:01
Quote from: Markitos on 13 May, 2006, 10:37:28
Quote from: Herodes on 12 May, 2006, 11:11:54
Make sure that there are values assigned when doing : local who,reason = string.find(data,"%s(%S+)%s(%S+)")

try posting a sample of the values you expect with the 'data' variable ...
1st the <> between the nick
2nd a space
3rd a pontuation char (prefix)
4th alphanumeric char (command) + repetitions
local s,e,cmd = string.find(data,"%b<>%s%p(%w+)")
5th non-spac char(victim to ban) + rep.
6th space
7th non- space char (reason) - on or more rep.
but in my script commands are in a table so...
if tCommands[cmd] then
return tCommands[cmd].tFunc(user, data), 1

So this description can be matched with...
"%b<>%s*[%+%-%.%!%?%#](%S+)%s+(%S+)%s+(.*)^"
I assume that you take the intial filtering ( user, cmd ) out ..
so this turn to
"(%S+)%s+(.*)^"
did i got it right ?
Title: Re: Is this function correct?
Post by: jiten on 13 May, 2006, 13:07:39
Markitos, do you string.sub data's endpipe? If not, it must be added to the string.find.

And regarding Herodes', shouldn't it be $ instead of ^ in the end of the string? :P
Title: Re: Is this function correct?
Post by: Markitos on 13 May, 2006, 15:45:11
Quote from: jiten on 13 May, 2006, 13:07:39
Markitos, do you string.sub data's endpipe? If not, it must be added to the string.find.

And regarding Herodes', shouldn't it be $ instead of ^ in the end of the string? :P
Already string.sub and changed the pattern but nothing yet...something tells me that herodes pattern is wrong  ???
Title: Re: Is this function correct?
Post by: Markitos on 13 May, 2006, 20:20:30
Fixed thanks to jiten...heres the updated one... [ban] = {
tFunc = function(user,data)
if user.bOperator then
local s,e,who,reason = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if who and reason then
local victim = GetItemByName(who)
if victim and victim.bOperator then
return user:SendData(sBot, "*** You can't ban an OP"),1
else
victim:SendPM(user.sName, "You are being banned Reason: "..reason)
SendToOps(sBot, user.sName.." is banning <"..who.."> Reason: "..reason.." - IP: "..victim.sIP)
victim:Ban()
end
end
end
end,
},
Title: Re: Is this function correct?
Post by: Herodes on 13 May, 2006, 21:02:52
Quote from: jiten on 13 May, 2006, 13:07:39
Markitos, do you string.sub data's endpipe? If not, it must be added to the string.find.

And regarding Herodes', shouldn't it be $ instead of ^ in the end of the string? :P
true as hell ... i've been out too long and haven't realised how easy it is to forget the details .. :)
Title: Re: Is this function correct?
Post by: bastya_elvtars on 14 May, 2006, 14:54:38
I'd use .+ instead of .*. .* returns "" if the capture cannot be found and can cause trouble.
Title: Re: Is this function correct?
Post by: VidFamne on 14 May, 2006, 15:27:07
Wouldnt it be ["ban"] = {..........} or something like that?
Title: Re: Is this function correct?
Post by: Markitos on 14 May, 2006, 16:14:21
Quote from: VidFamne on 14 May, 2006, 15:27:07
Wouldnt it be ["ban"] = {..........} or something like that?
It can...but *ban* was a var (ban = "ban") removed now...