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 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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 talk in the channel.
  43. +s | Secret mode, channel won't show up in /LIST or whois replies.
  44. +t | Only channel opers can modify the topic.
  45. = Prefixes =
  46. +q (~) | Founder channel mode.
  47. +a (&) | Admin channel mode.
  48. +o (@) | Operator channel mode.
  49. +h (%) | Halfop channel mode.
  50. +v (+) | Voice channel mode.`
  51. umodeHelpText = `== User Modes ==
  52. Oragono supports the following user modes:
  53. +a | User is marked as being away. This mode is set with the /AWAY command.
  54. +i | User is marked as invisible (their channels are hidden from whois replies).
  55. +o | User is an IRC operator.
  56. +R | User only accepts messages from other registered users.
  57. +s | Server Notice Masks (see help with /HELPOP snomasks).
  58. +Z | User is connected via TLS.`
  59. snomaskHelpText = `== Server Notice Masks ==
  60. Oragono supports the following server notice masks for operators:
  61. a | Local announcements.
  62. c | Local client connections.
  63. j | Local channel actions.
  64. k | Local kills.
  65. n | Local nick changes.
  66. o | Local oper actions.
  67. q | Local quits.
  68. t | Local /STATS usage.
  69. u | Local client account actions.
  70. x | Local X-lines (DLINE/KLINE/etc).
  71. To set a snomask, do this with your nickname:
  72. /MODE <nick> +s <chars>
  73. For instance, this would set the kill, oper, account and xline snomasks on dan:
  74. /MODE dan +s koux`
  75. )
  76. // Help contains the help strings distributed with the IRCd.
  77. var Help = map[string]HelpEntry{
  78. // Commands
  79. "acc": {
  80. text: `ACC REGISTER <accountname> [callback_namespace:]<callback> [cred_type] :<credential>
  81. ACC VERIFY <accountname> <auth_code>
  82. Used in account registration. See the relevant specs for more info:
  83. https://oragono.io/specs.html`,
  84. },
  85. "ambiance": {
  86. text: `AMBIANCE <target> <text to be sent>
  87. The AMBIANCE command is used to send a scene notification to the given target.`,
  88. },
  89. "authenticate": {
  90. text: `AUTHENTICATE
  91. Used during SASL authentication. See the IRCv3 specs for more info:
  92. http://ircv3.net/specs/extensions/sasl-3.1.html`,
  93. },
  94. "away": {
  95. text: `AWAY [message]
  96. If [message] is sent, marks you away. If [message] is not sent, marks you no
  97. longer away.`,
  98. },
  99. "cap": {
  100. text: `CAP <subcommand> [:<capabilities>]
  101. Used in capability negotiation. See the IRCv3 specs for more info:
  102. http://ircv3.net/specs/core/capability-negotiation-3.1.html
  103. http://ircv3.net/specs/core/capability-negotiation-3.2.html`,
  104. },
  105. "chanserv": {
  106. text: `CHANSERV <subcommand> [params]
  107. ChanServ controls channel registrations.`,
  108. },
  109. "chathistory": {
  110. text: `CHATHISTORY [params]
  111. CHATHISTORY is an experimental history replay command. See these documents:
  112. https://github.com/MuffinMedic/ircv3-specifications/blob/chathistory/extensions/chathistory.md
  113. https://gist.github.com/DanielOaks/c104ad6e8759c01eb5c826d627caf80d`,
  114. },
  115. "cs": {
  116. text: `CS <subcommand> [params]
  117. ChanServ controls channel registrations.`,
  118. },
  119. "debug": {
  120. oper: true,
  121. text: `DEBUG <option>
  122. Prints debug information about the IRCd. <option> can be one of:
  123. * GCSTATS: Garbage control statistics.
  124. * NUMGOROUTINE: Number of goroutines in use.
  125. * STARTCPUPROFILE: Starts the CPU profiler.
  126. * STOPCPUPROFILE: Stops the CPU profiler.
  127. * PROFILEHEAP: Writes out the CPU profiler info.`,
  128. },
  129. "dline": {
  130. oper: true,
  131. text: `DLINE [ANDKILL] [MYSELF] [duration] <ip>/<net> [ON <server>] [reason [| oper reason]]
  132. DLINE LIST
  133. Bans an IP address or network from connecting to the server. If the duration is
  134. given then only for that long. The reason is shown to the user themselves, but
  135. everyone else will see a standard message. The oper reason is shown to
  136. operators getting info about the DLINEs that exist.
  137. Bans are saved across subsequent launches of the server.
  138. "ANDKILL" means that all matching clients are also removed from the server.
  139. "MYSELF" is required when the DLINE matches the address the person applying it is connected
  140. from. If "MYSELF" is not given, trying to DLINE yourself will result in an error.
  141. [duration] can be of the following forms:
  142. 1y 12mo 31d 10h 8m 13s
  143. <net> is specified in typical CIDR notation. For example:
  144. 127.0.0.1/8
  145. 8.8.8.8/24
  146. ON <server> specifies that the ban is to be set on that specific server.
  147. [reason] and [oper reason], if they exist, are separated by a vertical bar (|).
  148. If "DLINE LIST" is sent, the server sends back a list of our current DLINEs.`,
  149. },
  150. "help": {
  151. text: `HELP <argument>
  152. Get an explanation of <argument>, or "index" for a list of help topics.`,
  153. },
  154. "helpop": {
  155. text: `HELPOP <argument>
  156. Get an explanation of <argument>, or "index" for a list of help topics.`,
  157. },
  158. "history": {
  159. text: `HISTORY <target> [limit]
  160. Replay message history. <target> can be a channel name, "me" to replay direct
  161. message history, or a nickname to replay another client's direct message
  162. history (they must be logged into the same account as you). At most [limit]
  163. messages will be replayed.`,
  164. },
  165. "hostserv": {
  166. text: `HOSTSERV <command> [params]
  167. HostServ lets you manage your vhost (a string displayed in place of your
  168. real hostname).`,
  169. },
  170. "hs": {
  171. text: `HS <command> [params]
  172. HostServ lets you manage your vhost (a string displayed in place of your
  173. real hostname).`,
  174. },
  175. "info": {
  176. text: `INFO
  177. Sends information about the server, developers, etc.`,
  178. },
  179. "invite": {
  180. text: `INVITE <nickname> <channel>
  181. Invites the given user to the given channel, so long as you have the
  182. appropriate channel privs.`,
  183. },
  184. "ison": {
  185. text: `ISON <nickname>{ <nickname>}
  186. Returns whether the given nicks exist on the network.`,
  187. },
  188. "join": {
  189. text: `JOIN <channel>{,<channel>} [<key>{,<key>}]
  190. Joins the given channels with the matching keys.`,
  191. },
  192. "kick": {
  193. text: `KICK <channel> <user> [reason]
  194. Removes the user from the given channel, so long as you have the appropriate
  195. channel privs.`,
  196. },
  197. "kill": {
  198. oper: true,
  199. text: `KILL <nickname> [reason]
  200. Removes the given user from the network, showing them the reason if it is
  201. supplied.`,
  202. },
  203. "kline": {
  204. oper: true,
  205. text: `KLINE [ANDKILL] [MYSELF] [duration] <mask> [ON <server>] [reason [| oper reason]]
  206. KLINE LIST
  207. Bans a mask from connecting to the server. If the duration is given then only for that
  208. long. The reason is shown to the user themselves, but everyone else will see a standard
  209. message. The oper reason is shown to operators getting info about the KLINEs that exist.
  210. Bans are saved across subsequent launches of the server.
  211. "ANDKILL" means that all matching clients are also removed from the server.
  212. "MYSELF" is required when the KLINE matches the address the person applying it is connected
  213. from. If "MYSELF" is not given, trying to KLINE yourself will result in an error.
  214. [duration] can be of the following forms:
  215. 1y 12mo 31d 10h 8m 13s
  216. <mask> is specified in typical IRC format. For example:
  217. dan
  218. dan!5*@127.*
  219. ON <server> specifies that the ban is to be set on that specific server.
  220. [reason] and [oper reason], if they exist, are separated by a vertical bar (|).
  221. If "KLINE LIST" is sent, the server sends back a list of our current KLINEs.`,
  222. },
  223. "language": {
  224. text: `LANGUAGE <code>{ <code>}
  225. Sets your preferred languages to the given ones.`,
  226. },
  227. "list": {
  228. text: `LIST [<channel>{,<channel>}] [<elistcond>{,<elistcond>}]
  229. Shows information on the given channels (or if none are given, then on all
  230. channels). <elistcond>s modify how the channels are selected.`,
  231. //TODO(dan): Explain <elistcond>s in more specific detail
  232. },
  233. "lusers": {
  234. text: `LUSERS [<mask> [<server>]]
  235. Shows statistics about the size of the network. If <mask> is given, only
  236. returns stats for servers matching the given mask. If <server> is given, the
  237. command is processed by that server.`,
  238. },
  239. "mode": {
  240. text: `MODE <target> [<modestring> [<mode arguments>...]]
  241. Sets and removes modes from the given target. For more specific information on
  242. mode characters, see the help for "modes".`,
  243. },
  244. "monitor": {
  245. text: `MONITOR <subcmd>
  246. Allows the monitoring of nicknames, for alerts when they are online and
  247. offline. The subcommands are:
  248. MONITOR + target{,target}
  249. Adds the given names to your list of monitored nicknames.
  250. MONITOR - target{,target}
  251. Removes the given names from your list of monitored nicknames.
  252. MONITOR C
  253. Clears your list of monitored nicknames.
  254. MONITOR L
  255. Lists all the nicknames you are currently monitoring.
  256. MONITOR S
  257. Lists whether each nick in your MONITOR list is online or offline.`,
  258. },
  259. "motd": {
  260. text: `MOTD [server]
  261. Returns the message of the day for this, or the given, server.`,
  262. },
  263. "names": {
  264. text: `NAMES [<channel>{,<channel>}]
  265. Views the clients joined to a channel and their channel membership prefixes. To
  266. view the channel membership prefixes supported by this server, see the help for
  267. "PREFIX".`,
  268. },
  269. "nick": {
  270. text: `NICK <newnick>
  271. Sets your nickname to the new given one.`,
  272. },
  273. "nickserv": {
  274. text: `NICKSERV <subcommand> [params]
  275. NickServ controls accounts and user registrations.`,
  276. },
  277. "notice": {
  278. text: `NOTICE <target>{,<target>} <text to be sent>
  279. Sends the text to the given targets as a NOTICE.`,
  280. },
  281. "npc": {
  282. text: `NPC <target> <sourcenick> <text to be sent>
  283. The NPC command is used to send a message to the target as the source.
  284. Requires the roleplay mode (+E) to be set on the target.`,
  285. },
  286. "npca": {
  287. text: `NPCA <target> <sourcenick> <text to be sent>
  288. The NPC command is used to send an action to the target as the source.
  289. Requires the roleplay mode (+E) to be set on the target.`,
  290. },
  291. "ns": {
  292. text: `NS <subcommand> [params]
  293. NickServ controls accounts and user registrations.`,
  294. },
  295. "oper": {
  296. text: `OPER <name> <password>
  297. If the correct details are given, gives you IRCop privs.`,
  298. },
  299. "part": {
  300. text: `PART <channel>{,<channel>} [reason]
  301. Leaves the given channels and shows people the given reason.`,
  302. },
  303. "pass": {
  304. text: `PASS <password>
  305. When the server requires a connection password to join, used to send us the
  306. password.`,
  307. },
  308. "ping": {
  309. text: `PING <args>...
  310. Requests a PONG. Used to check link connectivity.`,
  311. },
  312. "pong": {
  313. text: `PONG <args>...
  314. Replies to a PING. Used to check link connectivity.`,
  315. },
  316. "privmsg": {
  317. text: `PRIVMSG <target>{,<target>} <text to be sent>
  318. Sends the text to the given targets as a PRIVMSG.`,
  319. },
  320. "rename": {
  321. text: `RENAME <channel> <newname> [<reason>]
  322. Renames the given channel with the given reason, if possible.
  323. For example:
  324. RENAME #ircv2 #ircv3 :Protocol upgrades!`,
  325. },
  326. "sajoin": {
  327. oper: true,
  328. text: `SAJOIN [nick] #channel{,#channel}
  329. Forcibly joins a user to a channel, ignoring restrictions like bans, user limits
  330. and channel keys. If [nick] is omitted, it defaults to the operator.`,
  331. },
  332. "sanick": {
  333. oper: true,
  334. text: `SANICK <currentnick> <newnick>
  335. Gives the given user a new nickname.`,
  336. },
  337. "samode": {
  338. oper: true,
  339. text: `SAMODE <target> [<modestring> [<mode arguments>...]]
  340. Forcibly sets and removes modes from the given target -- only available to
  341. opers. For more specific information on mode characters, see the help for
  342. "cmode" and "umode".`,
  343. },
  344. "scene": {
  345. text: `SCENE <target> <text to be sent>
  346. The SCENE command is used to send a scene notification to the given target.`,
  347. },
  348. "setname": {
  349. text: `SETNAME <realname>
  350. The SETNAME command updates the realname to be the newly-given one.`,
  351. },
  352. "tagmsg": {
  353. text: `@+client-only-tags TAGMSG <target>{,<target>}
  354. Sends the given client-only tags to the given targets as a TAGMSG. See the IRCv3
  355. specs for more info: http://ircv3.net/specs/core/message-tags-3.3.html`,
  356. },
  357. "quit": {
  358. text: `QUIT [reason]
  359. Indicates that you're leaving the server, and shows everyone the given reason.`,
  360. },
  361. "rehash": {
  362. oper: true,
  363. text: `REHASH
  364. Reloads the config file and updates TLS certificates on listeners`,
  365. },
  366. "resume": {
  367. text: `RESUME <oldnick> [timestamp]
  368. Sent before registration has completed, this indicates that the client wants to
  369. resume their old connection <oldnick>.`,
  370. },
  371. "time": {
  372. text: `TIME [server]
  373. Shows the time of the current, or the given, server.`,
  374. },
  375. "topic": {
  376. text: `TOPIC <channel> [topic]
  377. If [topic] is given, sets the topic in the channel to that. If [topic] is not
  378. given, views the current topic on the channel.`,
  379. },
  380. "undline": {
  381. oper: true,
  382. text: `UNDLINE <ip>/<net>
  383. Removes an existing ban on an IP address or a network.
  384. <net> is specified in typical CIDR notation. For example:
  385. 127.0.0.1/8
  386. 8.8.8.8/24`,
  387. },
  388. "unkline": {
  389. oper: true,
  390. text: `UNKLINE <mask>
  391. Removes an existing ban on a mask.
  392. For example:
  393. dan
  394. dan!5*@127.*`,
  395. },
  396. "user": {
  397. text: `USER <username> 0 * <realname>
  398. Used in connection registration, sets your username and realname to the given
  399. values (though your username may also be looked up with Ident).`,
  400. },
  401. "userhost": {
  402. text: `USERHOST <nickname>{ <nickname>}
  403. Shows information about the given users. Takes up to 10 nicknames.`,
  404. },
  405. "version": {
  406. text: `VERSION [server]
  407. Views the version of software and the RPL_ISUPPORT tokens for the given server.`,
  408. },
  409. "webirc": {
  410. oper: true, // not really, but it's restricted anyways
  411. text: `WEBIRC <password> <gateway> <hostname> <ip> [:<flags>]
  412. Used by web<->IRC gateways and bouncers, the WEBIRC command allows gateways to
  413. pass-through the real IP addresses of clients:
  414. ircv3.net/specs/extensions/webirc.html
  415. <flags> is a list of space-separated strings indicating various details about
  416. the connection from the client to the gateway, such as:
  417. - tls: this flag indicates that the client->gateway connection is secure`,
  418. },
  419. "who": {
  420. text: `WHO <name> [o]
  421. Returns information for the given user.`,
  422. },
  423. "whois": {
  424. text: `WHOIS <client>{,<client>}
  425. Returns information for the given user(s).`,
  426. },
  427. "whowas": {
  428. text: `WHOWAS <nickname>
  429. Returns historical information on the last user with the given nickname.`,
  430. },
  431. // Informational
  432. "modes": {
  433. textGenerator: modesTextGenerator,
  434. helpType: InformationHelpEntry,
  435. },
  436. "cmode": {
  437. text: cmodeHelpText,
  438. helpType: InformationHelpEntry,
  439. },
  440. "cmodes": {
  441. text: cmodeHelpText,
  442. helpType: InformationHelpEntry,
  443. duplicate: true,
  444. },
  445. "umode": {
  446. text: umodeHelpText,
  447. helpType: InformationHelpEntry,
  448. },
  449. "umodes": {
  450. text: umodeHelpText,
  451. helpType: InformationHelpEntry,
  452. duplicate: true,
  453. },
  454. "snomask": {
  455. text: snomaskHelpText,
  456. helpType: InformationHelpEntry,
  457. oper: true,
  458. duplicate: true,
  459. },
  460. "snomasks": {
  461. text: snomaskHelpText,
  462. helpType: InformationHelpEntry,
  463. oper: true,
  464. },
  465. // RPL_ISUPPORT
  466. "casemapping": {
  467. text: `RPL_ISUPPORT CASEMAPPING
  468. Oragono supports an experimental unicode casemapping designed for extended
  469. Unicode support. This casemapping is based off RFC 7613 and the draft rfc7613
  470. casemapping spec here: https://oragono.io/specs.html`,
  471. helpType: ISupportHelpEntry,
  472. },
  473. "prefix": {
  474. text: `RPL_ISUPPORT PREFIX
  475. Oragono supports the following channel membership prefixes:
  476. +q (~) | Founder channel mode.
  477. +a (&) | Admin channel mode.
  478. +o (@) | Operator channel mode.
  479. +h (%) | Halfop channel mode.
  480. +v (+) | Voice channel mode.`,
  481. helpType: ISupportHelpEntry,
  482. },
  483. }
  484. // modesTextGenerator generates the text for the 'modes' help entry.
  485. // it exists only so we can translate this entry appropriately.
  486. func modesTextGenerator(client *Client) string {
  487. return client.t(cmodeHelpText) + "\n\n" + client.t(umodeHelpText)
  488. }
  489. type HelpIndexManager struct {
  490. sync.RWMutex // tier 1
  491. langToIndex map[string]string
  492. langToOperIndex map[string]string
  493. }
  494. // GenerateHelpIndex is used to generate HelpIndex.
  495. // Returns: a map from language code to the help index in that language.
  496. func GenerateHelpIndex(lm *languages.Manager, forOpers bool) map[string]string {
  497. // generate the help entry lists
  498. var commands, isupport, information []string
  499. var line string
  500. for name, info := range Help {
  501. if info.duplicate {
  502. continue
  503. }
  504. if info.oper && !forOpers {
  505. continue
  506. }
  507. line = fmt.Sprintf(" %s", name)
  508. if info.helpType == CommandHelpEntry {
  509. commands = append(commands, line)
  510. } else if info.helpType == ISupportHelpEntry {
  511. isupport = append(isupport, line)
  512. } else if info.helpType == InformationHelpEntry {
  513. information = append(information, line)
  514. }
  515. }
  516. // create the strings
  517. sort.Strings(commands)
  518. commandsString := strings.Join(commands, "\n")
  519. sort.Strings(isupport)
  520. isupportString := strings.Join(isupport, "\n")
  521. sort.Strings(information)
  522. informationString := strings.Join(information, "\n")
  523. // sub them in
  524. defaultHelpIndex := `= Help Topics =
  525. Commands:
  526. %[1]s
  527. RPL_ISUPPORT Tokens:
  528. %[2]s
  529. Information:
  530. %[3]s`
  531. newHelpIndex := make(map[string]string)
  532. newHelpIndex["en"] = fmt.Sprintf(defaultHelpIndex, commandsString, isupportString, informationString)
  533. for langCode := range lm.Languages {
  534. translatedHelpIndex := lm.Translate([]string{langCode}, defaultHelpIndex)
  535. if translatedHelpIndex != defaultHelpIndex {
  536. newHelpIndex[langCode] = fmt.Sprintf(translatedHelpIndex, commandsString, isupportString, informationString)
  537. }
  538. }
  539. return newHelpIndex
  540. }
  541. // GenerateIndices regenerates our help indexes for each currently enabled language.
  542. func (hm *HelpIndexManager) GenerateIndices(lm *languages.Manager) {
  543. // generate help indexes
  544. langToIndex := GenerateHelpIndex(lm, false)
  545. langToOperIndex := GenerateHelpIndex(lm, true)
  546. hm.Lock()
  547. defer hm.Unlock()
  548. hm.langToIndex = langToIndex
  549. hm.langToOperIndex = langToOperIndex
  550. }
  551. // sendHelp sends the client help of the given string.
  552. func (client *Client) sendHelp(name string, text string, rb *ResponseBuffer) {
  553. splitName := strings.Split(name, " ")
  554. textLines := strings.Split(text, "\n")
  555. for i, line := range textLines {
  556. args := splitName
  557. args = append(args, line)
  558. if i == 0 {
  559. rb.Add(nil, client.server.name, RPL_HELPSTART, args...)
  560. } else {
  561. rb.Add(nil, client.server.name, RPL_HELPTXT, args...)
  562. }
  563. }
  564. args := splitName
  565. args = append(args, client.t("End of /HELPOP"))
  566. rb.Add(nil, client.server.name, RPL_ENDOFHELP, args...)
  567. }
  568. // GetHelpIndex returns the help index for the given language.
  569. func (hm *HelpIndexManager) GetIndex(languages []string, oper bool) string {
  570. hm.RLock()
  571. langToIndex := hm.langToIndex
  572. if oper {
  573. langToIndex = hm.langToOperIndex
  574. }
  575. hm.RUnlock()
  576. for _, lang := range languages {
  577. index, exists := langToIndex[lang]
  578. if exists {
  579. return index
  580. }
  581. }
  582. // 'en' always exists
  583. return langToIndex["en"]
  584. }
  585. func init() {
  586. // startup check that we have HELP entries for every command
  587. for name := range Commands {
  588. _, exists := Help[strings.ToLower(name)]
  589. if !exists {
  590. panic(fmt.Sprintf("Help entry does not exist for command %s", name))
  591. }
  592. }
  593. }