Author Topic: Is this function correct?  (Read 4790 times)

0 Members and 1 Guest are viewing this topic.

Markitos

  • Guest
Is this function correct?
« on: 10 May, 2006, 09:37:23 »
Code: [Select]
[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,
},

PtokaX forum

Is this function correct?
« on: 10 May, 2006, 09:37:23 »

Herodes

  • Guest
Re: Is this function correct?
« Reply #1 on: 10 May, 2006, 13:35:06 »
Code: [Select]
[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
« Last Edit: 12 May, 2006, 10:35:37 by Herodes »

Markitos

  • Guest
Re: Is this function correct?
« Reply #2 on: 12 May, 2006, 09:59:16 »
anyone???

Herodes

  • Guest
Re: Is this function correct?
« Reply #3 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

Markitos

  • Guest
Re: Is this function correct?
« Reply #4 on: 12 May, 2006, 10:56:30 »
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 :-)

Herodes

  • Guest
Re: Is this function correct?
« Reply #5 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 ...

Markitos

  • Guest
Re: Is this function correct?
« Reply #6 on: 13 May, 2006, 10:37:28 »
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
Code: [Select]
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...
Code: [Select]
if tCommands[cmd] then
return tCommands[cmd].tFunc(user, data), 1

Herodes

  • Guest
Re: Is this function correct?
« Reply #7 on: 13 May, 2006, 12:00:01 »
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
Code: [Select]
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...
Code: [Select]
if tCommands[cmd] then
return tCommands[cmd].tFunc(user, data), 1
So this description can be matched with...
Code: [Select]
"%b<>%s*[%+%-%.%!%?%#](%S+)%s+(%S+)%s+(.*)^"I assume that you take the intial filtering ( user, cmd ) out ..
so this turn to
Code: [Select]
"(%S+)%s+(.*)^"did i got it right ?

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 577
  • Karma: +71/-5
Re: Is this function correct?
« Reply #8 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

Markitos

  • Guest
Re: Is this function correct?
« Reply #9 on: 13 May, 2006, 15:45:11 »
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  ???

Markitos

  • Guest
Re: Is this function correct?
« Reply #10 on: 13 May, 2006, 20:20:30 »
Fixed thanks to jiten...heres the updated one...
Code: [Select]
[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,
},

Herodes

  • Guest
Re: Is this function correct?
« Reply #11 on: 13 May, 2006, 21:02:52 »
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 .. :)

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 752
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Is this function correct?
« Reply #12 on: 14 May, 2006, 14:54:38 »
I'd use .+ instead of .*. .* returns "" if the capture cannot be found and can cause trouble.
Everything could have been anything else and it would have just as much meaning.

Offline VidFamne

  • Triple Ace
  • **
  • Posts: 173
  • Karma: +2/-0
Re: Is this function correct?
« Reply #13 on: 14 May, 2006, 15:27:07 »
Wouldnt it be ["ban"] = {..........} or something like that?

Markitos

  • Guest
Re: Is this function correct?
« Reply #14 on: 14 May, 2006, 16:14:21 »
Wouldnt it be ["ban"] = {..........} or something like that?
It can...but *ban* was a var (ban = "ban") removed now...

PtokaX forum

Re: Is this function correct?
« Reply #14 on: 14 May, 2006, 16:14:21 »