IRC.pm 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package Cpanel::iContact::Provider::IRC;
  2. use strict;
  3. use warnings;
  4. use parent 'Cpanel::iContact::Provider';
  5. sub send {
  6. my ($self) = @_;
  7. my @missing = grep { !defined $self->{'contact'}{$_} } qw{IRCSERVER};
  8. die "Kit not complete! Missing: " . join( ", ", @missing ) if scalar( @missing );
  9. my $args_hr = $self->{'args'};
  10. my @errs;
  11. my $subject_copy = $args_hr->{'subject'};
  12. my $body_copy = ${ $args_hr->{'text_body'} };
  13. require Encode;
  14. my $subject = Encode::decode_utf8( $subject_copy, $Encode::FB_QUIET );
  15. my $body = Encode::decode_utf8( $body_copy, $Encode::FB_QUIET );
  16. foreach my $destination ( @{ $args_hr->{'to'} } ) {
  17. local $@;
  18. eval {
  19. my $response;
  20. $self->_send(
  21. 'destination' => $destination,
  22. 'subject' => $subject,
  23. 'content' => $body
  24. );
  25. };
  26. push( @errs, $@ ) if $@;
  27. }
  28. if (@errs) {
  29. die "One or more notification attempts failed. Details below:\n"
  30. . join( "\n", @errs );
  31. }
  32. return 1;
  33. }
  34. sub _send {
  35. my ( $self, %args ) = @_;
  36. require Bot::BasicBot;
  37. my $bot = Bot::BasicBot->new(
  38. 'server' => $self->{'contact'}{'IRCSERVER'},
  39. 'port' => $self->{'contact'}{'IRCPORT'} || 6667,
  40. 'channels' => $args{'destination'},
  41. 'nick' => $self->{'contact'}{'IRCNICK'} || 'cPanel_&_WHM',
  42. 'ssl' => $self->{'contact'}{'IRCUSESSL'},
  43. );
  44. $bot->say( { 'body' => $args{'subject'} } );
  45. $bot->say( { 'body' => $args{'content'} } );
  46. $bot->shutdown();
  47. return;
  48. }
  49. 1;