commit 102b2e6e6634df3e03066f106bc46286831cd18f from: jrmu date: Sun Feb 19 02:30:40 2023 UTC Reorganized parts of code, deleted useless tests commit - 166ac4ea24eeb6b169040d1a333fbfd79309d661 commit + 102b2e6e6634df3e03066f106bc46286831cd18f blob - fcfec55c54b5ee70d0a8bc4865067d055d38956d blob + ba922b7604d9d33f2dd10e4ca0de13f97ab866e7 --- botnow +++ botnow @@ -42,6 +42,22 @@ sub appendfile { close $fh; } +# Returns date in YYYYMMDD format +sub date { + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); + my $localtime = sprintf("%04d%02d%02d", $year+1900, $mon+1, $mday); + return $localtime; +} + +# Returns timestamp in "Day MM DD HH:MM:SS" format +sub gettime { + 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 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); + my $localtime = sprintf("%s %s %d %02d:%02d:%02d", $days[$wday], $months[$mon], $mday, $hour, $min, $sec); + return $localtime; +} + # Path to configuration file my $confpath = "botnow.conf"; @@ -138,8 +154,6 @@ foreach my $mod (@modules) { } 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 @chans = split /[,\s]+/m, $conf{chans}; my @teamchans; if (defined($conf{teamchans})) { @teamchans = split /[,\s]+/m, $conf{teamchans}; } @@ -192,10 +206,7 @@ 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 =~ /^$nick.?$/ && $text eq "Welcome to ZNC") { - } elsif ($type eq "NOTICE" && $target =~ /^$nick.?$/ && $text eq "*** To connect now, you can use /quote PASS :, or /quote PASS /: 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") { + if ($type eq "464" && $target =~ /^$nick.?$/ && $text eq "Password required") { putserv($bot, "PASS $nick/$bot->{name}:$pass"); if ($bot->{name} =~ /^$localnet$/i) { putserv($bot, "OPER $nick $pass"); @@ -214,7 +225,7 @@ while(my @ready = $sel->can_read) { } elsif ($type eq "464" && $target =~ /^$nick.?$/ && $text eq "Invalid Password") { die "ERROR: Wrong Username/Password: $bot->{name}"; } else { - debug(ERRORS, "ERROR: Unexpected type: $type, target: $target, text: $text"); + debug(ALL, "Debug type: $type, target: $target, text: $text"); } } elsif($response =~ /^:(([^!]+)!([^@]+@[^@ ]+)) PRIVMSG ([^ ]+) :(.*)\r\n$/i) { my ($hostmask, $sendnick, $host, $target, $text) = ($1, $2, $3, $4, $5); @@ -488,19 +499,7 @@ sub putservlocalnet { } } putserv($botlocalnet, $text); -} - - -sub date { - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); - my $localtime = sprintf("%04d%02d%02d", $year+1900, $mon+1, $mday); - return $localtime; } -sub gettime { - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); - my $localtime = sprintf("%s %s %d %02d:%02d:%02d", $days[$wday], $months[$mon], $mday, $hour, $min, $sec); - return $localtime; -} sub whois { my( $socket, $target )=@_;