commit - b2b6fd905726aa542457f819ce4acd7799e198cc
commit + 166ac4ea24eeb6b169040d1a333fbfd79309d661
blob - dcf14b3a7a1e6dbc1c1f984d43bbcc5cad7b271f
blob + fcfec55c54b5ee70d0a8bc4865067d055d38956d
--- botnow
+++ botnow
# Comma-separated list of channels for requesting bouncers
$conf{chans} = $conf{chans} or die "ERROR: botnow.conf: chans";
-my @activenets;
-if (defined($conf{activenets})) {
- @activenets = split(/\s+/, $conf{activenets});
+my @networks;
+if (defined($conf{networks})) {
+ @networks = split(/\s+/, $conf{networks});
}
# Mail from address
$init->();
}
-
my @bots;
my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
my @teamchans;
if (defined($conf{teamchans})) { @teamchans = split /[,\s]+/m, $conf{teamchans}; }
my $call;
-my $botnick = $conf{nick};
+my $nick = $conf{nick};
my $host = $conf{host};
my $port = $conf{port};
my $pass = $conf{pass};
#rpath for reading file, wpath for writing file, cpath for creating path
#flock, fattr for sqlite
pledge( qw(stdio rpath wpath cpath inet dns proc exec flock fattr) ) or die "Unable to pledge: $!";
+
# create sockets
my $sel = IO::Select->new( );
-foreach my $network (@activenets) {
+foreach my $network (@networks) {
my $socket = IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port, Proto=>'tcp', Timeout=>'300') || print "Failed to establish connection\n";
$sel->add($socket);
my $bot = {("sock" => $socket), ("name" => $network)};
push(@bots, $bot);
- putserv($bot, "NICK $botnick");
- putserv($bot, "USER $botnick * * :$botnick");
+ putserv($bot, "NICK $nick");
+ putserv($bot, "USER $nick * * :$nick");
}
while(my @ready = $sel->can_read) {
putserv($bot, "PONG :$1");
} elsif ($response =~ /^:irc.znc.in (.*) (.*) :(.*)\r\n$/) {
my ($type, $target, $text) = ($1, $2, $3);
- if ($type eq "001" && $target =~ /^$botnick.?$/ && $text eq "Welcome to ZNC") {
- } elsif ($type eq "NOTICE" && $target =~ /^$botnick.?$/ && $text eq "*** To connect now, you can use /quote PASS <username>:<password>, or /quote PASS <username>/<network>:<password> to connect to a specific network.") {
- } elsif ($type eq "NOTICE" && $target =~ /^$botnick.?$/ && $text eq "*** You need to send your password. Configure your client to send a server password.") {
- } elsif ($type eq "464" && $target =~ /^$botnick.?$/ && $text eq "Password required") {
- putserv($bot, "PASS $botnick/$bot->{name}:$pass");
+ if ($type eq "001" && $target =~ /^$nick.?$/ && $text eq "Welcome to ZNC") {
+ } elsif ($type eq "NOTICE" && $target =~ /^$nick.?$/ && $text eq "*** To connect now, you can use /quote PASS <username>:<password>, or /quote PASS <username>/<network>:<password> to connect to a specific network.") {
+ } elsif ($type eq "NOTICE" && $target =~ /^$nick.?$/ && $text eq "*** You need to send your password. Configure your client to send a server password.") {
+ } elsif ($type eq "464" && $target =~ /^$nick.?$/ && $text eq "Password required") {
+ putserv($bot, "PASS $nick/$bot->{name}:$pass");
if ($bot->{name} =~ /^$localnet$/i) {
- putserv($bot, "OPER $botnick $pass");
+ putserv($bot, "OPER $nick $pass");
putserv($bot, "PRIVMSG *status :LoadMod --type=user controlpanel");
- putserv($bot, "PRIVMSG *controlpanel :get Admin $botnick");
+ putserv($bot, "PRIVMSG *controlpanel :get Admin $nick");
putserv($bot, "PRIVMSG *controlpanel :get Nick cloneuser");
foreach my $chan (@teamchans) {
putserv($bot, "JOIN $chan");
putserv($bot, "JOIN $chan");
}
}
- } elsif ($type eq "464" && $target =~ /^$botnick.?$/ && $text eq "Invalid Password") {
+ } elsif ($type eq "464" && $target =~ /^$nick.?$/ && $text eq "Invalid Password") {
die "ERROR: Wrong Username/Password: $bot->{name}";
} else {
- debug(ERRORS, "Unexpected bncnow.pl 257: type: $type, target: $target, text: $text");
+ debug(ERRORS, "ERROR: Unexpected type: $type, target: $target, text: $text");
}
} elsif($response =~ /^:(([^!]+)!([^@]+@[^@ ]+)) PRIVMSG ([^ ]+) :(.*)\r\n$/i) {
- my ($hostmask, $nick, $host, $target, $text) = ($1, $2, $3, $4, $5);
- if ($hostmask eq '*status!znc@znc.in' && $target =~ /^$botnick.?$/) {
+ my ($hostmask, $sendnick, $host, $target, $text) = ($1, $2, $3, $4, $5);
+ if ($hostmask eq '*status!znc@znc.in' && $target =~ /^$nick.?$/) {
if ($text =~ /Network ([[:ascii:]]+) doesn't exist./) {
- debug(ERRORS, "nonexistent: $1");
+ debug(ERRORS, "ERROR: nonexistent: $1");
} elsif ($text eq "You are currently disconnected from IRC. Use 'connect' to reconnect.") {
- debug(ERRORS, "disconnected: $bot->{name}");
+ debug(ERRORS, "ERROR: disconnected: $bot->{name}");
} elsif ($text =~ /Unable to load module (.*): Module (.*) already loaded./) {
debug(ALL, "Module $1 already loaded\n");
} elsif ($text =~ /^Disconnected from IRC.*$/) {
- debug(ERRORS, "$bot->{name}: $text");
+ debug(ERRORS, "ERROR: $bot->{name}: $text");
} elsif ($text =~ /^|/) {
- debug(ERRORS, "$bot->{name}: $text");
+ debug(ERRORS, "ERROR: $bot->{name}: $text");
} else {
- debug(ERRORS, "Unexpected bncnow.pl 273: $response");
+ debug(ERRORS, "ERROR: Unexpected: $response");
}
} elsif ($text =~ /^!([[:graph:]]+)\s*(.*)/) {
my ($cmd, $text) = ($1, $2);
foreach my $c (@{$call->{pub}}) {
if ($cmd eq $c->{cmd}) {
my $proc = $c->{proc};
- $proc->($bot, $nick, $host, $hand, $target, $text);
+ $proc->($bot, $sendnick, $host, $hand, $target, $text);
}
}
} else {
foreach my $c (@{$call->{msg}}) {
if ($cmd eq $c->{cmd}) {
my $proc = $c->{proc};
- $proc->($bot, $nick, $host, $hand, $text);
+ $proc->($bot, $sendnick, $host, $hand, $text);
}
}
}
if ($target =~ /^#/) {
foreach my $c (@{$call->{pubm}}) {
my $proc = $c->{proc};
- $proc->($bot, $nick, $host, $hand, $target, $text);
+ $proc->($bot, $sendnick, $host, $hand, $target, $text);
}
} else {
foreach my $c (@{$call->{msgm}}) {
my $proc = $c->{proc};
- $proc->($bot, $nick, $host, $hand, $text);
+ $proc->($bot, $sendnick, $host, $hand, $text);
}
}
}
} elsif($response =~ /^:([^ ]+) NOTICE ([^ ]+) :(.*)\r\n$/i) {
my ($hostmask, $target, $text) = ($1, $2, $3);
if ($hostmask =~ /([^!]+)!([^@]+@[^@ ]+)/) {
- my ($nick, $host) = ($1, $2);
+ my ($sendnick, $host) = ($1, $2);
my $hand = $staff; # TODO fix later
foreach my $c (@{$call->{notc}}) {
# if ($text eq $c->{mask}) { # TODO fix later
my $proc = $c->{proc};
- $proc->($bot, $nick, $host, $hand, $text, $target);
+ $proc->($bot, $sendnick, $host, $hand, $text, $target);
# }
}
- # TODO use CTCR
+
# CTCP replies
if ($hostmask ne '*status!znc@znc.in') {
if ($text =~ /^(PING|VERSION|TIME|USERINFO) (.*)$/i) {
my ($key, $val) = ($1, $2);
- my $id = SQLite::id("irc", "nick", $nick, $expires);
+ my $id = SQLite::id("irc", "nick", $sendnick, $expires);
SQLite::set("irc", "id", $id, "ctcp".lc($key), $val);
SQLite::set("irc", "id", $id, "localtime", time());
}
} elsif($response =~ /^:([^ ]+) MODE ([^ ]+) ([^ ]+)\s*(.*)\r\n$/i) {
my ($hostmask, $chan, $change, $targets) = ($1, $2, $3, $4);
if ($hostmask =~ /([^!]+)!([^@]+@[^@ ]+)/) {
- my ($nick, $host) = ($1, $2);
+ my ($sendnick, $host) = ($1, $2);
my $hand = $staff; # TODO fix later
foreach my $c (@{$call->{mode}}) {
# TODO filter by mask
my $proc = $c->{proc};
- $proc->($bot, $nick, $host, $hand, $chan, $change, $targets);
+ $proc->($bot, $sendnick, $host, $hand, $chan, $change, $targets);
}
}
debug(ALL, "$hostmask MODE $chan $change $targets");
#:jrmu!jrmu@jrmu.staff.ircnow.org MODE #testing +o jrmu
#Unexpected bncnow.pl 460: :irc.guava.ircnow.org MODE guava :+o
} elsif($response =~ /^:(([^!]+)!([^@]+@[^@ ]+)) JOIN :?(.*)\r\n$/i) {
- my ($hostmask, $nick, $host, $chan) = ($1, $2, $3, $4);
+ my ($hostmask, $sendnick, $host, $chan) = ($1, $2, $3, $4);
my $hand = $staff; # TODO fix later
foreach my $c (@{$call->{join}}) {
my $proc = $c->{proc};
- $proc->($bot, $nick, $host, $hand, $chan);
+ $proc->($bot, $sendnick, $host, $hand, $chan);
}
debug(ALL, "$hostmask JOIN $chan");
#:jrmu!jrmu@jrmu.staff.ircnow.org JOIN :#testing
} elsif($response =~ /^:(([^!]+)!([^@]+@[^@ ]+)) PART ([^ ]+) :(.*)\r\n$/i) {
- my ($hostmask, $nick, $host, $chan, $text) = ($1, $2, $3, $4, $5);
+ my ($hostmask, $sendnick, $host, $chan, $text) = ($1, $2, $3, $4, $5);
my $hand = $staff; # TODO fix later
foreach my $c (@{$call->{part}}) {
# if ($text eq $c->{mask}) { # TODO fix later
my $proc = $c->{proc};
- $proc->($bot, $nick, $host, $hand, $chan, $text);
+ $proc->($bot, $sendnick, $host, $hand, $chan, $text);
# }
}
debug(ALL, "$hostmask PART $chan :$text");
#:jrmu!jrmu@jrmu.staff.ircnow.org PART #testing :
} elsif($response =~ /^:(([^!]+)!([^@]+@[^@ ]+)) KICK (#[^ ]+) ([^ ]+) :(.*)\r\n$/i) {
- my ($hostmask, $nick, $host, $chan, $kicked, $text) = ($1, $2, $3, $4, $5, $6);
+ my ($hostmask, $sendnick, $host, $chan, $kicked, $text) = ($1, $2, $3, $4, $5, $6);
my $hand = $staff; # TODO fix later
foreach my $c (@{$call->{kick}}) {
# if ($text eq $c->{mask}) { # TODO fix later
my $proc = $c->{proc};
- $proc->($bot, $nick, $host, $hand, $chan, $text);
+ $proc->($bot, $sendnick, $host, $hand, $chan, $text);
# }
}
debug(ALL, "$hostmask KICK $chan $kicked :$text");
#jrmu!jrmu@jrmu.users.undernet.org KICK #ircnow guava :this is a test
} elsif($response =~ /^:(([^!]+)!([^@]+@[^@ ]+)) NICK :?(.*)\r\n$/i) {
- my ($hostmask, $nick, $host, $text) = ($1, $2, $3, $4);
+ my ($hostmask, $sendnick, $host, $text) = ($1, $2, $3, $4);
debug(ALL, "$hostmask NICK $text");
#:Fly0nDaWaLL|dal!psybnc@do.not.h4ck.me NICK :nec|dal
} elsif($response =~ /^:(([^!]+)!([^@]+@[^@ ]+)) QUIT :(.*)\r\n$/i) {
- my ($hostmask, $nick, $host, $text) = ($1, $2, $3, $4);
+ my ($hostmask, $sendnick, $host, $text) = ($1, $2, $3, $4);
debug(ALL, "$hostmask QUIT :$text");
#:Testah!~sid268081@aa38a510 QUIT :Client closed connection
} elsif($response =~ /^NOTICE AUTH :(.*)\r\n$/i) {
#NOTICE AUTH: *** Checking Ident
#NOTICE AUTH: *** Got ident response
#NOTICE AUTH: *** Found your hostname
- } elsif ($response =~ /^:([[:graph:]]+) (\d\d\d) $botnick.? :?(.*)\r?\n?\r$/i) {
+ } elsif ($response =~ /^:([[:graph:]]+) (\d\d\d) $nick.? :?(.*)\r?\n?\r$/i) {
my ($server, $code, $text) = ($1, $2, $3);
if ($code =~ /^001$/) { # Server Info
debug(ERRORS, "connected: $bot->{name}");
#Unexpected bncnow.pl 454: irc.guava.ircnow.org 396 guava.guava.ircnow.org :is your displayed hostname now
} elsif ($code =~ /^464$/) { # Invalid password for oper
foreach my $chan (@teamchans) {
- putserv($bot, "PRIVMSG $chan :$botnick oper password failed; the bot will be unable to view uncloaked IP addresses");
+ putserv($bot, "PRIVMSG $chan :$nick oper password failed; the bot will be unable to view uncloaked IP addresses");
}
} elsif ($code =~ /^477$/) { # Can't join channel
foreach my $chan (@teamchans) {
- putserv($bot, "PRIVMSG $chan :ERROR: $botnick on $server: $text");
+ putserv($bot, "PRIVMSG $chan :ERROR: $nick on $server: $text");
}
} elsif ($code == 716 && $text =~ /^([-_\|`a-zA-Z0-9]+) :is in \+g mode \(server-side ignore.\)/) {
debug(ALL, "$text");
sub isstaff {
my( $bot, $nick ) = @_;
- if( !( $bot->{name} =~ /^$localnet$/i ) )
- {
+ if( !( $bot->{name} =~ /^$localnet$/i ) ) {
return 0;
}
my $lnick = lc $nick;
foreach( @stafflist ) {
if( $lnick eq $_ ) {
return 1;
- }
+ }
}
return 0;
}