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