Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 100 lines (79 sloc) 2.39 kB
c4adef7 @rbuels initial commit
authored
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4
5 chdir $ARGV[0] if @ARGV;
6
7 use local::lib './local_lib';
8 use POE qw(Component::IRC);
9 use Config::General;
10
11 my @channels = do {
12 my %c = read_config();
13 map "#$_", keys %c
14 };
15
16 # We create a new PoCo-IRC object
17 my $irc = POE::Component::IRC->spawn(
18 nick => 'radicalweed',
19 ircname => 'the SGN Op Bot - Solanum carolinense',
20 server => 'irc.perl.org',
21 ) or die "Oh noooo! $!";
22
23 POE::Session->create(
24 package_states => [ main => [qw( _start irc_001 irc_join )], ],
25 heap => { irc => $irc },
26 );
27
28 $poe_kernel->run();
29
30 sub _start {
31 my $heap = $_[HEAP];
32
33 # retrieve our component's object from the heap where we stashed it
34 my $irc = $heap->{irc};
35
36 $irc->yield( register => 'all' );
37 $irc->yield( connect => {} );
38 return;
39 }
40
41 sub irc_001 {
42 my $sender = $_[SENDER];
43
44 # Since this is an irc_* event, we can get the component's object by
45 # accessing the heap of the sender. Then we register and connect to the
46 # specified server.
47 my $irc = $sender->get_heap();
48
49 print "Connected to ", $irc->server_name(), "\n";
50
51 # we join our channels
52 $irc->yield( join => $_ ) for @channels;
53 return;
54 }
55
56 sub irc_join {
57 my ( $sender, $who, $where, $what ) = @_[ SENDER, ARG0 .. ARG2 ];
58 my $nick = ( split /!/, $who )[0];
59 my $channel = ref $where ? $where->[0] : $where;
60 $channel =~ s/^#//;
61
62 my %config = read_config();
63 if( exists $config{$channel}{$nick} ) {
64 $irc->yield( mode => "#$channel" => '+o' => $nick );
65 }
66 }
67
68 sub read_config {
69 return Config::General->new('./radicalweed.conf')->getall;
70 }
71
72 # sub irc_public {
73 # my ( $sender, $who, $where, $what ) = @_[ SENDER, ARG0 .. ARG2 ];
74 # my $nick = ( split /!/, $who )[0];
75 # my $channel = $where->[0];
76
77 # if ( my ($rot13) = $what =~ /^rot13 (.+)/ ) {
78 # $rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];
79 # $irc->yield( privmsg => $channel => "$nick: $rot13" );
80 # }
81 # return;
82 # }
83
84 # We registered for all events, this will produce some debug info.
85 sub _default {
86 my ( $event, $args ) = @_[ ARG0 .. $#_ ];
87 my @output = ("$event: ");
88
89 for my $arg (@$args) {
90 if ( ref $arg eq 'ARRAY' ) {
91 push( @output, '[' . join( ', ', @$arg ) . ']' );
92 }
93 else {
94 push( @output, "'$arg'" );
95 }
96 }
97 print join ' ', @output, "\n";
98 return 0;
99 }
Something went wrong with that request. Please try again.