if-statementircmirc

How to use if statement with on *:CONNECT: mirc script


I would like to join three networks, authenticate towards nicksrv and send a message to a bot /or auto-join a few channels when I launch my IRC client. I am using mIRC 7.55.

What the client should do depends on which network it is. So I have an if statement for it but it is not working correctly.

With one server it works perfect, as soon as I add more than one I have issues. Something must be wrong with my syntax, or maybe if there is something else I could use than $server ?

on *:start: {
  /server irc.gazellegames.net:+7000
  /server -m irc.scratch-network.net:+7000
  /server -m irc.myanonamouse.net:+6697
}
on *:CONNECT: {
  if ($server = "horus.gazellegames.net" || "anubis.gazellegames.net") {
    /msg NickServ IDENTIFY password
    /msg Vertigo ENTER username password
  }
  if ($server = brooklyn.scratch-network.net) {
    /msg NickServ IDENTIFY password
    /msg Drone enter #channel1 username password
  }
  if ($server = "irc.myanonamouse.net" || "irc2.myanonamouse.net") {
    /msg NickServ IDENTIFY password
    /j #channel1,#channel2
  }
}

Expected result would be to join the networks and follow the IF STATEMENT and authenticate with correct credentials for each network. Script works but it is unreliable.

The script seems to send everything to first server it connects to, see snippet here: https://i.sstatic.net/vGuC4.jpg

And it is unable to join the second channel for irc.myanonamouse.net/irc2.myanonamouse.net.

I would like to avoid leaking my credentials and automate it, so I just need to launch the client to join all networks, authenticate, message a bot or join a few channels.


Solution

  • I've split the different types of activities to a specific alias handler and passed it the network identifier. i.e: SpecificNetworkCommands, JoinNetworkChannels

    I've also removed the NickServ authentication from the connect procedure, and will not only fire the response when triggered by NickServ initiating ON NOTICE event. This will helped you always be authenticated in case the Network Services restarted and are asking you to re-authenticate.

    Note:

    1. All of those repetitive if $network == can be make dynamic and cleaner, by further creating a storing mechanism for Authentications or AutoJoins.
    2. You can also, use Authentication\Identification, AutoJoin, Perform commands mSL scripting that will do every part of this for you without any effort and with most of the time with UI.

    Code: (Not been tested)

    ON *:CONNECT: {
      SpecificNetworkCommands $network
      JoinNetworkChannels $network
    }
    
    ; This will send network credentials whenever required.
    ON *:NOTICE:This nickname is registered*:?: {
      if ($nick == NickServ) {
        var %username, %password
        if ($network == NetworkName1) {
          %username = MyNetworkName1Username
          %password = MyNetworkName1Password
        }
        elseif ($network == NetworkName2) {
          %username = MyNetworkName2Username
          %password = MyNetworkName2Password
        }
        elseif ($network == freenode) {
          %username = MyFreeNodeUsername
          %password = MyFreeNodePassword
        }
    
        if (%username && %password) {
          msg nickserv identify %username %password
        }
      }
    }
    
    ; Contain network specific actions
    ; $1 means the passed $network parameter
    alias SpecificNetworkCommands {
      if ($1 == GGn) {
        msg Vertigo ENTER username password
      }
      elseif ($1 == Scratch-Network) {
        msg Drone enter #channel username password
      }
    }
    
    ; Joining the specific network channels
    ; $1 means the passed $network parameter
    alias JoinNetworkChannels {
      if ($1 == MYANONAMOUSE) {
        join #channel1
        join #channel2
      }
      elseif ($1 == freenode) {
        join #channel1
        join #channel2
      }
    }