Autojoin - single click save channels

By Bobbtyisdead on Apr 26, 2007

This code snippit is something I cooked up to manage the auto joining of channels on a network, most scripts I've seen need manual adding of the channels either in script or in a dialog, this script simply saves the channels on click.

When you load the snippit, it rips some information from your mIRC automatically, such as $mnick although you may want to add extra on connect events at the top of the script, for things such as identifying to a bot.

Once the code is loaded you can configure the settings from the menu bar, configuring default values or server specific ones. The script contains a default section but also allows you to override these settings for server connections.

A server is added to the autojoin when you save or add channels to the channel list. Updating this list is easy you just connect to the server you want join the channels and click save channels. You can manually add or remove channels, but the 'set' is the easiest way. You can turn autojoin off for which it will prompt you to join or not join channels or networks.

Last updated 09/01/10:
Added support for connecting to the same network twice with different events (added $net which will return a unique network name)

Previous updates:
Default values for all settings
Setting settings from menu bar
Full BNC login support (makes sure idents don't get mashed)
Added manual call for commands /ps - id and /jc - join channels.
Added Global on/off.

; After this script is loaded and configured you will be able to use the commands:
; /jc to rejoin channels in the autojoin list
; /ps to re-identify yourself

; This is an area to add extra on connect events, the example is to connect remove swiftircs hostmasking

alias aj.networkspec {
  ; Syntax for a single/first network
  if ($net == SwiftIRC) {
    ; You will need to remove the ; prefix on the command to use this example
    ;mode $me -x

  }
  ; Syntax for an additional network performs
}

; This section lets you alter the default values, you can change these from the menu
; Altering this section only matters if your planning on clearing variables a lot

alias aj.defaults {
  if (!%aj.mnick) { set %aj.mnick $mnick }
  if (!%aj.anick) { set %aj.anick $anick }
  if (!%aj.fullname) { set %aj.fullname $fullname }
  if (!%aj.ident) { set %aj.ident $emailaddr }
  if (!%aj.modes) { set %aj.modes +i }

  ; ##################################################
  ; You can probably ignore everything past this point
  ; ##################################################

  if (%aj.on != 1) { set %aj.onsay Off }
  if (%aj.on != 1) { set %aj.on 0 }
}

on 1:CONNECT: {
  mnick $iif($($+(%,aj.mnick.,%net),2),$v1,%aj.mnick)
  anick $iif($($+(%,aj.anick.,%net),2),$v1,%aj.anick)

  ial on
  notify on
  mode $me %aj.modes

  if (%aj.on == 1) { .timer 1 4 aj.normjoin }
  elseif ($?!="Join all servers?" == $true) { .timer 1 4 aj.normjoin }
  elseif ($?!="Join channels on this network?" == $true) { .timer 1 4 aj.justjoin }
  else { echo -a Connect script halted, use /ps to identify and /jc to join channels. }
}

alias aj.on {
  set %aj.on 1
  set %aj.onsay On
}

alias aj.off {
  set %aj.on 0
  set %aj.onsay Off
}

alias aj.whichchans {
  if ($?="Add channel to auto join (eg. #pants).  Type 0 to disable autojoin this network." == 0) {
    unset $eval($+(%,aj.chans.,$1),1)
    set %aj.nets $remtok(%aj.nets,$1,1,59)
  }
  elseif ($! != $null) {
    set %aj.nets $addtok(%aj.nets,$1,59)
    if ($eval($+(%,aj.chans.,$1),2) != $null) {
      set $eval($+(%,aj.chans.,$1),1) $eval($+(%,aj.chans.,$1),2) $+ ; $+ $!
    }
    else {
      set $eval($+(%,aj.chans.,$1),1) $!
    }
  }
}

alias aj.setwhichchans {
  var %i = 1
  while (%i <=  $chan(0)) {
    if (%chanlist != $null) {
      var %chanlist %chanlist $+ ; $+ $chan(%i)
    }
    else {
      var %chanlist $chan(%i)
    }
    inc %i
  }
  set %aj.nets $addtok(%aj.nets,$1,59)
  set $eval($+(%,aj.chans.,$1),1) %chanlist
}

menu menubar {
  Auto Join
  .Status - %aj.onsay
  ..On:/aj.on
  ..Off:/aj.off
  .-
  .Default settings
  ..Main Nick ( $+ %aj.mnick $+ ):/set %aj.mnick $$?="Enter nickname"
  ..Alt Nick ( $+ %aj.anick $+ ):/set %aj.anick $$?="Enter backup nickname"
  ..Realname ( $+ %aj.fullname $+ ):/set %aj.fullname $$?="Enter Realname (shown at end of /whois)"
  ..Ident ( $+ %aj.ident $+ ):/set %aj.ident $$?="Enter Ident/Email (ident@mail.com)"
  .-
  .Edit channels/servers
  ..Click to add/clear channels or remove server.
  ..$submenu($aj.chan($1))
  .Save current channels ( $+ $net $+ ):/aj.setwhichchans $net
  .-
  .Settings for $net
  ..Set Main Nick ( $+ $iif($($+(%,aj.mnick.,$net),2),$v1,Default) $+ ):/set $+(%,aj.mnick.,$net) $$?="Enter nickname"
  ..Set Alt Nick ( $+ $iif($($+(%,aj.anick.,$net),2),$v1,Default) $+ ):/set $+(%,aj.anick.,$net) $$?="Enter backup nickname"
  ..Set Ident ( $+ $iif($($+(%,aj.emailaddr.,$net),2),$v1,Default) $+ ):/set $+(%,aj.emailaddr.,$net) $$?="Enter Ident/Email (ident@mail.com)"
  ..Set Realname ( $+ $iif($($+(%,aj.realname.,$net),2),$v1,Default) $+ ):/set $+(%,aj.realname.,$net) $$?="Enter Realname (shown at end of /whois)"
  ..Set NickServ password ( $+ $iif($($+(%,aj.nsstring.,$net),2),*hidden*,Not Set) $+ ):/set $+(%,aj.nsstring.,$net) $$?="Enter ident command as sent to server (ns identify password)"
}

alias ps {
  if ( $($+(%,aj.nsstring.,$net),2)) {
    $($+(%,aj.nsstring.,$net),2)
  }
}

alias aj.chan {
  if ($1 == begin) return -
  if (($numtok(%aj.nets,59) == 0) && ($1 == 1)) { return Add for $net $+ :aj.whichchans $net }
  while ($1 <= $numtok(%aj.nets,59)) {
    return $gettok(%aj.nets,$1,59) $+ - $eval($+(%,aj.chans.,$gettok(%aj.nets,$1,59)),2) $+ :aj.whichchans $gettok(%aj.nets,$1,59)
    if ($1 == end) return -
  }
}

alias jc {
  if ($eval($+(%,aj.chans.,$net),2) != $null) {
    join $replace($eval($+(%,aj.chans.,$net),2),;,$chr(44))
  }
}

alias aj.normjoin {
  aj.justjoin
  aj.joinnw
}

alias aj.justjoin {
  aj.networkspec
  ps
  jc
}

alias aj.runnet {
  var %i = 1
  while (%i <=  $scid(0)) {
    if ($eval($+(%,$1,.,$scon(%i).net),2) != $null) {
      scon %i $2-
    }
    inc %i
  }
}

alias aj.joinnw {
  var %i = 1
  var %aj.concheck %aj.nets
  while (%i <= $scon(0)) {
    if ($scon(%i).status == connecting) {
      echo -s Currently connecting, 4 sec delay.
      timer 1 4 aj.joinnw
      halt
    }
    if ($istok(%aj.concheck,$scon(%i).net,59) == $true) {
      set %aj.concheck $remtok(%aj.concheck,$scon(%i).net,1,59)
    }
    inc %i
  }
  var %i = 1
  while (%i <= $numtok(%aj.concheck,59)) {
    var %usem $iif($status != disconnected,-m)
    var %net $gettok(%aj.concheck,%i,59))
    server %usem %net -i $iif($($+(%,aj.mnick.,%net),2),$v1,%aj.mnick) $iif($($+(%,aj.anick.,%net),2),$v1,%aj.anick) $iif($($+(%,aj.emailaddr.,%net),2),$v1,%aj.ident) $iif($($+(%,aj.realname.,%net),2),$v1,%aj.fullname)
    inc %i
  }
}

alias net {
  var %i = 1
  var %suf
  while (%i <= $scon(0)) {
    if ($scon(%i) == $cid) return $network $+ %suf
    if ($scon(%i).network == $network) {
      if (%suf == $null) var %suf = 1
      inc %suf
    }
    inc %i
  }
  return $network
}

on 1:load: {
  echo -a KH Autojoin script loaded, please make sure you use the menu to set some default settings for things such as nickname/ident
  echo -a You may also want to edit the first few lines to set up some simple per server scripts.
  aj.defaults
}
on 1:start: {
  aj.defaults
  mnick %aj.mnick
  anick %aj.anick
}

Comments

Sign in to comment.
Bobbtyisdead   -  May 06, 2007

Heh, your right ofc, I wasn\'t however coding this snippit for others to use, rather as something for myself and thought it would be useful for others, I\'m not really very good with dialog\'s so I decided to leave it as it is.

 Respond  
|MELIORITE|   -  Apr 27, 2007

I think this could have been approached from another angle. There is quite a lot of user input required into the substance of the snippet... I might have preferred entering the information into a dialog box or something. Although it has no practical use for me I can see you\'ve given the coding some thought and is otherwise a pretty good job.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.