Resolving Reason from this local's... plz help...
 

Resolving Reason from this local's... plz help...

Started by NightLitch, 07 November, 2003, 20:10:05

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NightLitch

I get everyting working here, Exept when forgeting rule and want reason from this:  !kick nick reason don't work

becouse local rule snaps up the reason on command...

!kick nick rule reason --works

!kick nick --work

!kick nick rule --work

but not

!kick nick reason

this I want help with...

here my regexp's


local s,e,cmd,nick = strfind( data, "%b<>%s+(%S+)%s+(%S+)" ) 
	if (nick == "" or nick == nil) then
		curUser:sendmessage(BOTNAME,"Syntax: "..PREFIXA.."kick   [reason]")
		return 1
	end
	local s,e,rule = strfind( data, "%b<>%s+%S+%s+%S+%s+(%S+)" )
	if (rule == nil or rule == "") then rule = "Not given"
	else rule = ""..rule
	end
	local s,e,reason = strfind( data, "%b<>%s+%S+%s+%S+%s+%S+%s+(.*)" ) 
	if (reason == "" or reason == nil) then reason = "for no reason"
	else reason = ""..reason


plz help me...

/NightLitch
//NL

NightLitch

//NL

NightLitch

This is frustrating...

How Am I going to do this...

If I forget typing rule and not reason....

if forgeting rule then the sentence in my reason checks if
it is right with the rule... and causes reason to be: for no reason... how can I fix this...
//NL

NightLitch

plz guys help me...

local s,e,cmd,nick = strfind( data, "%b<>%s+(%S+)%s+(%S+)" ) 
	if (nick == "" or nick == nil) then
		curUser:sendmessage(BOTNAME,"Syntax: "..PREFIXA.."kick   [reason]")
		return 1
	end
		local s,e,rule = strfind( data, "%b<>%s+%S+%s+%S+%s(%S+)" )
		SendToAll(rule)
		if (rule == nil or rule == "") then rule = "Not given"
		else rule = ""..rule
		end

		local s,e,reason = strfind( data, "%b<>%s+%S+%s+%S+%s+%S+%s*(.*)" ) 
		if (reason == "" or reason == nil) then reason = "for no reason"
		else reason = ""..reason
		end



Hope I explained myself enough up there to understand me...

/NightLitch
//NL

tezlo

ok.. with the help of the manual (Patterns)

all commands come in this format..
so this or this is what i do..
local s, e, cmd, args = strfind(data, "^%b<> %!(%S+)%s*(.*)%|$")
                                             ^^ ^^^ ^^^ ^^
                                             |   |   |   |
                                             |   |   |   any arguments (not required)
                                             |   |   any spaces (not required)
                                             |   command (required)
                                             hardcoded prefix (required.. could be [%!%+] whatever)

each command only needs to know who is executing it and with what arguments
this also makes it easier for syntax cheching
function doKickoranyothercommand(user, args)
local s, e, nick, reason = strfind(args, "(%S+)%s*(.*)")
                                           ^^^ ^^^ ^^
                                            |   |   |
                                            |   |   any reason (not required)
                                            |   any spaces
                                            nick (required)
if not s then show_syntax() return 1 end
if not GetItemByName(nick) then say_user_is_not_online() return 1 end
..

i only see you using %S+
which is not always what you need
the manual says..

%s - represents all space characters.
..
For all classes represented by single letters (%a, %c, ...), the corresponding upper-case letter represents the complement of the class.
For instance, %S represents all non-space characters.

kepp

local s,e,cmd,nick = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
	if (nick == "" or nick == nil) then
		curUser:sendmessage(BOTNAME,"Syntax: "..PREFIXA.."kick   [reason]")
		return 1
	end
		local s,e,rule = strfind( data, "%b<>%s+(%S+)" )
		SendToAll(rule)
		if (rule == nil or rule == "") then rule = "Not given"
		else rule = ""..rule
		end

		local s,e,reason = strfind( data, "%b<>%s*(.*)" )
		if (reason == "" or reason == nil) then reason = "for no reason"
		else reason = ""..reason
		end

??
Guarding    

NightLitch

#6
I feel so missunderstand....

I know what I have done...

And it is nothing wrong...

This is my explaination in my words... hope you got that... :-)

--// This regxep feel's the (!kick) & (nick) written in Chat...
local s,e,cmd,nick = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
--                                        |   |   |    |
--                                     SPACE CMD SPACE NICK
--                                %b<> I don't know...
--
--// If nick NIL then this function takes action
	if (nick == "" or nick == nil) then
		curUser:sendmessage(BOTNAME,"Syntax: "..PREFIXA.."kick   [reason]")
		return 1
	end

--// If there is more "text" written in command then this take action...
--// This is the regexp for rule (!kick),(nick) from above is the first two %S+ and %s+ is the spaces
--// (%S+) feels if rule have been written in chat... If Not... then rule = "Not Given"
		local s,e,rule = strfind( data, "%b<>%s+%S+%s+%S+%s(%S+)" )
--                                                    1  2  3  4  5  6
--// Explaination: 1 = Space, 2 = CMD, 3 = Space 4 = Nick, 5 = Space & 6 is RULE

