Added slog() to API::Log.

This commit is contained in:
Elijah Perrault committed 2011-02-14 14:59:07 -07:00
1 parent 50a3f73a82
commit a75e3ee771
3 files changed
+38 -1

No files matched your search

+1
View File
@@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log
3.0 Indev
===============================================================================
* Added slog() to API::Log for logging to IRC.
* Added a Greet module for greeting users on join.
* Added PostgreSQL support. Official modules do not support this yet.
* database:format now a required configuration value.
+3
View File
@@ -107,6 +107,9 @@ database {
# Locale.
locale "en_US";
# Logging to IRC. Uncomment this and set it to setup an IRC logchan.
# logchan "Freenode/#logchan";
# Expire logs in days. 0 disables.
expire_logs 15;
+34 -1
View File
@@ -11,7 +11,7 @@ use Exporter;
use base qw(Exporter);
use API::Std qw(conf_get);
our @EXPORT_OK = qw(println dbug alog);
our @EXPORT_OK = qw(println dbug alog slog);
# Print with the system newline appended.
@@ -107,6 +107,39 @@ sub expire_logs
return 1;
}
# Subroutine for logging to an IRC logchan.
sub slog
{
my ($msg) = @_;
# Check if logging to channel is enabled.
if (conf_get('logchan')) {
# It is, continue.
# Split the network and channel.
my ($net, $chan) = split '/', (conf_get('logchan'))[0][0];
$chan = lc $chan;
# Check if we're connected to the network.
if (!defined $Auto::SOCKET{$net}) {
dbug 'WARNING: slog(): Unable to log to IRC: Not connected to network.';
alog 'WARNING: slog(): Unable to log to IRC: Not connected to network.';
return;
}
# Check if we're in the channel.
if (!defined $Parser::IRC::botchans{$net}{$chan}) {
dbug 'WARNING: slog(): Unable to log to IRC: Not in channel.';
alog 'WARNING: slog(): Unable to log to IRC: Not in channel.';
return;
}
# Log to IRC.
API::IRC::privmsg($net, $chan, "\002LOG:\002 $msg");
}
return 1;
}
1;
# vim: set ai sw=4 ts=4: