|
Joined: Feb 2005
Posts: 194
Vogon poet
|
OP
Vogon poet
Joined: Feb 2005
Posts: 194 |
Hey. I need an on TEXT command that will be triggered if the one of the words said matches at least 4 character (in a row) of a hash item. More specifically, I'm doing an away system.
EX: DeepSeaFisher goes away. His name is added to a hash table (the nick being the item and the data is the reason) Insted of someone having to say "DeepSeaFisher" in a sentence to trigger a "DeepSeaFisher is away" message, they could say Deep or Fish, or any other 4 letter chunk of a nick. The only part I need is the 4 letter trigger (in bold bellow)
<DeepSeaFisher> !away blah <Bot> Your are now away for blah <Jimmy> Where did Deep go? <Bot> DeepSeaFisher is currently away
I believe this would be fairly simple. Please dont be confused by all my examples, I only tried to make it very clear of what I needed. Thanks in advance!
Thanks, Austin Hammer
"God sometimes puts us in the dark for us to see the light"
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
I dont beleive you can do that (well theroerticly you could but it would be task intensive), i would take everyline and process the words larger than 3 bytes for matching entries in the table. heres the code i came up with. on *:text:*:#:{
if ($hget(HASHTABLENAME)) {
hfree -w HASHTABLENAME.TEMP
var %text = $strip($1-)
var %i = 1
while (%i <= $numtok(%text,32)) {
var %word = $gettok(%text,%i,32)
if ($len(%word) >= 4) && (!$pos(%word,?,1) && !$pos(%word,&,1) && !$pos(%word,*,1)) {
if ($hfind(HASHTABLENAME,$+(*,%word,*),0,w)) {
var %l = $v1
while (%l) {
var %item = $hfind(HASHTABLENAME,$+(*,%word,*),%l,w)
if (!$hget(HASHTABLENAME.TEMP,%item)) {
hadd -m HASHTABLENAME.TEMP %item $true
msg $chan %item is currently away reason $hget(HASHTABLENAME,%item)
}
dec %l
}
}
;
var %l = $findtok(%text,%word,0,32) | while (%l) { var %text = $reptok(%text,%word,.,%l,32) | dec %l }
; ^ speed up rotine by removing %word AND any repeats of it later in the text
}
inc %i
}
hfree -w HASHTABLENAME.TEMP
}
}
* tested and was working. You didnt specify the hash table name so i called it HASHTABLENAME, there is also a HASHTABLENAME.TEMP table created and erased, its used to set a flag for any nick mentioned as away to ensure it doesnt get mentioned again in the same pass. You could remove the two lines of hfree -w HASHTABLENAME.TEMP and change the hadd -m HASHTABLENAME.TEMP %item $true to hadd -mu300 HASHTABLENAME.TEMP %item $true then it would only mention someones away once in a 5 min period. Just another idea maybe.
|
|
|
|
Joined: Feb 2005
Posts: 194
Vogon poet
|
OP
Vogon poet
Joined: Feb 2005
Posts: 194 |
Hey. This is excelent! I just have 1 small problem. I would like for it to work if the name had a question mark on the end. So that: Where is Deep? ... would also trigger. Normally, I would be able to modify a script to acomidate this, however, some of the code you used if unfamilar to me. So I would appreciate if you could show me how to make it work with a question mark.  Thanks, Austin Hammer
"God sometimes puts us in the dark for us to see the light"
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
Fjord artisan
Joined: May 2005
Posts: 449 |
would a simple on TEXT be enough for what you want? Like:
if ($istok($1-,deep,32)) { msg $chan Deep is away }
You might also have a first "if" statement before this one that would check if a variable was set for you being away. You'd set the variable on in the away alias. You might also want a "back" alias that unsets your variable. I actually wrote an alias for when I quit, so that all the variables that I set while I was logged in get unset before I quit. I'm new to this, so I don't know much beyond the basics. Hope that helps.
Last edited by bwr30060; 31/05/05 04:41 PM.
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
Fjord artisan
Joined: May 2005
Posts: 449 |
Oops, just realized the token identifier wouldn't work with a question mark, so your on TEXT line should really be
if (deep isin $strip($1-)) { msg $chan Deep is away }
Last edited by bwr30060; 31/05/05 04:44 PM.
|
|
|
|
Joined: Feb 2005
Posts: 194
Vogon poet
|
OP
Vogon poet
Joined: Feb 2005
Posts: 194 |
Sorry Blake. I guess I didnt make myself very clear. I need it to work for any nick that is an item in the hash table, not just the nick Deep. I only used that as an example to help explain my problem. But thanks anyways! 
"God sometimes puts us in the dark for us to see the light"
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
on *:text:*:#:{
if ($hget(HASHTABLENAME)) {
hfree -w HASHTABLENAME.TEMP
var %text = $strip($1-)
var %i = 1
while (%i <= $numtok(%text,32)) {
var %word = $gettok(%text,%i,32)
[color:blue];
while ($right(%word,1) == ?) { var %word = $left(%word,-1) }
; ^ remove an unlimited number of ? of the end of a word before testing it
; ^ This could be changed to deal with ? ! . , etc by changing to the following line
;while ($istok(? ! . $chr(44),$right(%word,1),32)) { var %word = $left(%word,-1) }
;[/color]
if ($len(%word) >= 4) && (!$pos(%word,?,1) && !$pos(%word,&,1) && !$pos(%word,*,1)) {
[color:blue];^ words with ?,&,* are ignored due to them being part of the wildmatching system of $hfind, also they arent legal characters in nicks
;[/color]
if ($hfind(HASHTABLENAME,$+(*,%word,*),0,w)) {
var %l = $v1
while (%l) {
var %item = $hfind(HASHTABLENAME,$+(*,%word,*),%l,w)
if (!$hget(HASHTABLENAME.TEMP,%item)) {
hadd -m HASHTABLENAME.TEMP %item $true
msg $chan %item is currently away reason $hget(HASHTABLENAME,%item)
}
dec %l
}
}
;
var %l = $findtok(%text,%word,0,32) | while (%l) { var %text = $reptok(%text,%word,.,%l,32) | dec %l }
; ^ speed up rotine by removing %word AND any repeats of it later in the text
}
inc %i
}
hfree -w HASHTABLENAME.TEMP
}
}
|
|
|
|
Joined: Feb 2005
Posts: 194
Vogon poet
|
OP
Vogon poet
Joined: Feb 2005
Posts: 194 |
Thanks bro! 
"God sometimes puts us in the dark for us to see the light"
|
|
|
|
|