1 | #! perl |
1 | #! perl # mandatory depends=doclet |
2 | |
2 | |
3 | our $TOPIC; |
3 | our $TOPIC; |
|
|
4 | our %DOCLET; |
|
|
5 | |
|
|
6 | our $HELP_CHANNEL = { |
|
|
7 | id => "help", |
|
|
8 | title => "Help", |
|
|
9 | reply => "help ", |
|
|
10 | tooltip => "Online Help", |
|
|
11 | }; |
|
|
12 | |
|
|
13 | # considerable duplication between load_doclets and load_topics |
|
|
14 | sub load_doclets { |
|
|
15 | %DOCLET = (); |
|
|
16 | |
|
|
17 | my %command_list; |
|
|
18 | |
|
|
19 | for ( |
|
|
20 | [standard => "command_help"], |
|
|
21 | [emote => "emote_help"], |
|
|
22 | [dm => "dmcommand_help"], |
|
|
23 | ) { |
|
|
24 | my ($type, $path) = @$_; |
|
|
25 | |
|
|
26 | my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" |
|
|
27 | or die "unable to load $path"; |
|
|
28 | |
|
|
29 | my $level = 1e9; |
|
|
30 | my $rpar; |
|
|
31 | |
|
|
32 | for my $par (@$paragraphs) { |
|
|
33 | if ($par->{type} eq "head2") { |
|
|
34 | # this code taken almost verbatim from DC/Protocol.pm |
|
|
35 | |
|
|
36 | if ($par->{markup} =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x) { |
|
|
37 | my $cmd = $1; |
|
|
38 | my @args = split /\|/, $2; |
|
|
39 | @args = (".*") unless @args; |
|
|
40 | |
|
|
41 | $_ = $_ eq ".*" ? "" : " $_" |
|
|
42 | for @args; |
|
|
43 | |
|
|
44 | my @variants = map "$cmd$_", sort { (length $a) <=> (length $b) } @args; |
|
|
45 | |
|
|
46 | $rpar = \($DOCLET{$cmd} = &cf::pod::as_cfpod ([$par])); |
|
|
47 | |
|
|
48 | push @{ $command_list{$type} }, @variants; |
|
|
49 | $level = $par->{level}; |
|
|
50 | } else { |
|
|
51 | cf::error "$par->{markup}: unparsable command heading"; |
|
|
52 | } |
|
|
53 | } elsif ($par->{level} > $level) { |
|
|
54 | $$rpar .= &cf::pod::as_cfpod ([$par]); |
|
|
55 | } |
|
|
56 | |
|
|
57 | cf::cede_to_tick; |
|
|
58 | } |
|
|
59 | } |
|
|
60 | |
|
|
61 | cf::cede_to_tick; |
|
|
62 | |
|
|
63 | while (my ($k, $v) = each %command_list) { |
|
|
64 | cf::client::set_command_face $k, $v |
|
|
65 | } |
|
|
66 | } |
|
|
67 | |
|
|
68 | our $DOCLET_HANDLER = ext::doclet::register command => sub { |
|
|
69 | my ($pl, $category, $command) = @_; |
|
|
70 | |
|
|
71 | if ($command =~ /^(cast|invoke)\s+(.*)$/) { # not used currently |
|
|
72 | my ($cmd, $arg) = ($1, $2); |
|
|
73 | (ext::doclet::doclet $pl, command => $cmd) |
|
|
74 | . (ext::doclet::doclet $pl, spell => $arg) |
|
|
75 | } elsif ($command =~ /^(ready_skill|use_skill)\s+(.*)$/) { |
|
|
76 | my ($cmd, $arg) = ($1, $2); |
|
|
77 | (ext::doclet::doclet $pl, command => $cmd) |
|
|
78 | . (ext::doclet::doclet $pl, skill => $arg) |
|
|
79 | } else { |
|
|
80 | my $guard = cf::lock_acquire "ext::help::loading"; |
|
|
81 | |
|
|
82 | $DOCLET{$command} |
|
|
83 | || "B<No documentation available for '$category/$command'>" |
|
|
84 | } |
|
|
85 | }; |
4 | |
86 | |
5 | sub load_topics($$) { |
87 | sub load_topics($$) { |
6 | my ($type, $path) = @_; |
88 | my ($type, $path) = @_; |
7 | |
89 | |
8 | my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" |
90 | my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" |
… | |
… | |
25 | |
107 | |
26 | @topics |
108 | @topics |
27 | } |
109 | } |
28 | |
110 | |
29 | sub reload() { |
111 | sub reload() { |
|
|
112 | my $guard1 = cf::lock_acquire "ext::help::loading"; |
|
|
113 | my $guard2 = cf::lock_acquire "ext::resource"; |
|
|
114 | |
|
|
115 | local $Coro::current->{desc} = "help loader"; |
|
|
116 | |
30 | $TOPIC = { |
117 | $TOPIC = { |
31 | (load_topics "DM Commands" => "dmcommand_help"), |
118 | (load_topics "DM Commands" => "dmcommand_help"), |
32 | (load_topics "Emotes" => "emote_help"), |
119 | (load_topics "Emotes" => "emote_help"), |
33 | (load_topics "Commands" => "command_help"), |
120 | (load_topics "Commands" => "command_help"), |
34 | (load_topics "Generic Help Topics" => "generic_help"), |
121 | (load_topics "Generic Help Topics" => "generic_help"), |
35 | }; |
122 | }; |
|
|
123 | |
|
|
124 | load_doclets; |
|
|
125 | |
|
|
126 | () |
36 | } |
127 | } |
37 | |
128 | |
38 | cf::sync_job { |
129 | cf::post_init { |
39 | my $guard = cf::lock_acquire "ext::help::loading"; |
|
|
40 | cf::async_ext { |
130 | cf::async_ext { reload }; |
41 | $Coro::current->{desc} = "help loader"; |
131 | Coro::cede; # make sure reload acquires the lock(s) |
42 | reload; |
|
|
43 | undef $guard; |
|
|
44 | }; |
|
|
45 | }; |
132 | }; |
46 | |
|
|
47 | # for lack of a better place: "media tags" |
|
|
48 | # b bold |
|
|
49 | # i italic |
|
|
50 | # ul underlined |
|
|
51 | # fixed font |
|
|
52 | # arcane font |
|
|
53 | # hand font |
|
|
54 | # strange font |
|
|
55 | # print font (default) |
|
|
56 | # color=xxx |
|
|
57 | |
133 | |
58 | cf::register_command help => sub { |
134 | cf::register_command help => sub { |
59 | my ($pl, $topic) = @_; |
135 | my ($pl, $topic) = @_; |
60 | |
136 | |
61 | if (cf::lock_active "ext::help::loading") { |
137 | if (cf::lock_active "ext::help::loading") { |
62 | $pl->reply (undef, "help files are being loaded currently, try again in a few seconds."); |
138 | $pl->send_msg ($HELP_CHANNEL => "help files are being loaded currently, try again in a few seconds.", cf::NDI_REPLY | cf::NDI_CLEAR); |
63 | return; |
139 | return; |
64 | } |
140 | } |
65 | |
141 | |
66 | $topic = $1 if $topic =~ /(\S+)/; |
142 | $topic = $1 if $topic =~ /(\S+)/; |
67 | |
143 | |
… | |
… | |
73 | push @{$topics{$v->[0]}}, $k; |
149 | push @{$topics{$v->[0]}}, $k; |
74 | } |
150 | } |
75 | |
151 | |
76 | my $res; |
152 | my $res; |
77 | while (my ($k, $v) = each %topics) { |
153 | while (my ($k, $v) = each %topics) { |
78 | $res .= "B<$k:>\n" . (join " ", sort @$v) . "\n\n"; |
154 | $res .= "T<$k:>\n\n" . (join " ", sort @$v) . "\n\n"; |
79 | } |
155 | } |
80 | |
156 | |
81 | $pl->reply (undef, $res); |
157 | $pl->send_msg ($HELP_CHANNEL => $res, cf::NDI_REPLY | cf::NDI_CLEAR); |
82 | |
158 | |
83 | } elsif (my $item = $TOPIC->{$topic}) { |
159 | } elsif (my $item = $TOPIC->{$topic}) { |
84 | my ($type, @pars) = @$item; |
160 | my ($type, @pars) = @$item; |
85 | $pl->reply (undef, cf::pod::as_cfpod \@pars); |
161 | $pl->send_msg ($HELP_CHANNEL => (cf::pod::as_cfpod \@pars), cf::NDI_REPLY | cf::NDI_CLEAR); |
86 | |
162 | |
87 | } else { |
163 | } else { |
88 | $pl->reply (undef, "'$topic' no such help topic, try just 'help' to get a list of topics."); |
164 | $pl->send_msg ($HELP_CHANNEL => "'$topic' no such help topic, try just 'help' to get a list of topics.", cf::NDI_REPLY); |
89 | } |
165 | } |
90 | }; |
166 | }; |
91 | |
167 | |