join.pm 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. use POE;
  2. {
  3. irc_commands => {
  4. join => sub {
  5. my ($source, $targets, $args, $account) = @_;
  6. BotIrc::check_ctx(priv => 'join') or return;
  7. chomp $args;
  8. my ($channel) = split(/\s+/, $args);
  9. if (!$channel) {
  10. # Auto-join
  11. my $chans = $BotIrc::irc->channels();
  12. my @new_chans = ();
  13. for (keys %{$BotIrc::config->{channel}}) {
  14. next if (exists $chans->{uc $_});
  15. $BotIrc::irc->yield(join => $_);
  16. push @new_chans, $_;
  17. }
  18. BotIrc::send_noise("Auto-joined configured channels: ". join(", ", @new_chans));
  19. return;
  20. }
  21. if ($channel !~ /^#\S+$/) {
  22. BotIrc::send_noise("I'm not particularly strict about channel names but you definitely didn't pass me a valid one there.");
  23. return;
  24. }
  25. if (!exists $BotIrc::config->{channel}{lc $channel}) {
  26. BotIrc::send_noise("You may not join me to channels that aren't configured. Sorry.");
  27. return;
  28. }
  29. if ($BotIrc::irc->is_channel_member($channel, $BotIrc::irc->nick_name())) {
  30. BotIrc::send_noise("Good morning, sleepyhead! I'm already on that channel.");
  31. return;
  32. }
  33. $BotIrc::irc->yield(join => $channel);
  34. BotIrc::send_noise("Okay.");
  35. },
  36. },
  37. };