sub handle_xmpp_message {
my ($self, $msg) = @_;
- $self->irc_tower->send_irc_message({
- to => $self->irc_channel,
- text => $msg->body
- });
+ if (my ($cmd, $args) = $msg->body =~ m{^/(\w+)\s*(.*)$}) {
+ if (my $meth = $self->can("_handle_command_${cmd}")) {
+ $self->$meth($msg, $args);
+ } else {
+ $self->_send_jabber("Unknown command ${cmd}");
+ }
+ } else {
+ $self->irc_tower->send_irc_message({
+ to => $self->irc_channel,
+ text => $msg->body
+ });
+ }
+}
+
+sub _handle_command_stop {
+ my ($self) = @_;
+ $self->irc_tower->stop_chain($self);
+ $self->jabber_tower->chain_set->remove($self);
+ $self->_send_jabber('Stopped.');
}
sub handle_irc_message {
my ($self, $message, $hints) = @_;
+ $self->_send_jabber(join(': ', $hints->{prefix_name}, $hints->{text}));
+}
+
+sub _send_jabber {
+ my ($self, $text) = @_;
$self->jabber_tower->send_xmpp_message({
to => $self->jabber_user,
- body => join(': ', $hints->{prefix_name}, $hints->{text})
+ body => $text,
});
}
});
}
+sub stop_chain {
+ my ($self, $chain) = @_;
+ $self->irc_client->send_message('PART', undef, $chain->irc_channel);
+ delete $self->chains->{$chain->irc_channel};
+ $self->remove_child($chain);
+}
+
sub send_irc_message {
my ($self, $args) = @_;
$self->irc_client->send_message('PRIVMSG', undef, @{$args}{qw(to text)});