From ac60b2267496a6f5659281b0d9940136e96b4045 Mon Sep 17 00:00:00 2001 From: Matthew Barksdale Date: Wed, 2 Feb 2011 15:47:59 -0500 Subject: [PATCH] Added a very simple IsItUp module. --- doc/CHANGELOG | 1 + modules/IsItUp.pm | 126 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 modules/IsItUp.pm diff --git a/doc/CHANGELOG b/doc/CHANGELOG index 74df06c..de88fb6 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev ================================================================== + * Added IsItUp module. * Added user:net for network-specific user blocks. * Bug fix: Fixed broken no-parameter config blocks. * Added core command SHUTDOWN. diff --git a/modules/IsItUp.pm b/modules/IsItUp.pm new file mode 100644 index 0000000..05623d9 --- /dev/null +++ b/modules/IsItUp.pm @@ -0,0 +1,126 @@ +# Auto IRC Bot. An advanced, lightweight and powerful IRC bot. +# Copyright (C) 2010-2011 Xelhua Development Team (doc/CREDITS) +# This program is free software; rights to this code are stated in doc/LICENSE. +package m_IsItUp; +use strict; +use warnings; +use API::Std qw(cmd_add cmd_del trans); +use API::IRC qw(privmsg notice); +use LWP::UserAgent; + +# Initialization subroutine. +sub _init +{ + # Create the ISITUP command. + cmd_add("ISITUP", 0, \%m_IsItUp::SHELP_ISITUP, \%m_IsItUp::FHELP_ISITUP, \&m_IsItUp::check) or return 0; + + # Success. + return 1; +} + +# Void subroutine. +sub _void +{ + # Delete the ISITUP command. + cmd_del("ISITUP") or return 0; + + # Success. + return 1; +} + +# Help hashes. +our %SHELP_ISITUP = ( + 'en' => "Checks if a website is up.", + ); + +our %FHELP_ISITUP = ( + 'en' => "This command will check if a website appears up or down to the bot. Syntax: ISITUP ", + ); + +# Callback for ISITUP command. +sub check +{ + my (%data) = @_; + + # Create an instance of LWP::UserAgent. + my $ua = LWP::UserAgent->new(); + $ua->agent('Auto IRC Bot'); + $ua->timeout(2); + my @args = @{ $data{args} }; + my $curl = $args[0]; + # Do we have enough parameters? + if (!defined $args[0]) { + notice($data{svr}, $data{nick}, trans("Not enough parameters")."."); + return 0; + } + # Does the URL start with http(s)? + if ($curl !~ m/^http/) { + $curl = "http://".$curl; + } + + # Get the response via HTTP. + my $response = $ua->get($curl); + + if ($response->is_success) { + # If successful, it's up. + privmsg($data{svr}, $data{chan}, $curl." appears to be up from here."); + } + else { + # Otherwise, it's down. + privmsg($data{svr}, $data{chan}, $curl." appears to be down from here."); + } + + return 1; +} + +# Start initialization. +API::Std::mod_init("IsItUp", "Xelhua", "1.00", "3.0.0d", __PACKAGE__); + +__END__ + +=head1 IsItUp + +=head2 Description + +=over + +This module adds the ISITUP command for checking if a +website appears up or down to Auto. + +=back + +=head2 How To Use + +=over + +Add IsItUp to the module autoload. + +=back + +=head2 Examples + +=over + + !isitup http://google.com + http://google.com appears to be up from here. + +=back + +=head2 To Do + +=over + +* Add Spanish, French and German translations for the help hashes. + +=back + +=head2 Technical + +=over + +This module requires LWP::UserAgent. All are obtainable +from the CPAN . + +This module is compatible with Auto version 3.0a2+. + +=back