All pastes #425327 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-04-05 12:49 UTC
rendered paste body
sub chan_check {
  my $now = time;
  Xchat::print("$logo\tCalling chan_check at $now","[JUNK]");
  for( Xchat::get_list("channels") ) {
    if ( !$_->{'network'} && $_->{'channel'} ne "[RAW]" && $_->{'channel'} ne "[JUNK]" && $_->{'channel'} ne "[NOTICES]" && $_->{'channel'} ne "[SERVER]" && $_->{'channel'} ne "[DCC]" ) {
      Xchat::set_context( $_->{'context'} );
      Xchat::command( "close" );
      Xchat::set_context(Xchat::get_context());
      Xchat::print("$logo\tClosing Tab $_->{'channel'} because no network was assigned","[JUNK]");
    }
  }
  foreach my $key ( sort(keys %CHANS) ) {
    # if no server context found && channel is set -auto then...
    if (!Xchat::find_context("","$CHANS{$key}{net}") && $CHANS{$key}{auto} eq "yes" ) {
      Xchat::print("$logo\t$CHANS{$key}{net} not found","[JUNK]");
      # if we have not already issued a newserver command for this server this interval then do so now
      # here we make sure that we didnt already recently try to connect before trying it again.  60 second delay
      if ( !$SERVS{$CHANS{$key}{net}}{lastconnect} ) { $SERVS{$CHANS{$key}{net}}{lastconnect} = 0; }
      if ( $now - $SERVS{$CHANS{$key}{net}}{lastconnect} > $SETTINGS{connect_time} ) {
        Xchat::print( "$logo\tNot connected to $CHANS{$key}{net} required by $CHANS{$key}{chan}.  Attempting connection","[JUNK]" );
        Xchat::command( "newserver $CHANS{$key}{net}" );
        $SERVS{$CHANS{$key}{net}}{lastconnect} = $now;
      }
      else { Xchat::print( "$logo\tNot connected to $CHANS{$key}{net} required by $CHANS{$key}{chan} and last connection attempt was $now - $SERVS{$CHANS{$key}{net}}{lastconnect} seconds ago.","[JUNK]" ); }
      last;  # staggers the connections to different networks
    }
    # if server context exists but no channel is found and channel is set to -auto then...
    elsif ( !Xchat::find_context($CHANS{$key}{chan},$CHANS{$key}{net}) && $CHANS{$key}{auto} eq "yes" ) {
      my $servstate;
      for ( Xchat::get_list("channels") ) {
        # find server connect status
        if ( lc($_->{'network'}) eq lc($CHANS{$key}{net}) ) {
          $servstate = "$_->{'flags'}";
          last;
        }
      }
      # if server state over 8 then we have the motd and then ok to try and join channel
      if ( !$CHANS{$key}{lastjoin} ) { $CHANS{$key}{lastjoin} = 0; }
      if ( !$SERVS{$CHANS{$key}{net}}{lastjoin} ) { $SERVS{$CHANS{$key}{net}}{lastjoin} = 0; }
      if ( $servstate >= 8 && $now - $SERVS{$CHANS{$key}{net}}{lastjoin} > $SETTINGS{join_time} && $now - $CHANS{$key}{lastjoin} > $SETTINGS{join_time} ) {
        Xchat::print("$logo\tNot in $CHANS{$key}{chan} on $CHANS{$key}{net}.  Attempting to join","[JUNK]");
        Xchat::print("$logo\t'join $CHANS{$key}{chan} $CHANS{$key}{key}','','$CHANS{$key}{net}'","[JUNK]");
        Xchat::command("join $CHANS{$key}{chan} $CHANS{$key}{key}","","$CHANS{$key}{net}");
        if ( $SERVS{$CHANS{$key}{net}}{status} && $SERVS{$CHANS{$key}{net}}{status} ne "Problem" ) { $SERVS{$CHANS{$key}{net}}{lastjoin} = $now; }
      }
      else { Xchat::print( "$logo\tNot in $CHANS{$key}{chan} and last connection attempt was $now - $SERVS{$CHANS{$key}{net}}{lastjoin} seconds ago on $CHANS{$key}{net}.  Server flags are $servstate","[JUNK]"); }
    }
    # if both server and channel context are found then then check for channel status and user modes...
    else {
      my $context = Xchat::find_context($CHANS{$key}{chan},$CHANS{$key}{net});
      if ( $context ) {
        Xchat::set_context($context);
        my $user = Xchat::user_info();
        Xchat::print("$logo\tDEBUG if ( ( $user->{prefix} eq '@' && $CHANS{$key}{expect} > 3 ) || ( $user->{prefix} eq '%' && $CHANS{$key}{expect} > 2 ) || ( $user->{prefix} eq '+' && $CHANS{$key}{expect} > 1 ) ||  ( !$user->{prefix} &&  $CHANS{$key}{expect} > 0 ) )","[JUNK]");
        if ( ( $user->{prefix} eq '@' && $CHANS{$key}{expect} > 3 ) || ( $user->{prefix} eq '%' && $CHANS{$key}{expect} > 2 ) || ( $user->{prefix} eq '+' && $CHANS{$key}{expect} > 1 ) || ( !$user->{prefix} && $CHANS{$key}{expect} > 0 ) ) {
          if ( !$CHANS{$key}{lastcmd} ) { $CHANS{$key}{lastcmd} = 0; }
          if ( $CHANS{$key}{botcmd} && $BOTS{$CHANS{$key}{botcmd}} && $now - $CHANS{$key}{lastcmd} > 30 ) {
            my $nick = Xchat::get_info("nick");
            my $cmd = $BOTS{$CHANS{$key}{botcmd}};
            $cmd =~ s/\%chan/$CHANS{$key}{chan}/g;
            $cmd =~ s/\%user/$nick/g;
            Xchat::command($cmd);
            Xchat::print("$logo\tYou are expecting $CHANS{$key}{expect} but only have $user->{prefix} in $CHANS{$key}{chan} on $CHANS{$key}{net}.  Need to fix that by using $cmd","[JUNK]");
            $CHANS{$key}{lastcmd} = $now;
          }
          elsif ( $CHANS{$key}{botcmd} && !$BOTS{$CHANS{$key}{botcmd}} ) { Xchat::print("$logo\tERROR: You are expecting $CHANS{$key}{expect} but only have $user->{prefix} in $CHANS{$key}{chan} on $CHANS{$key}{net} but the configured botcmd named $CHANS{$key}{botcmd} is not defined.","[JUNK]" ); }
          elsif ( !$CHANS{$key}{botcmd} ) { Xchat::print("$logo\tYou are expecting $CHANS{$key}{expect} but only have $user->{prefix} in $CHANS{$key}{chan} on $CHANS{$key}{net} and no botcmd was defined.","[JUNK]" ); }
          else { Xchat::print("$logo\tRetry for botcmd $CHANS{$key}{botcmd} in $CHANS{$key}{chan} on $CHANS{$key}{net} not yet expired.","[JUNK]" ); }
        }
      }
    }
  }
  Xchat::unhook( $chantimer );
  $chantimer = Xchat::hook_timer( $SETTINGS{chan_check}*1000,"$INFO{name}::chan_check" );
}