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" |
… | |
… | |
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 { |
|
|
41 | $Coro::current->{desc} = "help loader"; |
|
|
42 | reload; |
52 | reload; |
43 | undef $guard; |
|
|
44 | }; |
|
|
45 | }; |
53 | }; |
46 | |
54 | |
47 | # for lack of a better place: "media tags" |
55 | # for lack of a better place: "media tags" |
48 | # b bold |
56 | # b bold |
49 | # i italic |
57 | # i italic |
… | |
… | |
57 | |
65 | |
58 | cf::register_command help => sub { |
66 | cf::register_command help => sub { |
59 | my ($pl, $topic) = @_; |
67 | my ($pl, $topic) = @_; |
60 | |
68 | |
61 | if (cf::lock_active "ext::help::loading") { |
69 | if (cf::lock_active "ext::help::loading") { |
62 | $pl->reply (undef, "help files are being loaded currently, try again in a few seconds."); |
70 | $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; |
71 | return; |
64 | } |
72 | } |
65 | |
73 | |
66 | $topic = $1 if $topic =~ /(\S+)/; |
74 | $topic = $1 if $topic =~ /(\S+)/; |
67 | |
75 | |
… | |
… | |
73 | push @{$topics{$v->[0]}}, $k; |
81 | push @{$topics{$v->[0]}}, $k; |
74 | } |
82 | } |
75 | |
83 | |
76 | my $res; |
84 | my $res; |
77 | while (my ($k, $v) = each %topics) { |
85 | while (my ($k, $v) = each %topics) { |
78 | $res .= "B<$k:>\n" . (join " ", sort @$v) . "\n\n"; |
86 | $res .= "T<$k:>\n\n" . (join " ", sort @$v) . "\n\n"; |
79 | } |
87 | } |
80 | |
88 | |
81 | $pl->reply (undef, $res); |
89 | $pl->send_msg ($HELP_CHANNEL => $res, cf::NDI_REPLY | cf::NDI_CLEAR); |
82 | |
90 | |
83 | } elsif (my $item = $TOPIC->{$topic}) { |
91 | } elsif (my $item = $TOPIC->{$topic}) { |
84 | my ($type, @pars) = @$item; |
92 | my ($type, @pars) = @$item; |
85 | $pl->reply (undef, cf::pod::as_cfpod \@pars); |
93 | $pl->send_msg ($HELP_CHANNEL => (cf::pod::as_cfpod \@pars), cf::NDI_REPLY | cf::NDI_CLEAR); |
86 | |
94 | |
87 | } else { |
95 | } else { |
88 | $pl->reply (undef, "'$topic' no such help topic, try just 'help' to get a list of topics."); |
96 | $pl->send_msg ($HELP_CHANNEL => "'$topic' no such help topic, try just 'help' to get a list of topics.", cf::NDI_REPLY); |
89 | } |
97 | } |
90 | }; |
98 | }; |
91 | |
99 | |