Changeset 369479d for perl/modules/IRC/lib/BarnOwl/Module
- Timestamp:
- Jan 9, 2008, 2:18:31 PM (16 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 16c6cca
- Parents:
- 428834d (diff), 6286f26 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- perl/modules/IRC/lib/BarnOwl/Module
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
rb38b0b2 r6286f26 6 6 =head1 NAME 7 7 8 BarnOwl::Module:: Jabber8 BarnOwl::Module::IRC 9 9 10 10 =head1 DESCRIPTION 11 11 12 This module implements Jabbersupport for barnowl.12 This module implements IRC support for barnowl. 13 13 14 14 =cut … … 17 17 use BarnOwl::Hooks; 18 18 use BarnOwl::Message::IRC; 19 use BarnOwl::Module::IRC::Connection ;19 use BarnOwl::Module::IRC::Connection qw(is_private); 20 20 21 21 use Net::IRC; 22 22 use Getopt::Long; 23 23 24 our $VERSION = 0.0 1;24 our $VERSION = 0.02; 25 25 26 26 our $irc; … … 30 30 31 31 sub startup { 32 BarnOwl::new_variable_string(ircnick => {default => $ENV{USER}}); 33 BarnOwl::new_variable_string(ircuser => {default => $ENV{USER}}); 34 BarnOwl::new_variable_string(ircname => {default => ""}); 32 BarnOwl::new_variable_string('irc:nick', {default => $ENV{USER}}); 33 BarnOwl::new_variable_string('irc:user', {default => $ENV{USER}}); 34 BarnOwl::new_variable_string('irc:name', {default => ""}); 35 BarnOwl::new_variable_bool('irc:spew', {default => 0}); 35 36 register_commands(); 36 37 register_handlers(); … … 40 41 sub shutdown { 41 42 for my $conn (values %ircnets) { 42 $conn->disconnect ;43 $conn->disconnect(); 43 44 } 44 45 } … … 63 64 BarnOwl::new_command('irc-disconnect' => \&cmd_disconnect); 64 65 BarnOwl::new_command('irc-msg' => \&cmd_msg); 66 BarnOwl::new_command('irc-join' => \&cmd_join); 67 BarnOwl::new_command('irc-nick' => \&cmd_nick); 65 68 } 66 69 … … 76 79 my $cmd = shift; 77 80 78 my $nick = BarnOwl::getvar('irc nick');79 my $username = BarnOwl::getvar('irc user');80 my $ircname = BarnOwl::getvar('irc name');81 my $nick = BarnOwl::getvar('irc:nick'); 82 my $username = BarnOwl::getvar('irc:user'); 83 my $ircname = BarnOwl::getvar('irc:name'); 81 84 my $host; 82 85 my $port; … … 90 93 "alias=s" => \$alias, 91 94 "ssl" => \$ssl, 92 "password=s" => \$password); 95 "password=s" => \$password, 96 "port=i" => \$port, 97 ); 93 98 $host = shift @ARGV or die("Usage: $cmd HOST\n"); 94 99 if(!$alias) { … … 126 131 my $conn = get_connection(\@_); 127 132 my $to = shift or die("Usage: $cmd NICK\n"); 133 # handle multiple recipients? 128 134 if(@_) { 129 135 process_msg($conn, $to, join(" ", @_)); … … 148 154 body => $body, 149 155 sender => $conn->nick, 150 isprivate => 'true', 156 is_private($to) ? 157 (isprivate => 'true') : (channel => $to), 151 158 replycmd => "irc-msg $to", 152 replysendercmd => "irc-msg " . $conn->nick159 replysendercmd => "irc-msg $to" 153 160 ); 154 161 BarnOwl::queue_message($msg); 155 162 } 156 163 164 sub cmd_join { 165 my $cmd = shift; 166 my $conn = get_connection(\@_); 167 my $chan = shift or die("Usage: $cmd channel\n"); 168 $conn->join($chan); 169 } 170 171 sub cmd_nick { 172 my $cmd = shift; 173 my $conn = get_connection(\@_); 174 my $nick = shift or die("Usage: $cmd <new nick>"); 175 $conn->nick($nick); 176 } 157 177 158 178 ################################################################################ … … 177 197 178 198 sub get_connection_by_alias { 179 die("No such ircnet: $alias\n") unless exists $ircnets{$key}; 199 my $key = shift; 200 die("No such ircnet: $key\n") unless exists $ircnets{$key}; 180 201 return $ircnets{$key}; 181 202 } -
perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
rb38b0b2 r0e52069 15 15 =cut 16 16 17 use base qw(Net::IRC::Connection Class::Accessor );17 use base qw(Net::IRC::Connection Class::Accessor Exporter); 18 18 __PACKAGE__->mk_accessors(qw(alias channels)); 19 our @EXPORT_OK = qw(&is_private); 19 20 20 21 use BarnOwl; … … 30 31 bless($self, $class); 31 32 32 $self->add_global_handler(endofmotd => sub { goto &on_connect }); 33 $self->add_global_handler(msg => sub { goto &on_msg }); 34 $self->add_global_handler(notice => sub { goto &on_msg }); 33 $self->add_global_handler(376 => sub { goto &on_connect }); 34 $self->add_global_handler(['msg', 'notice', 'public', 'caction'], 35 sub { goto &on_msg }); 36 $self->add_global_handler(cping => sub { goto &on_ping }); 35 37 $self->add_default_handler(sub { goto &on_event; }); 36 38 … … 49 51 sub on_msg { 50 52 my ($self, $evt) = @_; 51 my $replycmd = "irc-msg " . $evt->nick; 53 my ($recipient) = $evt->to; 54 my $body = strip_irc_formatting([$evt->args]->[0]); 55 $body = BarnOwl::Style::boldify($evt->nick.' '.$body) if $evt->type eq 'caction'; 52 56 my $msg = BarnOwl::Message->new( 53 57 type => 'IRC', … … 55 59 server => $self->server, 56 60 network => $self->alias, 57 recipient => $ self->nick,58 body => strip_irc_formatting([$evt->args]->[0]),61 recipient => $recipient, 62 body => $body, 59 63 sender => $evt->nick, 60 64 hostname => $evt->host, 61 65 from => $evt->from, 62 notice => $evt->type eq 'notice' ? 'true' : '', 63 isprivate => 'true', 64 replycmd => $replycmd, 65 replysendercmd => $replycmd 66 $evt->type eq 'notice' ? 67 (notice => 'true') : (), 68 is_private($recipient) ? 69 (isprivate => 'true') : (channel => $recipient), 70 replycmd => 'irc-msg ' . 71 (is_private($recipient) ? $evt->nick : $recipient), 72 replysendercmd => 'irc-msg ' . $evt->nick, 66 73 ); 67 74 BarnOwl::queue_message($msg); 75 } 76 77 sub on_ping { 78 my ($self, $evt) = @_; 79 $self->ctcp_reply($evt->nick, join (' ', ($evt->args))); 80 } 81 82 sub on_event { 83 my ($self, $evt) = @_; 84 BarnOwl::admin_message("IRC", 85 "Unhandled IRC event of type " . $evt->type . ":\n" 86 . strip_irc_formatting(join("\n", $evt->args))) 87 if BarnOwl::getvar('irc:spew') eq 'on'; 68 88 } 69 89 … … 83 103 } 84 104 105 # Determines if the given message recipient is a username, as opposed to 106 # a channel that starts with # or &. 107 sub is_private { 108 return shift !~ /^[\#\&]/; 109 } 85 110 86 111 1;
Note: See TracChangeset
for help on using the changeset viewer.