| 1 |
pippijn |
1.1 |
#! perl |
| 2 |
|
|
|
| 3 |
root |
1.2 |
our $TOPIC; |
| 4 |
|
|
|
| 5 |
root |
1.12 |
our $HELP_CHANNEL = { |
| 6 |
|
|
id => "help", |
| 7 |
|
|
title => "Help", |
| 8 |
|
|
reply => "help ", |
| 9 |
|
|
tooltip => "Online Help", |
| 10 |
|
|
}; |
| 11 |
|
|
|
| 12 |
root |
1.3 |
sub load_topics($$) { |
| 13 |
|
|
my ($type, $path) = @_; |
| 14 |
root |
1.2 |
|
| 15 |
|
|
my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" |
| 16 |
|
|
or die "unable to load $path"; |
| 17 |
|
|
|
| 18 |
|
|
my @topics; |
| 19 |
|
|
my $level = 1e9; |
| 20 |
|
|
|
| 21 |
|
|
for my $par (@$paragraphs) { |
| 22 |
root |
1.11 |
cf::cede_to_tick; |
| 23 |
root |
1.2 |
if ($par->{type} eq "head2") { |
| 24 |
|
|
if ($par->{markup} =~ /^(\S+)/) { |
| 25 |
root |
1.3 |
push @topics, $1 => [$type => $par]; |
| 26 |
root |
1.2 |
$level = $par->{level}; |
| 27 |
|
|
} |
| 28 |
|
|
} elsif ($par->{level} > $level) { |
| 29 |
|
|
push @{ $topics[-1] }, $par; |
| 30 |
|
|
} |
| 31 |
|
|
} |
| 32 |
|
|
|
| 33 |
|
|
@topics |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
|
sub reload() { |
| 37 |
root |
1.15 |
my $guard = cf::lock_acquire "ext::help::loading"; |
| 38 |
|
|
|
| 39 |
|
|
local $Coro::current->{desc} = "help loader"; |
| 40 |
|
|
|
| 41 |
root |
1.2 |
$TOPIC = { |
| 42 |
root |
1.3 |
(load_topics "DM Commands" => "dmcommand_help"), |
| 43 |
|
|
(load_topics "Emotes" => "emote_help"), |
| 44 |
|
|
(load_topics "Commands" => "command_help"), |
| 45 |
|
|
(load_topics "Generic Help Topics" => "generic_help"), |
| 46 |
root |
1.2 |
}; |
| 47 |
root |
1.13 |
|
| 48 |
|
|
() |
| 49 |
root |
1.2 |
} |
| 50 |
|
|
|
| 51 |
root |
1.15 |
cf::post_init { |
| 52 |
root |
1.17 |
cf::async_ext { reload }; |
| 53 |
root |
1.2 |
}; |
| 54 |
|
|
|
| 55 |
root |
1.3 |
cf::register_command help => sub { |
| 56 |
root |
1.2 |
my ($pl, $topic) = @_; |
| 57 |
|
|
|
| 58 |
|
|
if (cf::lock_active "ext::help::loading") { |
| 59 |
root |
1.12 |
$pl->send_msg ($HELP_CHANNEL => "help files are being loaded currently, try again in a few seconds.", cf::NDI_REPLY | cf::NDI_CLEAR); |
| 60 |
root |
1.2 |
return; |
| 61 |
|
|
} |
| 62 |
root |
1.3 |
|
| 63 |
|
|
$topic = $1 if $topic =~ /(\S+)/; |
| 64 |
|
|
|
| 65 |
|
|
if (!length $topic) { |
| 66 |
|
|
# sort.. |
| 67 |
|
|
|
| 68 |
|
|
my %topics; |
| 69 |
|
|
while (my ($k, $v) = each %$TOPIC) { |
| 70 |
|
|
push @{$topics{$v->[0]}}, $k; |
| 71 |
|
|
} |
| 72 |
|
|
|
| 73 |
|
|
my $res; |
| 74 |
|
|
while (my ($k, $v) = each %topics) { |
| 75 |
root |
1.14 |
$res .= "T<$k:>\n\n" . (join " ", sort @$v) . "\n\n"; |
| 76 |
root |
1.3 |
} |
| 77 |
|
|
|
| 78 |
root |
1.12 |
$pl->send_msg ($HELP_CHANNEL => $res, cf::NDI_REPLY | cf::NDI_CLEAR); |
| 79 |
root |
1.3 |
|
| 80 |
root |
1.7 |
} elsif (my $item = $TOPIC->{$topic}) { |
| 81 |
|
|
my ($type, @pars) = @$item; |
| 82 |
root |
1.12 |
$pl->send_msg ($HELP_CHANNEL => (cf::pod::as_cfpod \@pars), cf::NDI_REPLY | cf::NDI_CLEAR); |
| 83 |
root |
1.3 |
|
| 84 |
|
|
} else { |
| 85 |
root |
1.12 |
$pl->send_msg ($HELP_CHANNEL => "'$topic' no such help topic, try just 'help' to get a list of topics.", cf::NDI_REPLY); |
| 86 |
root |
1.3 |
} |
| 87 |
root |
1.2 |
}; |
| 88 |
root |
1.3 |
|