Commit | Line | Data |
---|---|---|
281f2c0e IJ |
1 | proc loadhelp {} { |
2 | global help_topics errorInfo helpfile | |
3 | ||
4 | catch { unset help_topics } | |
5 | set f [open $helpfile r] | |
6 | try_except_finally { | |
7 | set lno 0 | |
8 | while {[gets $f l] >= 0} { | |
9 | incr lno | |
10 | if {[regexp {^#.*} $l]} { | |
11 | } elseif {[regexp {^ *$} $l]} { | |
12 | if {[info exists topic]} { | |
13 | set help_topics($topic) [join $lines "\n"] | |
14 | unset topic | |
15 | unset lines | |
16 | } | |
17 | } elseif {[regexp {^\:\:} $l]} { | |
18 | } elseif {[regexp {^\:([-+._0-9a-z]*)$} $l dummy newtopic]} { | |
19 | if {[info exists topic]} { | |
20 | error "help $newtopic while in $topic" | |
21 | } | |
22 | set topic $newtopic | |
23 | set lines {} | |
24 | } elseif {[regexp {^[^:#]} $l]} { | |
25 | set topic | |
26 | regsub -all {([^\\])\!\$?} _$l {\1} l | |
27 | regsub -all {\\(.)} $l {\1} l | |
28 | regsub {^_} $l {} l | |
29 | lappend lines [string trimright $l] | |
30 | } else { | |
31 | error "eh ? $lno: $l" | |
32 | } | |
33 | } | |
34 | if {[info exists topic]} { error "unfinished topic $topic" } | |
35 | } { | |
36 | set errorInfo "in $helpfile line $lno\n$errorInfo" | |
37 | } { | |
38 | close $f | |
39 | } | |
40 | } | |
41 | ||
42 | def_ucmd help { | |
43 | upvar 1 n n | |
44 | ||
45 | set topic [irctolower [string trim $text]] | |
46 | if {[string length $topic]} { | |
47 | set ontopic " on `$topic'" | |
48 | } else { | |
49 | set ontopic "" | |
50 | } | |
51 | if {[set lag [out_lagged]]} { | |
52 | if {[ischan $dest]} { set replyto $dest } else { set replyto $n } | |
53 | if {$lag > 1} { | |
54 | sendaction_priority 1 $replyto \ | |
55 | "is very lagged. Please ask for help$ontopic again later." | |
56 | ucmdr {} {} | |
57 | } else { | |
58 | sendaction_priority 1 $replyto \ | |
59 | "is lagged. Your help$ontopic will arrive shortly ..." | |
60 | } | |
61 | } | |
62 | ||
63 | upvar #0 help_topics($topic) info | |
64 | if {![info exists info]} { ucmdr "No help on $topic, sorry." {} } | |
65 | ucmdr $info {} | |
66 | } | |
67 | ||
68 | def_ucmd ? { | |
69 | global help_topics | |
70 | ucmdr $help_topics() {} | |
71 | } | |
72 |