Auto rejoin script

Release your script here.
State:
- Author
- What it does
- Perhaps a little guide.
- Also, if the snippet is of any use to the community, it has a chance of getting posted on the main page, so don't hesitate to submit/ask!

Auto rejoin script

Postby Cristian » Fri Jun 26, 2009 2:52 pm

This script checks if you are on the channels you have added in the script.
It checks every 5 minutes ((300 seconds) default), if you aren't on the it will join you.

Supports multiple connections to same network, information is stored by network and connection id

Commands:
    /rejoin -a #channel - adds a channel
    /rejoin -r #channel - removes a channel
    /rejoin -l - lists channels, for the network





Code: Select all
alias -l db { return autorejoin.ini }
alias -l waittime { return 300 }


alias rejoin {
  if ($1 == -a) {
    if (!$2) || ($left($2,1) != $chr(35)) || ($chr(44) isin $2) { echo -ag $+($chr(3),$color(info),$timestamp) $+($chr(3),$color(info),***) error: syntax /rejoin -[ae|r]|l [#channel] | return }

    if (!$readini($db,$network,$2)) {
      writeini -n $db $network $2 $cid
      echo -ag $+($chr(3),$color(info),$timestamp) $+($chr(3),$color(info),***) added $2 to rejoin list.
    }
    else {
      echo -ag $+($chr(3),$color(info),$timestamp) $+($chr(3),$color(info),***) error $2 is already added.
    }
  }
  if ($1 == -r) {
    if (!$2) || ($left($2,1) != $chr(35)) || ($chr(44) isin $2) { echo -ag $+($chr(3),$color(info),$timestamp) $+($chr(3),$color(info),***) error: syntax /rejoin -[ae|r]|l [#channel] | return }

    if ($readini($db,$network,$2)) {
      remini $db $network $2 | remini $db wait $2
      echo -ag $+($chr(3),$color(info),$timestamp) $+($chr(3),$color(info),***) removed $2 from rejoin list.
    }
    else {
      echo -ag $+($chr(3),$color(info),$timestamp) $+($chr(3),$color(info),***) error $2 is not added.
    }
  }
  if ($1 == -l) {
    echo -ag $+($chr(3),$color(info),$timestamp) $+($chr(3),$color(info),***)
    echo -ag $+($chr(3),$color(info),$timestamp) $+($chr(3),$color(info),***) Automated rejoin list: $+($chr(2),$chr(91),$chr(2),$chr(32),network,$chr(32),$chr(2),$chr(93),$chr(91),$chr(2),$chr(32),connection id,$chr(32),$chr(2),$chr(93),$chr(2),$chr(32),#channel)
    echo -ag $+($chr(3),$color(info),$timestamp) $+($chr(3),$color(info),***)
    var %x = 1, %z = $ini($db,$network,0), %c
    while (%x <= %z) {
      var %channel = $ini($db,$network,%x)
      var %id = $readini($db,$network,%channel)
      echo -ag $+($chr(3),$color(info),$timestamp) $+($chr(3),$color(info),***) $+($chr(2),$chr(91),$chr(2),$chr(32),$network,$chr(32),$chr(2),$chr(93),$chr(91),$chr(2),$chr(32),%id,$chr(32),$chr(2),$chr(93),$chr(2),$chr(32),%channel)
      inc %x
    }
  }
}

raw *:*: {
  if ($findtok(471 473 474 475,$numeric,1,32)) {
    writeini -n $db wait $2 $cid
  }
  checktimer
}

alias -l checkchannels {
  var %cid = $scon(0)
  while (%cid) {
    scid $scon(%cid)
    if ($status == connected) {

      var %network = $network

      if ($ini($db,$network,0)) {
        var %x = 1, %z = $ini($db,$network,0)
        while (%x <= %z) {
          var %channel = $ini($db,$network,%x)
          var %id = $readini($db,$network,%channel)
          if (%cid == %id) {
            if ($me !ison %channel) {
              var %t = $readini($db,join,%id)
              writeini -n $db join %id %channel %t
            }
          }
          inc %x
        }
      }
    }
    dec %cid
  }
  if ($ini($db,wait,0)) {
    var %x = 1, %z = $ini($db,wait,0)
    while (%x <= %z) {
      var %channel = $ini($db,wait,%x)
      var %id = $readini($db,wait,%channel)
      scid $scon(%id)
      if ($status == connected) {
        if ($me !ison %channel) {
          var %t = $readini($db,join,%id)
          writeini -n $db join %id %channel %t
          remini $db wait %channel
        }
      }
      inc %x
    }
  }
  var %x = $ini($db,join,0)
  while (%x) {
    var %id = $ini($db,join,%x)
    var %channels = $readini($db,join,%id)

    scid $scon(%id)
    join $replace(%channels,$chr(32),$chr(44))
    echo -sg $+($chr(3),$color(info),$timestamp) $+($chr(3),$color(info),***) Attempting to join $+($chr(2),%channels,$chr(2)) on Network $+($chr(2),$network,$chr(2)) Connection ID $+($chr(2),%id,$chr(2))
    dec %x
  }
  remini $db join
}

alias -l checktimer {
  if (!$timer(.rejoin.timer)) { .timer.rejoin.timer 1 $waittime checkchannels }
}
on *:KICK:#: {
  if ($knick iswm $me) {
    writeini -n $db wait $chan $cid
  }
  checktimer
}

on *:JOIN:#: {
  if ($nick iswm $me) {
    if ($readini($db,wait,$chan) == $cid) {
      remini $db wait $chan
    }
  }
  checktimer
}
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar

Re: Auto rejoin script

Postby zNigel- » Fri Jun 26, 2009 3:10 pm

That looks really good. Haven't tried it yet though but it sure looks good.

How do you even come up with those script ideas? I got problems myself to come up with something random ;x
zNigel-
 

Re: Auto rejoin script

Postby Cristian » Fri Jun 26, 2009 3:54 pm

the ideas comes to me in my sleep, this idea was easy, since I am on Quakenet with two connections, and didn't want to join the same channels twice.
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar

Re: Auto rejoin script

Postby zNigel- » Fri Jun 26, 2009 4:03 pm

Would be nice if scripting ideas was showing up whilst i sleep 2. Then i'd release more here :)

Keep the good work up m8.


Regards.
zNigel-
 

Re: Auto rejoin script

Postby Cristian » Fri Jun 26, 2009 4:31 pm

thanks
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar


Return to Mirc Scripting Release

Who is online

Users browsing this forum: No registered users and 0 guests