1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | our $TOPIC; |
3 | our $TOPIC; |
4 | |
4 | |
5 | sub load_topics($) { |
5 | sub load_topics($$) { |
6 | my ($path) = @_; |
6 | my ($type, $path) = @_; |
7 | |
7 | |
8 | my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" |
8 | my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" |
9 | or die "unable to load $path"; |
9 | or die "unable to load $path"; |
10 | |
10 | |
11 | my @topics; |
11 | my @topics; |
… | |
… | |
13 | |
13 | |
14 | for my $par (@$paragraphs) { |
14 | for my $par (@$paragraphs) { |
15 | Coro::cede; |
15 | Coro::cede; |
16 | if ($par->{type} eq "head2") { |
16 | if ($par->{type} eq "head2") { |
17 | if ($par->{markup} =~ /^(\S+)/) { |
17 | if ($par->{markup} =~ /^(\S+)/) { |
18 | push @topics, $1 => [$par]; |
18 | push @topics, $1 => [$type => $par]; |
19 | $level = $par->{level}; |
19 | $level = $par->{level}; |
20 | } |
20 | } |
21 | } elsif ($par->{level} > $level) { |
21 | } elsif ($par->{level} > $level) { |
22 | push @{ $topics[-1] }, $par; |
22 | push @{ $topics[-1] }, $par; |
23 | } |
23 | } |
… | |
… | |
26 | @topics |
26 | @topics |
27 | } |
27 | } |
28 | |
28 | |
29 | sub reload() { |
29 | sub reload() { |
30 | $TOPIC = { |
30 | $TOPIC = { |
31 | load_topics "dmcommand_help", |
31 | (load_topics "DM Commands" => "dmcommand_help"), |
32 | load_topics "emote_help", |
32 | (load_topics "Emotes" => "emote_help"), |
33 | load_topics "command_help", |
33 | (load_topics "Commands" => "command_help"), |
34 | load_topics "generic_help", |
34 | (load_topics "Generic Help Topics" => "generic_help"), |
35 | }; |
35 | }; |
36 | } |
36 | } |
37 | |
37 | |
38 | cf::sync_job { |
38 | cf::sync_job { |
39 | my $guard = cf::lock_acquire "ext::help::loading"; |
39 | my $guard = cf::lock_acquire "ext::help::loading"; |
… | |
… | |
41 | reload; |
41 | reload; |
42 | undef $guard; |
42 | undef $guard; |
43 | }; |
43 | }; |
44 | }; |
44 | }; |
45 | |
45 | |
46 | cf::register_command xhelp => sub { |
46 | cf::register_command help => sub { |
47 | my ($pl, $topic) = @_; |
47 | my ($pl, $topic) = @_; |
48 | |
48 | |
49 | if (cf::lock_active "ext::help::loading") { |
49 | if (cf::lock_active "ext::help::loading") { |
50 | $pl->reply (undef, "help files are being loaded currently, try again in a few seconds"); |
50 | $pl->reply (undef, "help files are being loaded currently, try again in a few seconds."); |
51 | return; |
51 | return; |
52 | } |
52 | } |
|
|
53 | |
|
|
54 | $topic = $1 if $topic =~ /(\S+)/; |
|
|
55 | |
|
|
56 | if (!length $topic) { |
|
|
57 | # sort.. |
|
|
58 | |
|
|
59 | my %topics; |
|
|
60 | while (my ($k, $v) = each %$TOPIC) { |
|
|
61 | push @{$topics{$v->[0]}}, $k; |
|
|
62 | } |
|
|
63 | |
|
|
64 | my $res; |
|
|
65 | while (my ($k, $v) = each %topics) { |
|
|
66 | $res .= "[b]$k:[/b]\n" . (join " ", @$v) . "\n\n"; |
|
|
67 | } |
|
|
68 | |
|
|
69 | $pl->reply (undef, $res); |
|
|
70 | |
|
|
71 | } elsif (my $topic = $TOPIC->{$topic}) { |
|
|
72 | my ($type, @pars) = @$topic; |
|
|
73 | $pl->reply (undef, cf::pod::as_text \@pars); |
|
|
74 | |
|
|
75 | } else { |
|
|
76 | $pl->reply (undef, "'$topic' no such help topic, try just 'help' to get a list of topics."); |
|
|
77 | } |
53 | }; |
78 | }; |
|
|
79 | |