}
-sub write_to_channel {
+# send_to_channel()
+#
+# send a message to a channel
+#
+# parameter:
+# - message
+# return:
+# none
+sub send_to_channel {
+ my $channel = shift;
+ my $msg = shift;
+ $msg =~ s/\n//g;
+ my $session = session_for_channel($channel);
+
+ if (defined($session)) {
+ my $irc = $main::sessions{$session}{'session'};
+ $irc->yield( privmsg => $channel, $msg );
+ }
}
# return:
# none
sub send_to_commandchannel {
+ my $msg = shift;
+ $msg =~ s/\n//g;
-# FIXME: check if channel is joined
+ my $commandchannel = config_get_key2('bot', 'commandchannel');
+ print_msg("commandchannel: $msg", DEBUG);
+ send_to_channel(config_get_key2('bot', 'commandchannel'), $msg)
+}
+
+
+# session_for_channel()
+#
+# find a session for a specific channel
+#
+# parameter:
+# - channel name
+# return:
+# - session number, or undef
+sub session_for_channel {
+ my $channel = shift;
-# http://search.cpan.org/dist/POE-Component-IRC/lib/POE/Component/IRC.pm#connected
+ foreach my $session (keys(%main::sessions)) {
+ if (grep {lc($_) eq lc($channel)} @{$main::sessions{$session}{'joined_channels'}}) {
+ # so far the first session is used:
+ # based on the current configuration method, each channel can only be assigned to one session
+ return $session;
+ }
+ }
+ return undef;
}