You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

help.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
  2. // released under the MIT license
  3. package irc
  4. import (
  5. "fmt"
  6. "sort"
  7. "strings"
  8. "sync"
  9. "github.com/oragono/oragono/irc/languages"
  10. )
  11. // HelpEntryType represents the different sorts of help entries that can exist.
  12. type HelpEntryType int
  13. const (
  14. // CommandHelpEntry is a help entry explaining a client command.
  15. CommandHelpEntry HelpEntryType = iota
  16. // InformationHelpEntry is a help entry explaining general server info.
  17. InformationHelpEntry
  18. // ISupportHelpEntry is a help entry explaining a specific RPL_ISUPPORT token.
  19. ISupportHelpEntry
  20. )
  21. // HelpEntry represents an entry in the Help map.
  22. type HelpEntry struct {
  23. oper bool
  24. text string
  25. textGenerator func(*Client) string
  26. helpType HelpEntryType
  27. duplicate bool
  28. }
  29. // used for duplicates
  30. var (
  31. cmodeHelpText = `== Channel Modes ==
  32. Oragono supports the following channel modes:
  33. +b | Client masks that are banned from the channel (e.g. *!*@127.0.0.1)
  34. +e | Client masks that are exempted from bans.
  35. +I | Client masks that are exempted from the invite-only flag.
  36. +i | Invite-only mode, only invited clients can join the channel.
  37. +k | Key required when joining the channel.
  38. +l | Client join limit for the channel.
  39. +m | Moderated mode, only privileged clients can talk on the channel.
  40. +n | No-outside-messages mode, only users that are on the channel can send
  41. | messages to it.
  42. +R | Only registered users can join the channel.
  43. +M | Only registered or voiced users can speak in the channel.
  44. +s | Secret mode, channel won't show up in /LIST or whois replies.
  45. +t | Only channel opers can modify the topic.
  46. +E | Roleplaying commands are enabled in the channel.
  47. +C | Clients are blocked from sending CTCP messages in the channel.
  48. +u | Auditorium mode: JOIN, PART, QUIT, NAMES, and WHO are hidden
  49. from unvoiced clients.
  50. +U | Op-moderated mode: messages from unprivileged clients are sent
  51. only to channel operators.
  52. = Prefixes =
  53. +q (~) | Founder channel mode.
  54. +a (&) | Admin channel mode.
  55. +o (@) | Operator channel mode.
  56. +h (%) | Halfop channel mode.
  57. +v (+) | Voice channel mode.`
  58. umodeHelpText = `== User Modes ==
  59. Oragono supports the following user modes:
  60. +a | User is marked as being away. This mode is set with the /AWAY command.
  61. +i | User is marked as invisible (their channels are hidden from whois replies).
  62. +o | User is an IRC operator.
  63. +R | User only accepts messages from other registered users.
  64. +s | Server Notice Masks (see help with /HELPOP snomasks).
  65. +Z | User is connected via TLS.
  66. +B | User is a bot.
  67. +E | User can receive roleplaying commands.
  68. +T | CTCP messages to the user are blocked.`
  69. snomaskHelpText = `== Server Notice Masks ==
  70. Oragono supports the following server notice masks for operators:
  71. a | Local announcements.
  72. c | Local client connections.
  73. j | Local channel actions.
  74. k | Local kills.
  75. n | Local nick changes.
  76. o | Local oper actions.
  77. q | Local quits.
  78. t | Local /STATS usage.
  79. u | Local client account actions.
  80. x | Local X-lines (DLINE/KLINE/etc).
  81. v | Local vhost changes.
  82. To set a snomask, do this with your nickname:
  83. /MODE <nick> +s <chars>
  84. For instance, this would set the kill, oper, account and xline snomasks on dan:
  85. /MODE dan +s koux`
  86. )
  87. // Help contains the help strings distributed with the IRCd.
  88. var Help = map[string]HelpEntry{
  89. // Commands
  90. "ambiance": {
  91. text: `AMBIANCE <target> <text to be sent>
  92. The AMBIANCE command is used to send a scene notification to the given target.`,
  93. },
  94. "authenticate": {
  95. text: `AUTHENTICATE
  96. Used during SASL authentication. See the IRCv3 specs for more info:
  97. http://ircv3.net/specs/extensions/sasl-3.1.html`,
  98. },
  99. "away": {
  100. text: `AWAY [message]
  101. If [message] is sent, marks you away. If [message] is not sent, marks you no
  102. longer away.`,
  103. },
  104. "batch": {
  105. text: `BATCH {+,-}reference-tag type [params...]
  106. BATCH initiates an IRCv3 client-to-server batch. You should never need to
  107. issue this command manually.`,
  108. },
  109. "cap": {
  110. text: `CAP <subcommand> [:<capabilities>]
  111. Used in capability negotiation. See the IRCv3 specs for more info:
  112. http://ircv3.net/specs/core/capability-negotiation-3.1.html
  113. http://ircv3.net/specs/core/capability-negotiation-3.2.html`,
  114. },
  115. "chathistory": {
  116. text: `CHATHISTORY [params]
  117. CHATHISTORY is a history replay command associated with the IRCv3
  118. specification draft/chathistory. See this document:
  119. https://github.com/ircv3/ircv3-specifications/pull/393`,
  120. },
  121. "debug": {
  122. oper: true,
  123. text: `DEBUG <option>
  124. Provides various debugging commands for the IRCd. <option> can be one of:
  125. * GCSTATS: Garbage control statistics.
  126. * NUMGOROUTINE: Number of goroutines in use.
  127. * STARTCPUPROFILE: Starts the CPU profiler.
  128. * STOPCPUPROFILE: Stops the CPU profiler.
  129. * PROFILEHEAP: Writes a memory profile.
  130. * CRASHSERVER: Crashes the server (for use in failover testing)`,
  131. },
  132. "defcon": {
  133. oper: true,
  134. text: `DEFCON [level]
  135. The DEFCON system can disable server features at runtime, to mitigate
  136. spam or other hostile activity. It has five levels, which are cumulative
  137. (i.e., level 3 includes all restrictions from level 4 and so on):
  138. 5: Normal operation
  139. 4: No new account or channel registrations; if Tor is enabled, no new
  140. unauthenticated connections from Tor
  141. 3: All users are +R; no changes to vhosts
  142. 2: No new unauthenticated connections; all channels are +R
  143. 1: No new connections except from localhost or other trusted IPs`,
  144. },
  145. "deoper": {
  146. oper: true,
  147. text: `DEOPER
  148. DEOPER removes the IRCop privileges granted to you by a successful /OPER.`,
  149. },
  150. "dline": {
  151. oper: true,
  152. text: `DLINE [ANDKILL] [MYSELF] [duration] <ip>/<net> [ON <server>] [reason [| oper reason]]
  153. DLINE LIST
  154. Bans an IP address or network from connecting to the server. If the duration is
  155. given then only for that long. The reason is shown to the user themselves, but
  156. everyone else will see a standard message. The oper reason is shown to
  157. operators getting info about the DLINEs that exist.
  158. Bans are saved across subsequent launches of the server.
  159. "ANDKILL" means that all matching clients are also removed from the server.
  160. "MYSELF" is required when the DLINE matches the address the person applying it is connected
  161. from. If "MYSELF" is not given, trying to DLINE yourself will result in an error.
  162. [duration] can be of the following forms:
  163. 1y 12mo 31d 10h 8m 13s
  164. <net> is specified in typical CIDR notation. For example:
  165. 127.0.0.1/8
  166. 8.8.8.8/24
  167. ON <server> specifies that the ban is to be set on that specific server.
  168. [reason] and [oper reason], if they exist, are separated by a vertical bar (|).
  169. If "DLINE LIST" is sent, the server sends back a list of our current DLINEs.
  170. To remove a DLINE, use the "UNDLINE" command.`,
  171. },
  172. "extjwt": {
  173. text: `EXTJWT <target> [service_name]
  174. Get a JSON Web Token for target (either * or a channel name).`,
  175. },
  176. "help": {
  177. text: `HELP <argument>
  178. Get an explanation of <argument>, or "index" for a list of help topics.`,
  179. },
  180. "helpop": {
  181. text: `HELPOP <argument>
  182. Get an explanation of <argument>, or "index" for a list of help topics.`,
  183. },
  184. "history": {
  185. text: `HISTORY <target> [limit]
  186. Replay message history. <target> can be a channel name, "me" to replay direct
  187. message history, or a nickname to replay another client's direct message
  188. history (they must be logged into the same account as you). [limit] can be
  189. either an integer (the maximum number of messages to replay), or a time
  190. duration like 10m or 1h (the time window within which to replay messages).`,
  191. },
  192. "info": {
  193. text: `INFO
  194. Sends information about the server, developers, etc.`,
  195. },
  196. "invite": {
  197. text: `INVITE <nickname> <channel>
  198. Invites the given user to the given channel, so long as you have the
  199. appropriate channel privs.`,
  200. },
  201. "ison": {
  202. text: `ISON <nickname>{ <nickname>}
  203. Returns whether the given nicks exist on the network.`,
  204. },
  205. "join": {
  206. text: `JOIN <channel>{,<channel>} [<key>{,<key>}]
  207. Joins the given channels with the matching keys.`,
  208. },
  209. "kick": {
  210. text: `KICK <channel> <user> [reason]
  211. Removes the user from the given channel, so long as you have the appropriate
  212. channel privs.`,
  213. },
  214. "kill": {
  215. oper: true,
  216. text: `KILL <nickname> [reason]
  217. Removes the given user from the network, showing them the reason if it is
  218. supplied.`,
  219. },
  220. "kline": {
  221. oper: true,
  222. text: `KLINE [ANDKILL] [MYSELF] [duration] <mask> [ON <server>] [reason [| oper reason]]
  223. KLINE LIST
  224. Bans a mask from connecting to the server. If the duration is given then only for that
  225. long. The reason is shown to the user themselves, but everyone else will see a standard
  226. message. The oper reason is shown to operators getting info about the KLINEs that exist.
  227. Bans are saved across subsequent launches of the server.
  228. "ANDKILL" means that all matching clients are also removed from the server.
  229. "MYSELF" is required when the KLINE matches the address the person applying it is connected
  230. from. If "MYSELF" is not given, trying to KLINE yourself will result in an error.
  231. [duration] can be of the following forms:
  232. 1y 12mo 31d 10h 8m 13s
  233. <mask> is specified in typical IRC format. For example:
  234. dan
  235. dan!5*@127.*
  236. ON <server> specifies that the ban is to be set on that specific server.
  237. [reason] and [oper reason], if they exist, are separated by a vertical bar (|).
  238. If "KLINE LIST" is sent, the server sends back a list of our current KLINEs.
  239. To remove a KLINE, use the "UNKLINE" command.`,
  240. },
  241. "language": {
  242. text: `LANGUAGE <code>{ <code>}
  243. Sets your preferred languages to the given ones.`,
  244. },
  245. "list": {
  246. text: `LIST [<channel>{,<channel>}] [<elistcond>{,<elistcond>}]
  247. Shows information on the given channels (or if none are given, then on all
  248. channels). <elistcond>s modify how the channels are selected.`,
  249. //TODO(dan): Explain <elistcond>s in more specific detail
  250. },
  251. "lusers": {
  252. text: `LUSERS [<mask> [<server>]]
  253. Shows statistics about the size of the network. If <mask> is given, only
  254. returns stats for servers matching the given mask. If <server> is given, the
  255. command is processed by that server.`,
  256. },
  257. "mode": {
  258. text: `MODE <target> [<modestring> [<mode arguments>...]]
  259. Sets and removes modes from the given target. For more specific information on
  260. mode characters, see the help for "modes".`,
  261. },
  262. "monitor": {
  263. text: `MONITOR <subcmd>
  264. Allows the monitoring of nicknames, for alerts when they are online and
  265. offline. The subcommands are:
  266. MONITOR + target{,target}
  267. Adds the given names to your list of monitored nicknames.
  268. MONITOR - target{,target}
  269. Removes the given names from your list of monitored nicknames.
  270. MONITOR C
  271. Clears your list of monitored nicknames.
  272. MONITOR L
  273. Lists all the nicknames you are currently monitoring.
  274. MONITOR S
  275. Lists whether each nick in your MONITOR list is online or offline.`,
  276. },
  277. "motd": {
  278. text: `MOTD [server]
  279. Returns the message of the day for this, or the given, server.`,
  280. },
  281. "names": {
  282. text: `NAMES [<channel>{,<channel>}]
  283. Views the clients joined to a channel and their channel membership prefixes. To
  284. view the channel membership prefixes supported by this server, see the help for
  285. "PREFIX".`,
  286. },
  287. "nick": {
  288. text: `NICK <newnick>
  289. Sets your nickname to the new given one.`,
  290. },
  291. "notice": {
  292. text: `NOTICE <target>{,<target>} <text to be sent>
  293. Sends the text to the given targets as a NOTICE.`,
  294. },
  295. "npc": {
  296. text: `NPC <target> <sourcenick> <text to be sent>
  297. The NPC command is used to send a message to the target as the source.
  298. Requires the roleplay mode (+E) to be set on the target.`,
  299. },
  300. "npca": {
  301. text: `NPCA <target> <sourcenick> <text to be sent>
  302. The NPC command is used to send an action to the target as the source.
  303. Requires the roleplay mode (+E) to be set on the target.`,
  304. },
  305. "oper": {
  306. text: `OPER <name> [password]
  307. If the correct details are given, gives you IRCop privs.`,
  308. },
  309. "part": {
  310. text: `PART <channel>{,<channel>} [reason]
  311. Leaves the given channels and shows people the given reason.`,
  312. },
  313. "pass": {
  314. text: `PASS <password>
  315. When the server requires a connection password to join, used to send us the
  316. password.`,
  317. },
  318. "ping": {
  319. text: `PING <args>...
  320. Requests a PONG. Used to check link connectivity.`,
  321. },
  322. "pong": {
  323. text: `PONG <args>...
  324. Replies to a PING. Used to check link connectivity.`,
  325. },
  326. "privmsg": {
  327. text: `PRIVMSG <target>{,<target>} <text to be sent>
  328. Sends the text to the given targets as a PRIVMSG.`,
  329. },
  330. "relaymsg": {
  331. text: `RELAYMSG <channel> <spoofed nick> :<message>
  332. This command lets channel operators relay messages to their
  333. channel from other messaging systems using relay bots. The
  334. spoofed nickname MUST contain a forwardslash.
  335. For example:
  336. RELAYMSG #ircv3 Mallory/D :Welp, we linked Discord...`,
  337. },
  338. "rename": {
  339. text: `RENAME <channel> <newname> [<reason>]
  340. Renames the given channel with the given reason, if possible.
  341. For example:
  342. RENAME #ircv2 #ircv3 :Protocol upgrades!`,
  343. },
  344. "sajoin": {
  345. oper: true,
  346. text: `SAJOIN [nick] #channel{,#channel}
  347. Forcibly joins a user to a channel, ignoring restrictions like bans, user limits
  348. and channel keys. If [nick] is omitted, it defaults to the operator.`,
  349. },
  350. "sanick": {
  351. oper: true,
  352. text: `SANICK <currentnick> <newnick>
  353. Gives the given user a new nickname.`,
  354. },
  355. "samode": {
  356. oper: true,
  357. text: `SAMODE <target> [<modestring> [<mode arguments>...]]
  358. Forcibly sets and removes modes from the given target -- only available to
  359. opers. For more specific information on mode characters, see the help for
  360. "cmode" and "umode".`,
  361. },
  362. "scene": {
  363. text: `SCENE <target> <text to be sent>
  364. The SCENE command is used to send a scene notification to the given target.`,
  365. },
  366. "setname": {
  367. text: `SETNAME <realname>
  368. The SETNAME command updates the realname to be the newly-given one.`,
  369. },
  370. "summon": {
  371. text: `SUMMON [parameters]
  372. The SUMMON command is not implemented.`,
  373. },
  374. "tagmsg": {
  375. text: `@+client-only-tags TAGMSG <target>{,<target>}
  376. Sends the given client-only tags to the given targets as a TAGMSG. See the IRCv3
  377. specs for more info: http://ircv3.net/specs/core/message-tags-3.3.html`,
  378. },
  379. "quit": {
  380. text: `QUIT [reason]
  381. Indicates that you're leaving the server, and shows everyone the given reason.`,
  382. },
  383. "register": {
  384. text: `REGISTER <email | *> <password>
  385. Registers an account in accordance with the draft/register capability.`,
  386. },
  387. "rehash": {
  388. oper: true,
  389. text: `REHASH
  390. Reloads the config file and updates TLS certificates on listeners`,
  391. },
  392. "time": {
  393. text: `TIME [server]
  394. Shows the time of the current, or the given, server.`,
  395. },
  396. "topic": {
  397. text: `TOPIC <channel> [topic]
  398. If [topic] is given, sets the topic in the channel to that. If [topic] is not
  399. given, views the current topic on the channel.`,
  400. },
  401. "uban": {
  402. text: `UBAN <subcommand> [arguments]
  403. Oragono's "unified ban" system. Accepts the following subcommands:
  404. 1. UBAN ADD <target> [REQUIRE-SASL] [DURATION <duration>] [REASON...]
  405. 2. UBAN DEL <target>
  406. 3. UBAN LIST
  407. 4. UBAN INFO <target>
  408. <target> may be an IP, a CIDR, a nickmask with wildcards, or the name of an
  409. account to suspend. Note that REQUIRE-SASL is only valid for IP and CIDR bans.`,
  410. },
  411. "undline": {
  412. oper: true,
  413. text: `UNDLINE <ip>/<net>
  414. Removes an existing ban on an IP address or a network.
  415. <net> is specified in typical CIDR notation. For example:
  416. 127.0.0.1/8
  417. 8.8.8.8/24`,
  418. },
  419. "unkline": {
  420. oper: true,
  421. text: `UNKLINE <mask>
  422. Removes an existing ban on a mask.
  423. For example:
  424. dan
  425. dan!5*@127.*`,
  426. },
  427. "user": {
  428. text: `USER <username> 0 * <realname>
  429. Used in connection registration, sets your username and realname to the given
  430. values (though your username may also be looked up with Ident).`,
  431. },
  432. "uninvite": {
  433. text: `UNINVITE <nickname> <channel>
  434. UNINVITE rescinds a channel invitation sent for an invite-only channel.`,
  435. },
  436. "users": {
  437. text: `USERS [parameters]
  438. The USERS command is not implemented.`,
  439. },
  440. "userhost": {
  441. text: `USERHOST <nickname>{ <nickname>}
  442. Shows information about the given users. Takes up to 10 nicknames.`,
  443. },
  444. "verify": {
  445. text: `VERIFY <account> <password>
  446. Verifies an account in accordance with the draft/register capability.`,
  447. },
  448. "version": {
  449. text: `VERSION [server]
  450. Views the version of software and the RPL_ISUPPORT tokens for the given server.`,
  451. },
  452. "webirc": {
  453. oper: true, // not really, but it's restricted anyways
  454. text: `WEBIRC <password> <gateway> <hostname> <ip> [:<flags>]
  455. Used by web<->IRC gateways and bouncers, the WEBIRC command allows gateways to
  456. pass-through the real IP addresses of clients:
  457. ircv3.net/specs/extensions/webirc.html
  458. <flags> is a list of space-separated strings indicating various details about
  459. the connection from the client to the gateway, such as:
  460. - tls: this flag indicates that the client->gateway connection is secure`,
  461. },
  462. "who": {
  463. text: `WHO <name> [o]
  464. Returns information for the given user.`,
  465. },
  466. "whois": {
  467. text: `WHOIS <client>{,<client>}
  468. Returns information for the given user(s).`,
  469. },
  470. "whowas": {
  471. text: `WHOWAS <nickname>
  472. Returns historical information on the last user with the given nickname.`,
  473. },
  474. "znc": {
  475. text: `ZNC <module> [params]
  476. Used to emulate features of the ZNC bouncer. This command is not intended
  477. for direct use by end users.`,
  478. duplicate: true,
  479. },
  480. // Informational
  481. "modes": {
  482. textGenerator: modesTextGenerator,
  483. helpType: InformationHelpEntry,
  484. },
  485. "cmode": {
  486. text: cmodeHelpText,
  487. helpType: InformationHelpEntry,
  488. },
  489. "cmodes": {
  490. text: cmodeHelpText,
  491. helpType: InformationHelpEntry,
  492. duplicate: true,
  493. },
  494. "umode": {
  495. text: umodeHelpText,
  496. helpType: InformationHelpEntry,
  497. },
  498. "umodes": {
  499. text: umodeHelpText,
  500. helpType: InformationHelpEntry,
  501. duplicate: true,
  502. },
  503. "snomask": {
  504. text: snomaskHelpText,
  505. helpType: InformationHelpEntry,
  506. oper: true,
  507. duplicate: true,
  508. },
  509. "snomasks": {
  510. text: snomaskHelpText,
  511. helpType: InformationHelpEntry,
  512. oper: true,
  513. },
  514. // RPL_ISUPPORT
  515. "casemapping": {
  516. text: `RPL_ISUPPORT CASEMAPPING
  517. Oragono supports an experimental unicode casemapping designed for extended
  518. Unicode support. This casemapping is based off RFC 7613 and the draft rfc7613
  519. casemapping spec here: https://oragono.io/specs.html`,
  520. helpType: ISupportHelpEntry,
  521. },
  522. "prefix": {
  523. text: `RPL_ISUPPORT PREFIX
  524. Oragono supports the following channel membership prefixes:
  525. +q (~) | Founder channel mode.
  526. +a (&) | Admin channel mode.
  527. +o (@) | Operator channel mode.
  528. +h (%) | Halfop channel mode.
  529. +v (+) | Voice channel mode.`,
  530. helpType: ISupportHelpEntry,
  531. },
  532. }
  533. // modesTextGenerator generates the text for the 'modes' help entry.
  534. // it exists only so we can translate this entry appropriately.
  535. func modesTextGenerator(client *Client) string {
  536. return client.t(cmodeHelpText) + "\n\n" + client.t(umodeHelpText)
  537. }
  538. type HelpIndexManager struct {
  539. sync.RWMutex // tier 1
  540. langToIndex map[string]string
  541. langToOperIndex map[string]string
  542. }
  543. // GenerateHelpIndex is used to generate HelpIndex.
  544. // Returns: a map from language code to the help index in that language.
  545. func GenerateHelpIndex(lm *languages.Manager, forOpers bool) map[string]string {
  546. // generate the help entry lists
  547. var commands, isupport, information []string
  548. var line string
  549. for name, info := range Help {
  550. if info.duplicate {
  551. continue
  552. }
  553. if info.oper && !forOpers {
  554. continue
  555. }
  556. line = fmt.Sprintf(" %s", name)
  557. if info.helpType == CommandHelpEntry {
  558. commands = append(commands, line)
  559. } else if info.helpType == ISupportHelpEntry {
  560. isupport = append(isupport, line)
  561. } else if info.helpType == InformationHelpEntry {
  562. information = append(information, line)
  563. }
  564. }
  565. // create the strings
  566. sort.Strings(commands)
  567. commandsString := strings.Join(commands, "\n")
  568. sort.Strings(isupport)
  569. isupportString := strings.Join(isupport, "\n")
  570. sort.Strings(information)
  571. informationString := strings.Join(information, "\n")
  572. // sub them in
  573. defaultHelpIndex := `= Help Topics =
  574. Commands:
  575. %[1]s
  576. RPL_ISUPPORT Tokens:
  577. %[2]s
  578. Information:
  579. %[3]s`
  580. newHelpIndex := make(map[string]string)
  581. newHelpIndex["en"] = fmt.Sprintf(defaultHelpIndex, commandsString, isupportString, informationString)
  582. for langCode := range lm.Languages {
  583. translatedHelpIndex := lm.Translate([]string{langCode}, defaultHelpIndex)
  584. if translatedHelpIndex != defaultHelpIndex {
  585. newHelpIndex[langCode] = fmt.Sprintf(translatedHelpIndex, commandsString, isupportString, informationString)
  586. }
  587. }
  588. return newHelpIndex
  589. }
  590. // GenerateIndices regenerates our help indexes for each currently enabled language.
  591. func (hm *HelpIndexManager) GenerateIndices(lm *languages.Manager) {
  592. // generate help indexes
  593. langToIndex := GenerateHelpIndex(lm, false)
  594. langToOperIndex := GenerateHelpIndex(lm, true)
  595. hm.Lock()
  596. defer hm.Unlock()
  597. hm.langToIndex = langToIndex
  598. hm.langToOperIndex = langToOperIndex
  599. }
  600. // sendHelp sends the client help of the given string.
  601. func (client *Client) sendHelp(helpEntry string, text string, rb *ResponseBuffer) {
  602. helpEntry = strings.ToUpper(helpEntry)
  603. nick := client.Nick()
  604. textLines := strings.Split(text, "\n")
  605. for i, line := range textLines {
  606. if i == 0 {
  607. rb.Add(nil, client.server.name, RPL_HELPSTART, nick, helpEntry, line)
  608. } else {
  609. rb.Add(nil, client.server.name, RPL_HELPTXT, nick, helpEntry, line)
  610. }
  611. }
  612. rb.Add(nil, client.server.name, RPL_ENDOFHELP, nick, helpEntry, client.t("End of /HELPOP"))
  613. }
  614. // GetHelpIndex returns the help index for the given language.
  615. func (hm *HelpIndexManager) GetIndex(languages []string, oper bool) string {
  616. hm.RLock()
  617. langToIndex := hm.langToIndex
  618. if oper {
  619. langToIndex = hm.langToOperIndex
  620. }
  621. hm.RUnlock()
  622. for _, lang := range languages {
  623. index, exists := langToIndex[lang]
  624. if exists {
  625. return index
  626. }
  627. }
  628. // 'en' always exists
  629. return langToIndex["en"]
  630. }
  631. func init() {
  632. // startup check that we have HELP entries for every command
  633. for name := range Commands {
  634. _, exists := Help[strings.ToLower(name)]
  635. if !exists {
  636. panic(fmt.Sprintf("Help entry does not exist for command %s", name))
  637. }
  638. }
  639. }