--// Debug see how the outcome of rule is...
		SendToAll(rule)

--// Eplained above....
		if (rule == nil or rule == "") then rule = "Not given"
		else rule = ""..rule
		end

--// And the same goes here with the 123456..... for Reason
		local s,e,reason = strfind( data, "%b<>%s+%S+%s+%S+%s+%S+%s*(.*)" ) 
		if (reason == "" or reason == nil) then reason = "for no reason"
		else reason = ""..reason
		end
--// END

I want to know how I can bypass rule if rule is forgotten and get the typed letters to be reason... Understand me????....

As I wrote up there:

!kick nick rule reason --works (rule = rule & reason = reason)

!kick nick --work (rule = "Not Given" & reason = "For No Reason"

!kick nick rule --work (rule = rule & reason if forgotten so NIL = "For No Reason"

!kick nick reason --not work (outcome is: reason is being rule but not found in the Table later so outcome "Not Given"


So my problem IS.... to bypass rule...

I tested as above check rule before doing the local s,e,rule if rule is accepted in rule-table if then

local s,e,reason = strfind( data, "%b<>%s+%S+%s+%S+%s+%S+%s*(.*)" )

but when

else    ( If not rule given, I tried this:)

reason = rule

local s,e,reason = strfind( data, "%b<>%s+%S+%s+%S+%s*(.*)" )

but then the thing is rule had regexp (%S+) so only first word get's in the reason... and if I try (.*) or (.+) then it's not working if I want the hole sentence...

!kick nick rule reason    becouse rule is being nil:ed... becouse of it's not a number... that I have in the rule-table... it's being the reason then.... but don't work with the hole sentence as i desc.

plz help...

/NightLitch
//NL

klownietklowniet

I must say that I didn't understand much from that. But if rule is a number and you extract something that converted to number gives nil, then you know that it's not a rule but a reason. So maybe you can use that... ;-)
[ > DC - UniteD < ]

tezlo

#8
well the code doesnt make much sense to me
i just tried to explain a logical way of doing the same..

ie in this piece of code..
local s,e,cmd,nick = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
if (nick == "" or nick == nil) then -- something

nick can never be equal to "" (an empty string)
same with rule later on

read up on regexp a bit please
you could do with just one..

local s,e,cmd,nick,reason = strfind(data, "%b<> %!(%S+)%s(%S+)%s*(.*)")
but what i explained is a bit more efficient

NightLitch

Gaaaaa.....   I hate my english....

or was it my code you didn't understand... ;-)

if I do it like this then


local s,e,rule = strfind( data, "%b<>%s+%S+%s+%S+%s(%d+)" )

(%d+) or (%d)



What should it be??

and for reason

local s,e,reason = strfind( data, "%b<>%s+%S+%s+%S+%s+%d+%s*(.*)" )

%d+ or %d


/NightLitch
//NL

NightLitch

#10
you missing the rule thing Tezlo or????

reson is no problem...

That I have understand and learnd but:

if I forgot rule between nick & reason I want it to work... got it??

can I get it to work then with this:

local s,e,cmd,nick,rule,reason = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(%d+)%s*(.*)" )

???

if %d+ not with then number nil and then rule = "Not Given and

Reason works either way??
//NL

tezlo

yea i kind of missed the rule thing..
whats it doing there ?

as for %d+ or %d
%d will match one number
%d+ will match one or more numbers
%d* will match no/any numbers

its all in the manual

NightLitch

got it to work with this regexp:


   local s,e,cmd,nick,rule,reason = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(%d*)%s*(.*)" )


This is my hole test function

function dotest(curUser, data, cmd)
	local s,e,cmd,nick,rule,reason = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(%d*)%s*(.*)" )
	if (nick == "" or nick == nil) then
		curUser:sendmessage(BOTNAME,"Syntax: "..PREFIXA.."kick   [reason]")
		return 1
	end

		SendToAll(rule)
		if (rule == nil or rule == "") then rule = "Not given"
		else rule = ""..rule
		end

		if (reason == "" or reason == nil) then reason = "for no reason"
		else reason = ""..reason
		end


	local vUser = GetItemByName(nick)
	if not vUser then
		curUser:sendmessage(BOTNAME,nick.." is not online or wrong name...")
		return 1
	end


	if OPKICKING == "enable" then
		if vUser.bOperator then
			curUser:sendmessage(BOTNAME,"***You Can't Kick an Operator")
			return 1
		else
		end
	end
	if not RULELIST[rule] then
		SendToAll(BOTNAME,curUser.sName.." is Kicking "..nick..", Reason: "..reason..", Rule: Not Given")
	else
		SendToAll(BOTNAME,curUser.sName.." is Kicking "..nick..", Reason: "..reason..", Rule: "..RULELIST[rule])
	end
	return 1
end


ThX for the guidence ppl... Now a thing or two more clearly now...

And always ThX to you Tezlo...

Have read that part about digits in LUA many times...

Don't now why it didn't stuck in me at once... ;-p

/NightLitch

and sorry for my bad english sometimes...
//NL

SMF spam blocked by CleanTalk