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