Created
February 24, 2017 05:48
-
-
Save usrbinsam/f3de51200fb25722847c870d752dc666 to your computer and use it in GitHub Desktop.
irccat in POE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# see https://metacpan.org/pod/POE::Component::IRC | |
use strict; | |
use warnings; | |
use POE qw/ | |
Component::IRC | |
Component::IRC::Plugin::FollowTail | |
/; | |
my $channel = '#irccat'; | |
my %tail_files = ( | |
everything => "/var/log/everything/current", | |
sshd => "/var/log/sshd/current", | |
kernel => "/var/log/kernel/current", | |
mail => "/var/log/mail/current", | |
critical => "/var/log/critical/current", | |
crond => "/var/log/cron/current", | |
); | |
my $irc = POE::Component::IRC->spawn( | |
Nick => 'irccat', | |
Username => 'irccat', | |
Ircname => 'irccat in POE::Component::IRC', | |
UseSSL => 1, | |
Server => '127.0.0.1', | |
Port => 1217, | |
Flood => 1, # disable internal throtlting | |
Password => '', # server PASS | |
# SSLCert => '', | |
# SSLKey => '', | |
# SSLCtx => '' # if you want to make your own contexts | |
); | |
POE::Session->create( | |
package_states => [ | |
main => [ qw/ | |
_start | |
irc_001 | |
irc_tail_input | |
irc_tail_reset | |
/ ] | |
], | |
heap => { irc => $irc } | |
); | |
sub _start | |
{ | |
my ($heap) = $_[ HEAP ]; | |
# XXX: should we add this to irc_001 after joining? | |
while (my ($alias, $filename) = each %tail_files) { | |
$heap->{irc}->plugin_add("follow_tail_$alias" => POE::Component::IRC::Plugin::FollowTail->new(filename => $filename)) | |
} | |
$heap->{irc}->yield(register => 'all'); | |
$heap->{irc}->yield(connect => { }); | |
} | |
sub irc_001 | |
{ | |
$_[HEAP]->{irc}->yield(join => $channel) | |
} | |
sub irc_tail_input | |
{ | |
my ($heap, $filename, $input) = @_[ HEAP, ARG0, ARG1 ]; | |
# XXX: can buffer messages here if we're not in the channel | |
# yet with POE::Component::IRC::State if we really wanted to. | |
# | |
# $input =~ s///; # or whatever you want here | |
# | |
$heap->{irc}->yield(privmsg => $channel => $input) | |
} | |
sub irc_tail_reset | |
{ | |
my ($heap, $filename) = @_[ HEAP, ARG0 ]; | |
$heap->{irc}->yield(privmsg => $channel => "--- $filename reset ---") | |
} | |
POE::Kernel->run; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment