選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

help.go 20KB

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