1 | #! perl |
1 | #! perl # mandatory depends=doclet |
2 | |
2 | |
3 | our $TOPIC; |
3 | our $TOPIC; |
|
|
4 | our %DOCLET; |
4 | |
5 | |
5 | our $HELP_CHANNEL = { |
6 | our $HELP_CHANNEL = { |
6 | id => "help", |
7 | id => "help", |
7 | title => "Help", |
8 | title => "Help", |
8 | reply => "help ", |
9 | reply => "help ", |
9 | tooltip => "Online Help", |
10 | tooltip => "Online Help", |
|
|
11 | }; |
|
|
12 | |
|
|
13 | # these commands should be preferred by the client completer |
|
|
14 | # we put them first in their own face. |
|
|
15 | our @PREFERRED = qw(chat say shout tell); |
|
|
16 | |
|
|
17 | # considerable duplication between load_doclets and load_topics |
|
|
18 | sub load_doclets { |
|
|
19 | %DOCLET = (); |
|
|
20 | |
|
|
21 | my %command_list; |
|
|
22 | my %preferred = map { $_ => undef } @PREFERRED; |
|
|
23 | |
|
|
24 | for ( |
|
|
25 | [standard => "command_help"], |
|
|
26 | [emote => "emote_help"], |
|
|
27 | [dm => "dmcommand_help"], |
|
|
28 | ) { |
|
|
29 | my ($type, $path) = @$_; |
|
|
30 | |
|
|
31 | my $paragraphs = cf::pod::load_pod "$PODDIR/$path.pod" |
|
|
32 | or die "unable to load $path"; |
|
|
33 | |
|
|
34 | my $level = 1e9; |
|
|
35 | my $rpar; |
|
|
36 | |
|
|
37 | for my $par (@$paragraphs) { |
|
|
38 | if ($par->{type} eq "head2") { |
|
|
39 | # this code taken almost verbatim from DC/Protocol.pm |
|
|
40 | |
|
|
41 | if ($par->{markup} =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x) { |
|
|
42 | my $cmd = $1; |
|
|
43 | my @args = split /\|/, $2; |
|
|
44 | @args = (".*") unless @args; |
|
|
45 | |
|
|
46 | $_ = $_ eq ".*" ? "" : " $_" |
|
|
47 | for @args; |
|
|
48 | |
|
|
49 | my @variants = map "$cmd$_", sort { (length $a) <=> (length $b) } @args; |
|
|
50 | |
|
|
51 | $rpar = \($DOCLET{$cmd} = &cf::pod::as_cfpod ([$par])); |
|
|
52 | |
|
|
53 | push @{ $command_list{$type} }, @variants; |
|
|
54 | $level = $par->{level}; |
|
|
55 | } else { |
|
|
56 | cf::error "$par->{markup}: unparsable command heading"; |
|
|
57 | } |
|
|
58 | } elsif ($par->{level} > $level) { |
|
|
59 | $$rpar .= &cf::pod::as_cfpod ([$par]); |
|
|
60 | } |
|
|
61 | |
|
|
62 | cf::cede_to_tick; |
|
|
63 | } |
|
|
64 | } |
|
|
65 | |
|
|
66 | cf::cede_to_tick; |
|
|
67 | |
|
|
68 | @$_ = grep !exists $preferred{$_}, @$_ |
|
|
69 | for values %command_list; |
|
|
70 | |
|
|
71 | $command_list{preferred} = \@PREFERRED; |
|
|
72 | |
|
|
73 | while (my ($k, $v) = each %command_list) { |
|
|
74 | cf::cede_to_tick; |
|
|
75 | cf::client::set_command_face $k, $v; |
|
|
76 | } |
|
|
77 | } |
|
|
78 | |
|
|
79 | our $DOCLET_HANDLER = ext::doclet::register command => sub { |
|
|
80 | my ($pl, $category, $command) = @_; |
|
|
81 | |
|
|
82 | if ($command =~ /^(cast|invoke)\s+(.*)$/) { # not used currently |
|
|
83 | my ($cmd, $arg) = ($1, $2); |
|
|
84 | (ext::doclet::doclet $pl, command => $cmd) |
|
|
85 | . (ext::doclet::doclet $pl, spell => $arg) |
|
|
86 | } elsif ($command =~ /^(ready_skill|use_skill)\s+(.*)$/) { |
|
|
87 | my ($cmd, $arg) = ($1, $2); |
|
|
88 | (ext::doclet::doclet $pl, command => $cmd) |
|
|
89 | . (ext::doclet::doclet $pl, skill => $arg) |
|
|
90 | } else { |
|
|
91 | my $guard = cf::lock_acquire "ext::help::loading"; |
|
|
92 | |
|
|
93 | $DOCLET{$command} |
|
|
94 | || "B<No documentation available for '$category/$command'>" |
|
|
95 | } |
10 | }; |
96 | }; |
11 | |
97 | |
12 | sub load_topics($$) { |
98 | sub load_topics($$) { |
13 | my ($type, $path) = @_; |
99 | my ($type, $path) = @_; |
14 | |
100 | |
… | |
… | |
32 | |
118 | |
33 | @topics |
119 | @topics |
34 | } |
120 | } |
35 | |
121 | |
36 | sub reload() { |
122 | sub reload() { |
37 | my $guard = cf::lock_acquire "ext::help::loading"; |
123 | my $guard1 = cf::lock_acquire "ext::help::loading"; |
|
|
124 | my $guard2 = cf::lock_acquire "ext::resource"; |
38 | |
125 | |
39 | local $Coro::current->{desc} = "help loader"; |
126 | local $Coro::current->{desc} = "help loader"; |
40 | |
127 | |
41 | $TOPIC = { |
128 | $TOPIC = { |
42 | (load_topics "DM Commands" => "dmcommand_help"), |
129 | (load_topics "DM Commands" => "dmcommand_help"), |
43 | (load_topics "Emotes" => "emote_help"), |
130 | (load_topics "Emotes" => "emote_help"), |
44 | (load_topics "Commands" => "command_help"), |
131 | (load_topics "Commands" => "command_help"), |
45 | (load_topics "Generic Help Topics" => "generic_help"), |
132 | (load_topics "Generic Help Topics" => "generic_help"), |
46 | }; |
133 | }; |
|
|
134 | |
|
|
135 | load_doclets; |
47 | |
136 | |
48 | () |
137 | () |
49 | } |
138 | } |
50 | |
139 | |
51 | cf::post_init { |
140 | cf::post_init { |
52 | reload; |
141 | cf::async_ext { reload }; |
|
|
142 | Coro::cede; # make sure reload acquires the lock(s) |
53 | }; |
143 | }; |
54 | |
|
|
55 | # for lack of a better place: "media tags" |
|
|
56 | # b bold |
|
|
57 | # i italic |
|
|
58 | # ul underlined |
|
|
59 | # fixed font |
|
|
60 | # arcane font |
|
|
61 | # hand font |
|
|
62 | # strange font |
|
|
63 | # print font (default) |
|
|
64 | # color=xxx |
|
|
65 | |
144 | |
66 | cf::register_command help => sub { |
145 | cf::register_command help => sub { |
67 | my ($pl, $topic) = @_; |
146 | my ($pl, $topic) = @_; |
68 | |
147 | |
69 | if (cf::lock_active "ext::help::loading") { |
148 | if (cf::lock_active "ext::help::loading") { |