Is this function correct?
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Is this function correct?

Started by Markitos, 10 May, 2006, 09:37:23

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Markitos

[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,
		},

Herodes

#1
[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

Markitos


Herodes

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

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 :-)

Herodes

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

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

Herodes

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 ?

jiten

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

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  ???

Markitos

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,
	},

Herodes

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 .. :)

bastya_elvtars

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.

VidFamne

Wouldnt it be ["ban"] = {..........} or something like that?

Markitos

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...

SMF spam blocked by CleanTalk