- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
r5ff830a reab7a4c 10 10 =head1 DESCRIPTION 11 11 12 This module is a wrapper around Net::IRC::Connectionfor BarnOwl's IRC12 This module is a Net::IRC::Connection subclass for BarnOwl's IRC 13 13 support 14 14 15 15 =cut 16 16 17 use Net::IRC::Connection; 18 19 use base qw(Class::Accessor Exporter); 20 __PACKAGE__->mk_accessors(qw(conn alias channels connected motd)); 17 use base qw(Net::IRC::Connection Class::Accessor Exporter); 18 __PACKAGE__->mk_accessors(qw(alias channels owl_connected owl_motd)); 21 19 our @EXPORT_OK = qw(&is_private); 22 20 23 21 use BarnOwl; 24 25 BEGIN {26 no strict 'refs';27 my @delegate = qw(nick server);28 for my $meth (@delegate) {29 *{"BarnOwl::Module::IRC::Connection::$meth"} = sub {30 shift->conn->$meth(@_);31 }32 }33 };34 22 35 23 sub new { … … 38 26 my $alias = shift; 39 27 my %args = (@_); 40 my $conn = Net::IRC::Connection->new($irc, %args); 41 my $self = bless({}, $class); 42 $self->conn($conn); 28 my $self = $class->SUPER::new($irc, %args); 43 29 $self->alias($alias); 44 30 $self->channels([]); 45 $self->motd(""); 46 $self->connected(0); 47 48 $self->conn->add_handler(376 => sub { shift; $self->on_connect(@_) }); 49 $self->conn->add_default_handler(sub { shift; $self->on_event(@_) }); 50 $self->conn->add_handler(['msg', 'notice', 'public', 'caction'], 51 sub { shift; $self->on_msg(@_) }); 52 $self->conn->add_handler(['welcome', 'yourhost', 'created', 53 'luserclient', 'luserop', 'luserchannels', 'luserme', 54 'notice', 'error'], 55 sub { shift; $self->on_admin_msg(@_) }); 56 $self->conn->add_handler(['myinfo', 'map', 'n_local', 'n_global', 31 $self->owl_motd(""); 32 $self->owl_connected(0); 33 bless($self, $class); 34 35 $self->add_default_handler(sub { goto &on_event; }); 36 $self->add_handler(['msg', 'notice', 'public', 'caction'], 37 sub { goto &on_msg }); 38 $self->add_handler(['welcome', 'yourhost', 'created', 39 'luserclient', 'luserop', 'luserchannels', 'luserme'], 40 sub { goto &on_admin_msg }); 41 $self->add_handler(['myinfo', 'map', 'n_local', 'n_global', 57 42 'luserconns'], 58 43 sub { }); 59 $self-> conn->add_handler(motdstart => sub { shift; $self->on_motdstart(@_)});60 $self-> conn->add_handler(motd => sub { shift; $self->on_motd(@_)});61 $self-> conn->add_handler(endofmotd => sub { shift; $self->on_endofmotd(@_)});62 $self-> conn->add_handler(join => sub { shift; $self->on_join(@_)});63 $self-> conn->add_handler(part => sub { shift; $self->on_part(@_)});64 $self-> conn->add_handler(disconnect => sub { shift; $self->on_disconnect(@_)});65 $self-> conn->add_handler(nicknameinuse => sub { shift; $self->on_nickinuse(@_)});66 $self-> conn->add_handler(cping => sub { shift; $self->on_ping(@_)});44 $self->add_handler(motdstart => sub { goto &on_motdstart }); 45 $self->add_handler(motd => sub { goto &on_motd }); 46 $self->add_handler(endofmotd => sub { goto &on_endofmotd }); 47 $self->add_handler(join => sub { goto &on_join }); 48 $self->add_handler(part => sub { goto &on_part }); 49 $self->add_handler(disconnect => sub { goto &on_disconnect }); 50 $self->add_handler(nicknameinuse => sub { goto &on_nickinuse }); 51 $self->add_handler(cping => sub { goto &on_ping }); 67 52 68 53 return $self; … … 112 97 sub on_ping { 113 98 my ($self, $evt) = @_; 114 $self->c onn->ctcp_reply($evt->nick, join (' ', ($evt->args)));99 $self->ctcp_reply($evt->nick, join (' ', ($evt->args))); 115 100 } 116 101 … … 125 110 sub on_motdstart { 126 111 my ($self, $evt) = @_; 127 $self-> motd(join "\n", cdr $evt->args);112 $self->owl_motd(join "\n", cdr $evt->args); 128 113 } 129 114 130 115 sub on_motd { 131 116 my ($self, $evt) = @_; 132 $self-> motd(join "\n", $self->motd, cdr $evt->args);117 $self->owl_motd(join "\n", $self->owl_motd, cdr $evt->args); 133 118 } 134 119 135 120 sub on_endofmotd { 136 121 my ($self, $evt) = @_; 137 $self-> motd(join "\n", $self->motd, cdr $evt->args);138 if(!$self-> connected) {122 $self->owl_motd(join "\n", $self->owl_motd, cdr $evt->args); 123 if(!$self->owl_connected) { 139 124 BarnOwl::admin_message("IRC", "Connected to " . 140 125 $self->server . " (" . $self->alias . ")"); 141 $self-> connected(1);126 $self->owl_connected(1); 142 127 143 128 } 144 129 BarnOwl::admin_message("IRC", 145 130 BarnOwl::Style::boldify('MOTD for ' . $self->alias) . "\n" 146 . strip_irc_formatting($self-> motd));131 . strip_irc_formatting($self->owl_motd)); 147 132 } 148 133 … … 178 163 "[" . $self->alias . "] " . 179 164 [$evt->args]->[1] . ": Nick already in use"); 180 unless($self-> connected) {181 $self-> conn->disconnect;165 unless($self->owl_connected) { 166 $self->disconnect; 182 167 } 183 168 }
Note: See TracChangeset
for help on using the changeset viewer.