Added a BotStats module for returning statistics about the bot.
This commit is contained in:
1 parent
501dd30a0b
commit
a8b8256385
3 files changed
+118
-1
No files matched your search
@@ -15,10 +15,11 @@ In this alpha6 release, we have added:
|
|||||||
|
|
||||||
* Added an UNO module for playing the classic game of UNO.
|
* Added an UNO module for playing the classic game of UNO.
|
||||||
* Added an Eval module for evaluating Perl code.
|
* Added an Eval module for evaluating Perl code.
|
||||||
|
* Added a BotStats module for returning statistics about the bot.
|
||||||
|
|
||||||
Bug fixes:
|
Bug fixes:
|
||||||
|
|
||||||
None
|
* Fixed a bug that occurs when our configured nickname is in use.
|
||||||
|
|
||||||
Incompatibilities:
|
Incompatibilities:
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log
|
|||||||
|
|
||||||
3.0 Indev
|
3.0 Indev
|
||||||
===============================================================================
|
===============================================================================
|
||||||
|
* Added a BotStats module for returning statistics about the bot.
|
||||||
* Now parsing numeric 396.
|
* Now parsing numeric 396.
|
||||||
* Added who() to API::IRC.
|
* Added who() to API::IRC.
|
||||||
* Added hook on_whoreply.
|
* Added hook on_whoreply.
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
# Module: BotStats. See below for documentation.
|
||||||
|
# Copyright (C) 2010-2011 Xelhua Development Group, et al.
|
||||||
|
# This program is free software; rights to this code are stated in doc/LICENSE.
|
||||||
|
package M::BotStats;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use English qw(-no_match_vars);
|
||||||
|
use API::Std qw(cmd_add cmd_del);
|
||||||
|
use API::IRC qw(privmsg);
|
||||||
|
|
||||||
|
# Initialization subroutine.
|
||||||
|
sub _init {
|
||||||
|
# Create the STATS command.
|
||||||
|
cmd_add('STATS', 2, 0, \%M::BotStats::HELP_STATS, \&M::BotStats::stats) or return;
|
||||||
|
|
||||||
|
# Success.
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Void subroutine.
|
||||||
|
sub _void {
|
||||||
|
# Delete the STATS command.
|
||||||
|
cmd_del('STATS') or return;
|
||||||
|
|
||||||
|
# Success.
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Help hash for STATS. Spanish, German and French translations needed.
|
||||||
|
our %HELP_STATS = (
|
||||||
|
'en' => "This command will return information about the bot (uptime, version, etc.). \2Syntax:\2 STATS",
|
||||||
|
);
|
||||||
|
|
||||||
|
# Callback for STATS command.
|
||||||
|
sub stats {
|
||||||
|
my ($src, undef) = @_;
|
||||||
|
|
||||||
|
# Check if this was private or public.
|
||||||
|
my $target;
|
||||||
|
if ($src->{chan}) {
|
||||||
|
$target = $src->{chan};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$target = $src->{nick};
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get uptime data.
|
||||||
|
my $uptime = time - $Auto::STARTTIME;
|
||||||
|
my $days = my $hours = my $mins = my $secs = 0;
|
||||||
|
while ($uptime >= 86_400) { $days++; $uptime -= 86_400; }
|
||||||
|
while ($uptime >= 3_600) { $hours++; $uptime -= 3_600; }
|
||||||
|
while ($uptime >= 60) { $mins++; $uptime -= 60; }
|
||||||
|
while ($uptime >= 1) { $secs++; $uptime--; }
|
||||||
|
|
||||||
|
# Return it.
|
||||||
|
privmsg($src->{svr}, $target, "I have been running for \2$days\2 days, \2$hours\2 hours, \2$mins\2 minutes, and \2$secs\2 seconds.");
|
||||||
|
|
||||||
|
# Return version data.
|
||||||
|
privmsg($src->{svr}, $target, 'I am running '.Auto::NAME.' (version '.Auto::VER.q{.}.Auto::SVER.q{.}.Auto::REV.Auto::RSTAGE.") for Perl $PERL_VERSION on $OSNAME.");
|
||||||
|
|
||||||
|
# Get network and channel data.
|
||||||
|
my $nets = keys %Auto::SOCKET;
|
||||||
|
my $chans;
|
||||||
|
foreach my $net (keys %Auto::SOCKET) {
|
||||||
|
foreach (keys %{$Proto::IRC::botchans{$net}}) { $chans++; }
|
||||||
|
}
|
||||||
|
|
||||||
|
# Return network/channel data.
|
||||||
|
privmsg($src->{svr}, $target, "I am on \2$chans\2 channels, across \2$nets\2 networks.");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
API::Std::mod_init('BotStats', 'Xelhua', '1.00', '3.0.0a6', __PACKAGE__);
|
||||||
|
# vim: set ai et sw=4 ts=4:
|
||||||
|
# build: perl=5.010000
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
BotStats - General information about the bot
|
||||||
|
|
||||||
|
=head1 VERSION
|
||||||
|
|
||||||
|
1.00
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
<starcoder> !stats
|
||||||
|
<blue> I have been running for 0 days, 0 hours, 1 minutes, and 5 seconds.
|
||||||
|
<blue> I am running Auto IRC Bot (version 3.0.0a6) for Perl v5.12.3 on linux.
|
||||||
|
<blue> I am on 2 channels, across 1 networks.
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
This module creates the STATS command, for returning general information about
|
||||||
|
the bot such as uptime, version, etc.
|
||||||
|
|
||||||
|
This module is compatible with Auto v3.0.0a6+.
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
This module was written by Elijah Perrault.
|
||||||
|
|
||||||
|
This module is maintained by Xelhua Development Group.
|
||||||
|
|
||||||
|
=head1 LICENSE AND COPYRIGHT
|
||||||
|
|
||||||
|
This module is Copyright 2010-2011 Xelhua Development Group.
|
||||||
|
|
||||||
|
This module is released under the same licensing terms as Auto itself.
|
||||||
|
|
||||||
|
=cut
|
||||||
Reference in new issue
Block a user