man.pm 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. use POE;
  2. {
  3. on_load => sub {
  4. $BotIrc::heap{man_cache} = undef;
  5. },
  6. before_unload => sub {
  7. delete $BotIrc::heap{man_cache};
  8. },
  9. irc_commands => {
  10. man_update => sub {
  11. my ($source, $targets, $args, $auth) = @_;
  12. BotIrc::check_ctx(authed => 1) or return;
  13. umask(0022);
  14. system("cd $BotIrc::config->{man_repodir} && git pull -q &");
  15. BotIrc::send_noise("Manpage index updating. Please allow a few seconds before using again.");
  16. $BotIrc::heap{man_cache} = undef;
  17. }
  18. },
  19. irc_on_anymsg => sub {
  20. return 0 if ($_[ARG2] !~ /\bman\s+([a-z-]+)/);
  21. BotIrc::check_ctx(wisdom_auto_redirect => 1) or return;
  22. if (!defined $BotIrc::heap{man_cache}) {
  23. my @mans = BotIrc::read_dir($BotIrc::config->{man_repodir}) or do {
  24. error("Manpage cache broken: $!");
  25. BotIrc::send_noise("Manpage cache is broken. The bot owner has been notified.");
  26. return 1;
  27. };
  28. @mans = grep { $_ =~ /\.html$/ && $_ ne 'index.html' } @mans;
  29. for (@mans) {
  30. s/\.html$//;
  31. $BotIrc::heap{man_cache}{$_} = undef;
  32. }
  33. }
  34. while ($_[ARG2] =~ /\bman\s+(git\s+)?([a-z-]+)?/g) {
  35. my $page = $2;
  36. if (defined $1) {
  37. $altpage = "git-$2";
  38. if (exists $BotIrc::heap{man_cache}{$altpage}) {
  39. $page = $altpage;
  40. } else {
  41. $page = 'git';
  42. }
  43. }
  44. next if (!exists $BotIrc::heap{man_cache}{$page});
  45. BotIrc::send_wisdom("the $page manpage is available at $BotIrc::config->{man_baseurl}/$page.html");
  46. }
  47. return 0;
  48. },
  49. };