« blib/lib/Bot/BasicBot/Pluggable/Module/Seen.pm
↑ Summary
blib/lib/Bot/BasicBot/Pluggable/Module/Google.pm »
| 1 | package Bot::BasicBot::Pluggable::Module::Join; | ||
| 2 | $Bot::BasicBot::Pluggable::Module::Join::VERSION = '1.11'; | ||
| 3 | use base qw(Bot::BasicBot::Pluggable::Module); | ||
| 4 | use warnings; | ||
| 5 | use strict; | ||
| 6 | |||
| 7 | sub connected { | ||
| 8 | my $self = shift; | ||
| 9 | my $channels = $self->get("channels") || []; | ||
| 10 | |||
| 11 | ## If we are not a array reference, we are problably the old | ||
| 12 | ## string format ... trying to convert | ||
| 13 | if ( not ref($channels) && $channels =~ 'ARRAY' ) { | ||
| 14 | $channels = [ split( /\s+/, $channels ) ]; | ||
| 15 | } | ||
| 16 | |||
| 17 | for ( @{$channels} ) { | ||
| 18 | print "Joining $_.\n"; | ||
| 19 | $self->bot->join($_); | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | sub help { | ||
| 24 | return | ||
| 25 | "Join and leave channels. Usage: join <channel>, leave/part <channel>, channels. Requires direct addressing."; | ||
| 26 | } | ||
| 27 | |||
| 28 | sub told { | ||
| 29 | my ( $self, $mess ) = @_; | ||
| 30 | my $body = $mess->{body}; | ||
| 31 | return unless defined $body; | ||
| 32 | return unless $mess->{address}; | ||
| 33 | |||
| 34 | my ( $command, $param ) = split( /\s+/, $body, 2 ); | ||
| 35 | $command = lc($command); | ||
| 36 | return unless $command =~ /^(join|leave|part|channels)$/; | ||
| 37 | |||
| 38 | if (!$self->authed($mess->{who})) { | ||
| 39 | return "Sorry, you must be authenticated to do that."; | ||
| 40 | } | ||
| 41 | |||
| 42 | if ( $command eq "join" ) { | ||
| 43 | $self->add_channel($param); | ||
| 44 | return "Ok."; | ||
| 45 | |||
| 46 | } | ||
| 47 | elsif ( $command eq "leave" or $command eq "part" ) { | ||
| 48 | $self->remove_channel( $param || $mess->{channel} ); | ||
| 49 | return "Ok."; | ||
| 50 | |||
| 51 | } | ||
| 52 | elsif ( $command eq "channels" ) { | ||
| 53 | my @channels = $self->bot->channels; | ||
| 54 | my $channel_num = scalar @channels; | ||
| 55 | if ( $channel_num == 0 ) { | ||
| 56 | return "I'm not in any channel."; | ||
| 57 | } | ||
| 58 | elsif ( $channel_num == 1 ) { | ||
| 59 | return "I'm in " . $channels[0] . "."; | ||
| 60 | } | ||
| 61 | elsif ( $channel_num == 2 ) { | ||
| 62 | return "I'm in " . $channels[0] . " and " . $channels[1] . "."; | ||
| 63 | } | ||
| 64 | else { | ||
| 65 | return | ||
| 66 | "I'm in " | ||
| 67 | . join( ', ', @channels[ 0 .. $#channels - 1 ] ) | ||
| 68 | . " and $channels[-1]."; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | sub chanjoin { | ||
| 74 | my ( $self, $mess ) = @_; | ||
| 75 | if ( $mess->{who} eq $self->bot->nick ) { | ||
| 76 | $self->set( channels => [ $self->bot->channels ] ); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | sub chanpart { | ||
| 81 | my ( $self, $mess ) = @_; | ||
| 82 | if ( $mess->{who} eq $self->bot->nick ) { | ||
| 83 | $self->set( channels => [ $self->bot->channels ] ); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | sub add_channel { | ||
| 88 | my ( $self, $channel ) = @_; | ||
| 89 | $self->bot->join($channel); | ||
| 90 | } | ||
| 91 | |||
| 92 | sub remove_channel { | ||
| 93 | my ( $self, $channel ) = @_; | ||
| 94 | $self->bot->part($channel); | ||
| 95 | } | ||
| 96 | |||
| 97 | 1; | ||
| 98 | |||
| 99 | __END__ | ||
| 100 | |||
| 101 | =head1 NAME | ||
| 102 | |||
| 103 | Bot::BasicBot::Pluggable::Module::Join - join and leave channels; remembers state | ||
| 104 | |||
| 105 | =head1 VERSION | ||
| 106 | |||
| 107 | version 1.11 | ||
| 108 | |||
| 109 | =head1 IRC USAGE | ||
| 110 | |||
| 111 | =over 4 | ||
| 112 | |||
| 113 | =item join <channel> | ||
| 114 | |||
| 115 | =item part <channel> | ||
| 116 | |||
| 117 | =item channels | ||
| 118 | |||
| 119 | List the channels the bot is in. | ||
| 120 | |||
| 121 | =back | ||
| 122 | |||
| 123 | =head1 METHODS | ||
| 124 | |||
| 125 | =over 4 | ||
| 126 | |||
| 127 | =item add_channel($channel) | ||
| 128 | |||
| 129 | =item remove_channel($channel) | ||
| 130 | |||
| 131 | =back | ||
| 132 | |||
| 133 | =head1 AUTHOR | ||
| 134 | |||
| 135 | Mario Domgoergen <mdom@cpan.org> | ||
| 136 | |||
| 137 | This program is free software; you can redistribute it | ||
| 138 | and/or modify it under the same terms as Perl itself. |