mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
Tomao #205733 30/10/08 04:49 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Code:
on *:TEXT:*:#: {
  var %x = /^(hello|hey|hi)\s $+ $me $+ /Si
  if ($regex($1-,%x)) {
    if $right($me,4) != -afk {
      describe # Hello $nick $+ , hows it going ? :)
    }
    else {
      describe # Sorry $nick $+ , but I'm not able to have a conversation with you at this time :)
  }
}

This works, just wondered if there was a better way to do it, such as having it all in the ON TEXT event, or if it makes any difference.

RusselB #205745 30/10/08 09:21 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Nice one, RusselB. It works very well. I made a previous post attempting to use something else but to no avail, compared to yours.

However, the var can be omitted and gathered in the on text event as such:

Code:
on $*:TEXT:$(/^(hello|hey|hi|hello,|hey,|hi,)\s( $+ $me $+ )$/Si):#: {
  if ($regex($1-,$regml(2))) { if ($right($me,4) != -afk) { describe # Hello $nick $+ , hows it going ? :) }
    else { describe # Sorry $nick $+ , but I'm not able to have a conversation with you at this time :) }
  }
}


Comma match is added in case people use hi, <nickname> instead of hi <nickname>

RusselB #205748 30/10/08 10:17 PM
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Well I used a testing script I got off of here last year to test the evaluation time of different identifiers and comparisons. The conclusion was that 'isin' was actually the fastest. I also found using "else" is slower than alternative methods.

Code:
on *:TEXT:*:#:{
  if ($1 isin hi.hello.hey) && ($2 == $me) {
    if {$right($me,4) == -afk) { describe # Sorry $nick $+ , but I'm not able to have a conversation with you at this time :) | return }
    describe # Hello $nick $+ , hows it going ? :)
  }
}


Something I have to ask though is about the -afk. If you are indeed afk this would require the user to say Hey -afkRusselB ! Also, no punctuation afterwards would be allowed. Hey RusselB! wouldnt work since $2 is RusselB! and not $me which is RusselB.

Any thoughts about this?

Last edited by DJ_Sol; 30/10/08 10:19 PM.
DJ_Sol #205752 30/10/08 11:11 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
I believe his away nickname is RusselB-afk

Code:
//echo -a $right(ResselB-afk,4)


I think regex works decently well in this case for matching purposes. I have addressed the ! and . punctuation so that people can call hi RusselB! or hi, RusselB. or Hi russellb or without any. The nickname being called is not case sensitive because of /i modifier.

And it will not trigger when someone calls out in this fashion: hi russelb <followed by words>

Code:
on $*:TEXT:$(/^(hello|hey|hi|hello,|hey,|hi,)\s( $+ $me $+ )(!|.|)$/Si):#: {
  if ($regex($1-,$regml(2))) { if ($right($me,4) != -afk) { describe # Hello $nick $+ , hows it going ? :) }
    else { describe # Sorry $nick $+ , but I'm not able to have a conversation with you at this time :) }
  }
}

Tomao #205760 31/10/08 02:27 AM
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Yeah thats a good use of regex.

Page 2 of 2 1 2

Link Copied to Clipboard