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 | } |
… | |
… | |
31 | (load_topics "DM Commands" => "dmcommand_help"), |
38 | (load_topics "DM Commands" => "dmcommand_help"), |
32 | (load_topics "Emotes" => "emote_help"), |
39 | (load_topics "Emotes" => "emote_help"), |
33 | (load_topics "Commands" => "command_help"), |
40 | (load_topics "Commands" => "command_help"), |
34 | (load_topics "Generic Help Topics" => "generic_help"), |
41 | (load_topics "Generic Help Topics" => "generic_help"), |
35 | }; |
42 | }; |
|
|
43 | |
|
|
44 | () |
36 | } |
45 | } |
37 | |
46 | |
38 | cf::sync_job { |
47 | cf::sync_job { |
39 | my $guard = cf::lock_acquire "ext::help::loading"; |
48 | my $guard = cf::lock_acquire "ext::help::loading"; |
40 | cf::async_ext { |
49 | cf::async_ext { |
|
|
50 | $Coro::current->{desc} = "help loader"; |
41 | reload; |
51 | reload; |
42 | undef $guard; |
52 | undef $guard; |
43 | }; |
53 | }; |
44 | }; |
54 | }; |
45 | |
55 | |
|
|
56 | # for lack of a better place: "media tags" |
|
|
57 | # b bold |
|
|
58 | # i italic |
|
|
59 | # ul underlined |
|
|
60 | # fixed font |
|
|
61 | # arcane font |
|
|
62 | # hand font |
|
|
63 | # strange font |
|
|
64 | # print font (default) |
|
|
65 | # color=xxx |
|
|
66 | |
46 | cf::register_command help => sub { |
67 | cf::register_command help => sub { |
47 | my ($pl, $topic) = @_; |
68 | my ($pl, $topic) = @_; |
48 | |
69 | |
49 | if (cf::lock_active "ext::help::loading") { |
70 | if (cf::lock_active "ext::help::loading") { |
50 | $pl->reply (undef, "help files are being loaded currently, try again in a few seconds."); |
71 | $pl->send_msg ($HELP_CHANNEL => "help files are being loaded currently, try again in a few seconds.", cf::NDI_REPLY | cf::NDI_CLEAR); |
51 | return; |
72 | return; |
52 | } |
73 | } |
53 | |
74 | |
54 | $topic = $1 if $topic =~ /(\S+)/; |
75 | $topic = $1 if $topic =~ /(\S+)/; |
55 | |
76 | |
… | |
… | |
61 | push @{$topics{$v->[0]}}, $k; |
82 | push @{$topics{$v->[0]}}, $k; |
62 | } |
83 | } |
63 | |
84 | |
64 | my $res; |
85 | my $res; |
65 | while (my ($k, $v) = each %topics) { |
86 | while (my ($k, $v) = each %topics) { |
66 | $res .= "[b]$k:[/b]\n" . (join " ", sort @$v) . "\n\n"; |
87 | $res .= "B<$k:>\n" . (join " ", sort @$v) . "\n\n"; |
67 | } |
88 | } |
68 | |
89 | |
69 | $pl->reply (undef, $res); |
90 | $pl->send_msg ($HELP_CHANNEL => $res, cf::NDI_REPLY | cf::NDI_CLEAR); |
70 | |
91 | |
71 | } elsif (my $topic = $TOPIC->{$topic}) { |
92 | } elsif (my $item = $TOPIC->{$topic}) { |
72 | my ($type, @pars) = @$topic; |
93 | my ($type, @pars) = @$item; |
73 | $pl->reply (undef, cf::pod::as_text \@pars); |
94 | $pl->send_msg ($HELP_CHANNEL => (cf::pod::as_cfpod \@pars), cf::NDI_REPLY | cf::NDI_CLEAR); |
74 | |
95 | |
75 | } else { |
96 | } else { |
76 | $pl->reply (undef, "'$topic' no such help topic, try just 'help' to get a list of topics."); |
97 | $pl->send_msg ($HELP_CHANNEL => "'$topic' no such help topic, try just 'help' to get a list of topics.", cf::NDI_REPLY); |
77 | } |
98 | } |
78 | }; |
99 | }; |
79 | |
100 | |