Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

initial commit

  • Loading branch information...
commit c4adef79ebf7d4a50813c41e5930897f465decc3 0 parents
Robert Buels authored March 19, 2010
1  .gitignore
... ...
@@ -0,0 +1 @@
  1
+local_lib
13  radicalweed.conf
... ...
@@ -0,0 +1,13 @@
  1
+# each section is a channel for the bot to join
  2
+# and in that section, just list the nicks that the bot
  3
+# should give op to (set +o)
  4
+     <cxgn>
  5
+           adri
  6
+           aure
  7
+           isaak
  8
+           jrg72
  9
+   	   diracshard
  10
+           mueller
  11
+           naama
  12
+           rbuels
  13
+     </cxgn>
99  radicalweed.pl
... ...
@@ -0,0 +1,99 @@
  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
+}

0 notes on commit c4adef7

Please sign in to comment.
Something went wrong with that request. Please try again.