|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
sure I think my example is more educative to some degree, as it tries some dynamic text picking - but then, yours is shorter, faster, and last but not least: more comprehensible
|
|
|
|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
Indeed long story short stripping a specific word or group of words out of context is quite easy and can be done in not 1 not 2 but many several ways. all with $findtok $gettok and $calc Its possible "First find seen token" then Find "Ago." token then gettok calc + 1 for the seen token and minus 1 for the ago. token But it''s rather lengthy I made up what I call $mrgtok it consits of $findtok within gettok range in multiple areas. Why? Well I seem to always be using $findtok and $gettok in alot of my scripts
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Feb 2006
Posts: 97
Babel fish
|
OP
Babel fish
Joined: Feb 2006
Posts: 97 |
Thanks Horstl and Lpfix5,
Going to play and learn from it this weekend, gonna try if you can make it prefixed line independent so that it just triggers on : *m+*w+*d or *w+*d or just *d.
I'm not an average scripter more an avbg hoping to learn from it
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
Uh, if you want a wildmatch for this kind of "duration in textstring", I suppose a regex is most suitable -at last-. I'm not that firm with regex, - atm it will match only if m AND w AND d are provided... I have probs to handle the spaces... but for sure someone that reads this can improve my poor attempt Also note, that whatever regex/other method used, it inevitable will match statements like "Hey, I bought a new 3d game! on *:text:*:#: {
noop $regex($1-,/((?:\d+m)? (?:[1-3]w)? (?:[1-6]d)?)/S)
if ($regml(1)) { echo -a match: $regml(1) }
}
|
|
|
|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
Is it possible to change the outcome of that incoming mesage instead of 1w 3d to be like 1week 3days? or you have no control on the incoming message? Because to make a solid pickup you would in theory need it to be more tight in the way to pick up the (y)ear (m)onth (d)ays The only way to make it tighter is if theres atleast 2 matching num symbols example. Lets say for sure the output would be 2m 1w 6d is when I seen NICKthen.. Using regex like this..
on *:TEXT:*:#:{
if ($regex($1-,/\b(\d+m|[1-3]w|[1-6]d)\b/g) >= 2) { echo -a $regml(1) $regml(2) $regml(3) }
}
Will only function if theres a matching event that is 2 or higher meaning if 3d is the only word in it will not function but if 2w 3d will. The downfall if by any chance, 1d or 1m or 1w is the only output then the script does not launch, but if you know where im coming from, If the script shows this 3d 8h 7s ago. then you could expand your regex match. so make it work as you wish. In the code I put youll see $regml(1) up to 3 it doesnt matter if theres only 2 matches the 3rd regml won't trigger.
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
I was thinking of fetching all possibly strings that do that, and put them into a hash or txt file then read from file and parse as will..
Example...
Exactly 2w 5d is when I last seen nick. I seen nick 2w 5d ago. Nick was seen 2w 5d ago.
This would give me 3 options to go about. But then again it might defeat the purpose of your w m d rules.
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Feb 2006
Posts: 97
Babel fish
|
OP
Babel fish
Joined: Feb 2006
Posts: 97 |
Is it possible to change the outcome of that incoming mesage instead of 1w 3d to be like 1week 3days? or you have no control on the incoming message? Actually i haven't got any control on it and i had plans using it for more then 1 channel and not every channel uses same style. Because to make a solid pickup you would in theory need it to be more tight in the way to pick up the (y)ear (m)onth (d)ays The only way to make it tighter is if theres atleast 2 matching num symbols example. Lets say for sure the output would be 2m 1w 6d is when I seen NICKthen.. Using regex like this..
on *:TEXT:*:#:{
if ($regex($1-,/\b(\d+m|[1-3]w|[1-6]d)\b/g) >= 2) { echo -a $regml(1) $regml(2) $regml(3) }
}
Will only function if theres a matching event that is 2 or higher meaning if 3d is the only word in it will not function but if 2w 3d will. The downfall if by any chance, 1d or 1m or 1w is the only output then the script does not launch, but if you know where im coming from, If the script shows this 3d 8h 7s ago. then you could expand your regex match. so make it work as you wish. In the code I put youll see $regml(1) up to 3 it doesnt matter if theres only 2 matches the 3rd regml won't trigger. You said that if it's bigger then 2 it will function, but what if we splits it and check for <= 52 for weeks <=12 for months and <=31 for days? Then we have all options and the change it picks wrong format is hardly there, or do i forget something? -update- Still struggling with regex function, so no preview code yet
Last edited by ots654685; 28/11/07 11:15 AM.
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
You said that if it's bigger then 2 it will function, but what if we splits it and check for <= 52 for weeks <=12 for months and <=31 for days? Then we have all options and the change it picks wrong format is hardly there, or do i forget something? The $duration output of the given examples breaks at 7days > 1week, 4weeks > one month - Thus you'll always run into problems like "I need a new 3d video card" "from my house it's only 600m to the local store" There's need for some other kind of checking... For example, if this would be a reply to a !seen script, a group enabled only for a couple of seconds on text !seen
|
|
|
|
Joined: May 2007
Posts: 89
Babel fish
|
Babel fish
Joined: May 2007
Posts: 89 |
Imo, the function
Alias GetSeen {
If $regex($1-,/(seen\s\b(\d{1,}m\s\d{1,}w\s\d{1,}d|\d{1,}w\s\d{1,}d|\d{1,}d)\sago\.$)/iS) {
Echo -ast $regml(2)
}
}
echoes what you want. I don't know about the further processing on the result of the function. For instance, if you want to get piecewise returns, then a simple < /tokenize 32 $regml(2) > would do that by allocating to $1 $2 .. $n each spaced token. It could ressemble this code.
Alias GetSeen {
If $regex($1-,/(seen\s\b(\d{1,}m\s\d{1,}w\s\d{1,}d|\d{1,}w\s\d{1,}d|\d{1,}d)\sago\.$)/iS) {
Tokenize 32 $regml(2)
Echo -st $*
}
}
Of course, these codes are only for demonstrating how you can grab the desired format. And, there is for sure, better regular expressions that could be used. This one functions though. Cordialement PS: If you need whichever explanation, just ask us.
tropnul
|
|
|
|
|