commit - a90fe83e647b257c36e5a230a373f884ea57430b
commit + 699af575932db751f5e8b569ade0eba9899dbe19
blob - 6d1272f298f32bcdae6eb5ebd14eba7c7b1570dd
blob + c8ee81d47981b713dffa41897bca374fccf23c81
--- mata_bot.pl
+++ mata_bot.pl
my $DEFAULT_HOST = 'localhost';
my $DEFAULT_LOGGING = 0;
my $DEFAULT_LOGLEVEL = 'none';
-my $DEFAULT_PATH_BALL = "/usr/local/share/matabot/ball";
-my $DEFAULT_PATH_HELLOS = "/usr/local/share/matabot/hellos";
-my $DEFAULT_PATH_QUOTES = "/usr/local/share/matabot/quotes";
+my $DEFAULT_PATH_BALL = '/usr/local/share/matabot/ball';
+my $DEFAULT_PATH_HELLOS = '/usr/local/share/matabot/hellos';
+my $DEFAULT_PATH_QUOTES = '/usr/local/share/matabot/quotes';
my $DEFAULT_PORT = 6667;
my $DEFAULT_TLS = 0;
my $MATA_CUTE = '[>.<]';
my $min = $ndice;
my $max = $ndice * $nface;
my $result = $min + int rand(1 + $max - $min);
- my $roll = "d${nface}";
+ my $roll = 'd' . $nface;
$roll = $ndice . $roll if $ndice > 1;
$reply = "${sender_nick} rolled a ${roll} and got ${result}! ${MATA_HAPPY}";
} elsif ($content =~ /\b{wb}pray+\b{wb}/) {
} elsif ($content =~ /\b{wb}bru[hv]+\b{wb}/i) {
$reply = "Did i stutter? ${MATA_NORM}";
} elsif ($content =~ /\b{wb}f+(u?ck+)? *(yo)?u+\b{wb}/i) {
- $reply = "$MATA_FLIPOFF"
+ $reply = $MATA_FLIPOFF
} elsif ($content =~ /\b{wb}i+ *l+(ove+)? *(you+|y+|u+)\b{wb}/i) {
$reply = "<3 ${MATA_HAPPY}"
} elsif ($content =~ /(thanks+|thx+|thank +(yo)?u+)( *a+ *lot+)?/i) {
my $video_id = $1;
my $response = HTTP::Tiny->new->get("https://fuyt.lab8.cz/?s=${video_id}&o=relevance");
unless ($response->{success}) {
- $reply = "failed to get title of video ${video_id} ${MATA_DEAD} ($response->{status} $response->{reason}!)";
+ $reply = "failed to get title of youtube video ${video_id} ${MATA_DEAD} ($response->{status} $response->{reason}!)";
return $message, $reply;
}
unless (length $response->{content}) {
return $message, $reply;
}
my $content = $response->{content};
- if ($content =~ m,<span class="title"><a href="https://www\.youtube\.com/watch\?v=$video_id" accesskey="0">([^<]+)</a>,i) {
+ if ($content =~ m,<span class="title"><a href="https://www\.youtube\.com/watch\?v=${video_id}" accesskey="0">([^<]+)</a>,i) {
my $title = $1;
$title =~ tr/[\000\r\n]//d;
$title = trim($title);
- $reply = "YouTube: $title";
+ $reply = "YouTube: ${title}";
} else {
- $reply = "failed to get title of video ${video_id} ${MATA_DEAD} (no videos matching ID $video_id!)";
+ $reply = "failed to get title of video ${video_id} ${MATA_DEAD} (no videos matching ID ${video_id}!)";
}
} elsif ($message =~ m,https?://[^ ]+,) {
my $url = $&;
my $title = $1;
$title =~ tr/[\000\r\n]//d;
$title = trim($title);
- $reply = "Title: $title";
+ $reply = "Title: ${title}";
} else {
$reply = "No title found (GET ${url} ${MATA_DEAD}";
}
my $s = IO::Select->new($sock);
$! = 0;
if ($s->can_write($SOCK_TIMEOUT)) {
- print $sock "$message\r\n";
+ print $sock $message . "\r\n";
logger($opts, 'info', '<- ' . $message);
return 1;
} else {
my $pongtime = time;
my $s = IO::Select->new($sock);
my %subbuffer;
+
while (1) {
my $reply;
$! = 0;
my $sender_nick = $1;
my $sender_message = $2;
($subbuffer->{$sender_nick}, $reply) = respond($lists, $subbuffer, $sender_nick, $sender_message);
- $reply = "PRIVMSG $opts->{'chan'} :" . $reply if $reply;
+ $reply = "PRIVMSG $opts->{'chan'} :${reply}" if $reply;
}
out($sock, $opts, $reply) if $reply;
} else {
$loglevel = 'error';
}
$loglevel = 'info' if $flags{'v'};
- open (my $ball_file, "<", $ball_path) or die "couldn't open ${ball_path}: $!";
+ open (my $ball_file, '<', $ball_path) or die "couldn't open ${ball_path}: $!";
chomp(my @ball = <$ball_file>);
- close $ball_file or die "$ball_file: $!";
- open (my $hellos_file, "<", $hellos_path) or die "couldn't open ${hellos_path}: $!";
+ close $ball_file or die "${ball_file}: $!";
+ open (my $hellos_file, '<', $hellos_path) or die "couldn't open ${hellos_path}: $!";
chomp(my @hellos = <$hellos_file>);
- close $hellos_file or die "$hellos_file: $!";
- open (my $quotes_file, "<", $quotes_path) or die "couldn't open ${quotes_path}: $!";
+ close $hellos_file or die "${hellos_file}: $!";
+ open (my $quotes_file, '<', $quotes_path) or die "couldn't open ${quotes_path}: $!";
chomp(my @quotes = <$quotes_file>);
- close $quotes_file or die "$quotes_file: $!";
+ close $quotes_file or die "${quotes_file}: $!";
return {
chan => $chan,
}
if ($sock) {
# set user, real, and nick, then join
- out($sock, $opts, "USER $USER * * :$REAL");
- out($sock, $opts, "NICK $NICK");
+ out($sock, $opts, "USER ${USER} * * :${REAL}");
+ out($sock, $opts, "NICK ${NICK}");
out($sock, $opts, "JOIN $opts->{'chan'}");
# main loop
evasdrop($sock, $opts, $lists);
# end session and sleep a bit before reconnecting
- out($sock, $opts, "QUIT");
+ out($sock, $opts, 'QUIT');
if ($opts->{'tls'}) {
close($sock);
} else {
blob - e2e62c699dc5352313eca77a110a2ff350a71f7d
blob + ebd9f6486ba55eded0c351545d53fbf2a366a585
--- matabot.8
+++ matabot.8
.It Fl t
Turn on TLS.
.It Fl v
-Produce more verbose output.
+Produce more verbose output (logs all irc events in addition to errors).
.El
.Sh COMMANDS
Bot can do some tricks (non-exhaustive, or it won't be funny):
Typical invocation
.Po use these flags in your Pa /etc/rc.conf.local Pc Ns :
.Pp
-.Dl $ matabot -th irc.server.tld -j #analognowhere -p 6697
+.Dl $ matabot -lth irc.server.tld -j #analognowhere -p 6697
.Pp
Test on a local ircd with verbose logging turned on.
(No TLS):