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

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