Search code examples
ircmirc

How to check if $4 is registered in IRC?


I am quite an expert when it comes to programming in the MSL language, however I am unfamiliar with raw commands and whatnot.

I am in development of a new script. In this script I would like to check if $4 in what a user says is a registered nick or not but I do not know how to do this.

Thank you very much for any help and/or advice in advanced.

Best Regards, Tim

Update:

raw 307:*:{ set $+(%,%chan,-,%CheckNick) Registered }
on *:TEXT:*:#:{
    if ($1 == !regtest) {
        set %chan $remove($chan,$chr(35))

        set %CheckNick $4
        whois $4
    }
    if ($($+(%,%chan,-,%CheckNick),$4),5) != $null) {
        do this...
    }
    else {
        else message...
    }
}

I got this to work to check however my if statement to check if the variable has been set or not is being ignored...

Edit:

I tried using this:

checkNickReg $chan $2 $nick

...And echoing this:

  echo -a Target: $1
  echo -a Nick: $2
  echo -a Status: $3
  echo -a Chan: $3 - $chan

I'm trying to get a response to the channel such as; $nick $+ , $1 is not registered/registered/registered but not logged in.

What I've posted above is obviously wrong as it doesn't work, however I've tried a few methods and I'm actually not sure how the data is passed on with out the likes of tokenizing or setting variables...

Reply

[01:59:06] <~MrTIMarshall> !isReged mr-dynomite
[01:59:08] <&TornHQ> : mr-dynomite status is: NOTLOGGED
EDIT: mr-dynomite is not currently on, should this not = does not exist or does this check even when their not on, if so this is bloody brillant!!! [02:00:04] <~MrTIMarshall> !isReged MrTIMarshall
[02:00:04] <&TornHQ> : MrTIMarshall status is: LOGGEDIN

$4 does not seem to work and what is the difference between 'exists, not logged in' and 'recognized, not logged in'?

Also, how does the data get passed on without setting variables or tokenizing?

(P.S. Thank you so much for the help you have dedicated so far!)

Another Edit:

I've been taking an in depth look today, am I correct in thinking if 0 or 1 the user is either not on-line or not registered (in the comments it says 0 = does not exists / not online, 1 = not logged in whereas 2 also says not logged in but recognized of which I'm unsure as what recognized means. Otherwise I'm very grateful for this script help and whatnot I'm just unclear on the numbers...


Solution

  • Since you have not specified any particular network I wrote an outline for some common networks around (that actually have user authentication systems). You should be able to add many other networks following the pattern.

    Basically you execute /checkNickReg <target> <nick> [optional extra data] and when the server replays with the registration info (if applicable) use the on isReged signal event to handle the reply. Everything else is pretty much transparent.

    EDIT: Looks like the specified network you are using (Torn) uses the standard anope services. So I updated the code to support that network.

    ; triggers when you get nick registration info back
    ; $1 = Target
    ; $2 = Nick
    ; $3 = Status, can be: LOGGEDIN, RECOGNIZED, NOTLOGGED
    ; $4- = Everything else passed
    on *:signal:isReged:{
      echo -a Target: $1
      echo -a Nick: $2
      echo -a Status: $3
      echo -a Else: $4-
    }
    
    ; reg lookup routines
    alias checkNickReg {
      set %reg. $+ $network 1
      set %reg.target. $+ $network $1
      set %reg.nick. $+ $network $2
      set %reg.other. $+ $network $3-
    
      ; Freenode uses: NickServ ACC <nick>
      if ($network == Freenode) msg NickServ ACC $2
      ; Rizon/SwiftIRC/OFTC/Torn use: NickServ STATUS <nick>
      elseif ($istok(Rizon SwiftIRC OFTC Torn, $network, 32)) msg NickServ STATUS $2
    }
    
    ; listen for replays
    on *:notice:*:*:{
      if ($($+(%, reg., $network),2)) {
        ;
        var %target = $($+(%, reg.target., $network),2)
        var %nick = $($+(%, reg.nick., $network),2)
        var %other = $($+(%, reg.other., $network),2)
        ;
        unset %reg*. $+ $network
    
        if (($network == FreeNode) && ($2 == ACC)) $&
          || (($istok(Rizon SwiftIRC OFTC Torn, $network, 32)) && ($1 == STATUS)) {
    
          ; FreeNode:
    
          ; 0 = does not exist
          ; 1 = exists, not logged in
          ; 2 = recognized, not logged in
          ; 3 = logged in
    
          ; Rizon/SwiftIRC/OFTC/Torn:
    
          ; 0 = does not exists / not online
          ; 1 = not logged in
          ; 2 = recognized, not logged in
          ; 3 = logged in
    
          if ($3 < 2) var %status = NOTLOGGED
          elseif ($3 == 2) var %status = RECOGNIZED
          else var %status = LOGGEDIN
        }
    
        ;send status signal
        .signal isReged %target %nick %status %other 
      }
    }
    

    (Extra Note: It might be useful to add an extra check to make sure $nick is AuthServ/NickServ for security reasons.)

    A simple usage example is:

    ; Just a basic example of how to call it.
    on *:text:!isReged &:#:{
      checkNickReg $chan $2 $nick
    }
    
    on *:signal:isReged:{
      msg $1 $4: $2 status is: $3
    }
    

    Type !isReged <nick>

    Edit: The data gets passed to the on isReged event via global variables. I set them in the checkNickReg alias and I clean them up in the on notice event. So you never see them because they get cleaned up. They are passed to the isReged signal event in $1-.