瀏覽代碼

Naive implementation

Andy Baugh 8 年之前
父節點
當前提交
2e0cf20f89
共有 4 個文件被更改,包括 26 次插入14 次删除
  1. 1 1
      Makefile
  2. 6 5
      lib/Cpanel/iContact/Provider.pm
  3. 12 0
      lib/Cpanel/iContact/Provider/IRC.pm
  4. 7 8
      t/Cpanel-iContact-Provider-IRC.t

+ 1 - 1
Makefile

@@ -10,4 +10,4 @@ test:
 	[ -x /usr/local/cpanel/3rdparty/bin/prove ] || prove t/*.t
 
 depend:
-	perl -MNet::XMPP -MMozilla::CA -MTest::More -MTest::Fatal -MTest::MockModule -MConfig::Simple -e 'exit 0;' || sudo cpan -i Net::XMPP Mozilla::CA Test::More Test::Fatal Test::MockModule Config::Simple
+	perl -MNet::XMPP -MMozilla::CA -MTest::More -MTest::Fatal -MTest::MockModule -MConfig::Simple -MBot::BasicBot -e 'exit 0;' || sudo cpan -i Net::XMPP Mozilla::CA Test::More Test::Fatal Test::MockModule Config::Simple Bot::BasicBot

+ 6 - 5
lib/Cpanel/iContact/Provider.pm

@@ -11,11 +11,12 @@ sub new {
     my $text_body = 'HOLY CRAP THE AUTO-LAYOFF THING TRIGGERED';
     my $self = {
         'contact' => {
-            'XMPPUSERNAME'  => 'mr_t@a-team.gov',
-            'XMPPPASSWORD'  => 'bjBarracus#1',
-            'XMPPUSETLS'    => 1,
-            'XMPPTLSVERIFY' => 1,
-            'XMPPCOMPONENTNAME' => 'jibber.jabber.org'
+            'XMPPUSERNAME'      => 'mr_t@a-team.gov',
+            'XMPPPASSWORD'      => 'bjBarracus#1',
+            'XMPPUSETLS'        => 1,
+            'XMPPTLSVERIFY'     => 1,
+            'XMPPCOMPONENTNAME' => 'jibber.jabber.org',
+            'IRCSERVER'         => 'irc.bot.test',
         },
         'args' => {
             'subject'   => 'cPanel on Drugs',

+ 12 - 0
lib/Cpanel/iContact/Provider/IRC.pm

@@ -7,6 +7,8 @@ use parent 'Cpanel::iContact::Provider';
 
 sub send {
     my ($self) = @_;
+    my @missing = grep { !defined $self->{'contact'}{$_} } qw{IRCSERVER};
+    die "Kit not complete! Missing: " . join( ", ", @missing ) if scalar( @missing );
 
     my $args_hr = $self->{'args'};
     my @errs;
@@ -42,6 +44,16 @@ sub send {
 sub _send {
     my ( $self, %args ) = @_;
     require Bot::BasicBot;
+    my $bot = Bot::BasicBot->new(
+        'server'   => $self->{'contact'}{'IRCSERVER'},
+        'port'     => $self->{'contact'}{'IRCPORT'} || 6667,
+        'channels' => $args{'destination'},
+        'nick'     => $self->{'contact'}{'IRCNICK'} || 'cPanel_&_WHM',
+        'ssl'      => $self->{'contact'}{'IRCUSESSL'},
+    );
+    $bot->say( { 'body' => $args{'subject'} } );
+    $bot->say( { 'body' => $args{'content'} } );
+    $bot->shutdown();
 
     return;
 }

+ 7 - 8
t/Cpanel-iContact-Provider-IRC.t

@@ -7,18 +7,17 @@ use lib abs_path( dirname(__FILE__) . "/../lib" );
 
 use Test::More 'tests' => 5;
 use Test::Fatal;
-use Config::Simple ();
+use Bot::BasicBot ();
 
-is( exception { require Cpanel::iContact::Provider::XMPP; }, undef, 'Module at least compiles' );
-isa_ok( my $xmpp = Cpanel::iContact::Provider::XMPP->new(), "Cpanel::iContact::Provider::XMPP" );
+is( exception { require Cpanel::iContact::Provider::IRC; }, undef, 'Module at least compiles' );
+isa_ok( my $bot = Cpanel::iContact::Provider::IRC->new(), "Cpanel::iContact::Provider::IRC" );
 my $sent;
 {
     no warnings qw{redefine once};
-    local *Bot::BasicBot::new     = sub { return bless {}, "Bot::BasicBot"; };
-    local *Bot::BasicBot::AuthSend    = sub { return ( 'ok', "Assumed Success" ); };
-    local *Bot::BasicBot::MessageSend = sub { return; };
-    local *Bot::BasicBot::Disconnect  = sub { return; };
-    is( exception { $sent = $xmpp->send(); }, undef, 'send() did not die' );
+    local *Bot::BasicBot::new      = sub { return bless {}, "Bot::BasicBot"; };
+    local *Bot::BasicBot::say      = sub { return ( 'ok', "Assumed Success" ); };
+    local *Bot::BasicBot::shutdown = sub { return; };
+    is( exception { $sent = $bot->send(); }, undef, 'send() did not throw' );
 }
 ok( $sent, "...and the message appears to have actually sent." );