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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
  2. // released under the MIT license
  3. package irc
  4. import (
  5. "strings"
  6. "github.com/DanielOaks/girc-go/ircmsg"
  7. )
  8. // HelpEntry represents an entry in the Help map.
  9. type HelpEntry struct {
  10. oper bool
  11. text string
  12. }
  13. // used for duplicates
  14. var (
  15. cmodeHelpText = `== Channel Modes ==
  16. Oragono supports the following channel modes:
  17. +b | Client masks that are banned from the channel (e.g. *!*@127.0.0.1)
  18. +e | Client masks that are exempted from bans.
  19. +I | Client masks that are exempted from the invite-only flag.
  20. +i | Invite-only mode, only invited clients can join the channel.
  21. +k | Key required when joining the channel.
  22. +l | Client join limit for the channel.
  23. +m | Moderated mode, only privileged clients can talk on the channel.
  24. +n | No-outside-messages mode, only users that are on the channel can send
  25. | messages to it.
  26. +r | Only registered users can talk in the channel.
  27. +s | Secret mode, channel won't show up in /LIST or whois replies.
  28. +t | Only channel opers can modify the topic.
  29. = Prefixes =
  30. +q (~) | Founder channel mode.
  31. +a (&) | Admin channel mode.
  32. +o (@) | Operator channel mode.
  33. +h (%) | Halfop channel mode.
  34. +v (+) | Voice channel mode.`
  35. umodeHelpText = `== User Modes ==
  36. Oragono supports the following user modes:
  37. +a | User is marked as being away. This mode is set with the /AWAY command.
  38. +i | User is marked as invisible (their channels are hidden from whois replies).
  39. +o | User is an IRC operator.
  40. +Z | User is connected via TLS.`
  41. )
  42. // Help contains the help strings distributed with the IRCd.
  43. var Help = map[string]HelpEntry{
  44. // Commands
  45. "ambiance": {
  46. text: `AMBIANCE <target> <text to be sent>
  47. The AMBIANCE command is used to send a scene notification to the given target.`,
  48. },
  49. "authenticate": {
  50. text: `AUTHENTICATE
  51. Used during SASL authentication. See the IRCv3 specs for more info:
  52. http://ircv3.net/specs/extensions/sasl-3.1.html`,
  53. },
  54. "away": {
  55. text: `AWAY [message]
  56. If [message] is sent, marks you away. If [message] is not sent, marks you no
  57. longer away.`,
  58. },
  59. "cap": {
  60. text: `CAP <subcommand> [:<capabilities>]
  61. Used in capability negotiation. See the IRCv3 specs for more info:
  62. http://ircv3.net/specs/core/capability-negotiation-3.1.html
  63. http://ircv3.net/specs/core/capability-negotiation-3.2.html`,
  64. },
  65. "chanserv": {
  66. text: `CHANSERV <subcommand> [params]
  67. ChanServ controls channel registrations.`,
  68. },
  69. "cs": {
  70. text: `CS <subcommand> [params]
  71. ChanServ controls channel registrations.`,
  72. },
  73. "debug": {
  74. oper: true,
  75. text: `DEBUG <option>
  76. Prints debug information about the IRCd. <option> can be one of:
  77. * GCSTATS: Garbage control statistics.
  78. * NUMGOROUTINE: Number of goroutines in use.
  79. * STARTCPUPROFILE: Starts the CPU profiler.
  80. * STOPCPUPROFILE: Stops the CPU profiler.
  81. * PROFILEHEAP: Writes out the CPU profiler info.`,
  82. },
  83. "dline": {
  84. oper: true,
  85. text: `DLINE [MYSELF] [duration] <ip>/<net> [ON <server>] [reason [| oper reason]]
  86. Bans an IP address or network from connecting to the server. If the duration is
  87. given then only for that long. The reason is shown to the user themselves, but
  88. everyone else will see a standard message. The oper reason is shown to
  89. operators getting info about the DLINEs that exist.
  90. Bans are saved across subsequent launches of the server.
  91. "MYSELF" is required when the DLINE matches the address the person applying it is connected
  92. from. If "MYSELF" is not given, trying to DLINE yourself will result in an error.
  93. [duration] can be of the following forms:
  94. 1y 12mo 31d 10h 8m 13s
  95. <net> is specified in typical CIDR notation. For example:
  96. 127.0.0.1/8
  97. 8.8.8.8/24
  98. ON <server> specifies that the ban is to be set on that specific server.
  99. [reason] and [oper reason], if they exist, are separated by a vertical bar (|).`,
  100. },
  101. "help": {
  102. text: `HELP <argument>
  103. Get an explanation of <argument>.`,
  104. },
  105. "invite": {
  106. text: `INVITE <nickname> <channel>
  107. Invites the given user to the given channel, so long as you have the
  108. appropriate channel privs.`,
  109. },
  110. "ison": {
  111. text: `ISON <nickname>{ <nickname>}
  112. Returns whether the given nicks exist on the network.`,
  113. },
  114. "join": {
  115. text: `JOIN <channel>{,<channel>} [<key>{,<key>}]
  116. JOIN 0
  117. Joins the given channels with the matching keys, or if the only param is "0"
  118. parts all channels instead.`,
  119. },
  120. "kick": {
  121. text: `KICK <channel> <user> [reason]
  122. Removes the user from the given channel, so long as you have the appropriate
  123. channel privs.`,
  124. },
  125. "kill": {
  126. oper: true,
  127. text: `KILL <nickname> [reason]
  128. Removes the given user from the network, showing them the reason if it is
  129. supplied.`,
  130. },
  131. "kline": {
  132. oper: true,
  133. text: `KLINE [MYSELF] [duration] <mask> [ON <server>] [reason [| oper reason]]
  134. Bans a mask from connecting to the server. If the duration is given then only for that
  135. long. The reason is shown to the user themselves, but everyone else will see a standard
  136. message. The oper reason is shown to operators getting info about the KLINEs that exist.
  137. Bans are saved across subsequent launches of the server.
  138. "MYSELF" is required when the KLINE matches the address the person applying it is connected
  139. from. If "MYSELF" is not given, trying to KLINE yourself will result in an error.
  140. [duration] can be of the following forms:
  141. 1y 12mo 31d 10h 8m 13s
  142. <mask> is specified in typical IRC format. For example:
  143. dan
  144. dan!5*@127.*
  145. ON <server> specifies that the ban is to be set on that specific server.
  146. [reason] and [oper reason], if they exist, are separated by a vertical bar (|).`,
  147. },
  148. "list": {
  149. text: `LIST [<channel>{,<channel>}] [<elistcond>{,<elistcond>}]
  150. Shows information on the given channels (or if none are given, then on all
  151. channels). <elistcond>s modify how the channels are selected.`,
  152. //TODO(dan): Explain <elistcond>s in more specific detail
  153. },
  154. "lusers": {
  155. text: `LUSERS [<mask> [<server>]]
  156. Shows statistics about the size of the network. If <mask> is given, only
  157. returns stats for servers matching the given mask. If <server> is given, the
  158. command is processed by that server.`,
  159. },
  160. "mode": {
  161. text: `MODE <target> [<modestring> [<mode arguments>...]]
  162. Sets and removes modes from the given target. For more specific information on
  163. mode characters, see the help for "modes".`,
  164. },
  165. "monitor": {
  166. text: `MONITOR <subcmd>
  167. Allows the monitoring of nicknames, for alerts when they are online and
  168. offline. The subcommands are:
  169. MONITOR + target{,target}
  170. Adds the given names to your list of monitored nicknames.
  171. MONITOR - target{,target}
  172. Removes the given names from your list of monitored nicknames.
  173. MONITOR C
  174. Clears your list of monitored nicknames.
  175. MONITOR L
  176. Lists all the nicknames you are currently monitoring.
  177. MONITOR S
  178. Lists whether each nick in your MONITOR list is online or offline.`,
  179. },
  180. "motd": {
  181. text: `MOTD [server]
  182. Returns the message of the day for this, or the given, server.`,
  183. },
  184. "names": {
  185. text: `NAMES [<channel>{,<channel>}]
  186. Views the clients joined to a channel and their channel membership prefixes. To
  187. view the channel membership prefixes supported by this server, see the help for
  188. "PREFIX".`,
  189. },
  190. "nick": {
  191. text: `NICK <newnick>
  192. Sets your nickname to the new given one.`,
  193. },
  194. "nickserv": {
  195. text: `NICKSERV <subcommand> [params]
  196. NickServ controls accounts and user registrations.`,
  197. },
  198. "notice": {
  199. text: `NOTICE <target>{,<target>} <text to be sent>
  200. Sends the text to the given targets as a NOTICE.`,
  201. },
  202. "npc": {
  203. text: `NPC <target> <sourcenick> <text to be sent>
  204. The NPC command is used to send a message to the target as the source.
  205. Requires the roleplay mode (+E) to be set on the target.`,
  206. },
  207. "npca": {
  208. text: `NPCA <target> <sourcenick> <text to be sent>
  209. The NPC command is used to send an action to the target as the source.
  210. Requires the roleplay mode (+E) to be set on the target.`,
  211. },
  212. "ns": {
  213. text: `NS <subcommand> [params]
  214. NickServ controls accounts and user registrations.`,
  215. },
  216. "oper": {
  217. text: `OPER <name> <password>
  218. If the correct details are given, gives you IRCop privs.`,
  219. },
  220. "part": {
  221. text: `PART <channel>{,<channel>} [reason]
  222. Leaves the given channels and shows people the given reason.`,
  223. },
  224. "pass": {
  225. text: `PASS <password>
  226. When the server requires a connection password to join, used to send us the
  227. password.`,
  228. },
  229. "ping": {
  230. text: `PING <args>...
  231. Requests a PONG. Used to check link connectivity.`,
  232. },
  233. "pong": {
  234. text: `PONG <args>...
  235. Replies to a PING. Used to check link connectivity.`,
  236. },
  237. "privmsg": {
  238. text: `PRIVMSG <target>{,<target>} <text to be sent>
  239. Sends the text to the given targets as a PRIVMSG.`,
  240. },
  241. "sanick": {
  242. oper: true,
  243. text: `SANICK <currentnick> <newnick>
  244. Gives the given user a new nickname.`,
  245. },
  246. "samode": {
  247. oper: true,
  248. text: `SAMODE <target> [<modestring> [<mode arguments>...]]
  249. Forcibly sets and removes modes from the given target -- only available to
  250. opers. For more specific information on mode characters, see the help for
  251. "cmode" and "umode".`,
  252. },
  253. "scene": {
  254. text: `SCENE <target> <text to be sent>
  255. The SCENE command is used to send a scene notification to the given target.`,
  256. },
  257. "tagmsg": {
  258. text: `@+client-only-tags TAGMSG <target>{,<target>}
  259. Sends the given client-only tags to the given targets as a TAGMSG. See the IRCv3
  260. specs for more info: http://ircv3.net/specs/core/message-tags-3.3.html`,
  261. },
  262. "quit": {
  263. text: `QUIT [reason]
  264. Indicates that you're leaving the server, and shows everyone the given reason.`,
  265. },
  266. "reg": {
  267. text: `REG CREATE <accountname> [callback_namespace:]<callback> [cred_type] :<credential>
  268. REG VERIFY <accountname> <auth_code>
  269. Used in account registration. See the relevant specs for more info:
  270. http://oragono.io/specs.html`,
  271. },
  272. "rehash": {
  273. oper: true,
  274. text: `REHASH
  275. Reloads the config file and updates TLS certificates on listeners`,
  276. },
  277. "time": {
  278. text: `TIME [server]
  279. Shows the time of the current, or the given, server.`,
  280. },
  281. "topic": {
  282. text: `TOPIC <channel> [topic]
  283. If [topic] is given, sets the topic in the channel to that. If [topic] is not
  284. given, views the current topic on the channel.`,
  285. },
  286. "undline": {
  287. oper: true,
  288. text: `UNDLINE <ip>/<net>
  289. Removes an existing ban on an IP address or a network.
  290. <net> is specified in typical CIDR notation. For example:
  291. 127.0.0.1/8
  292. 8.8.8.8/24`,
  293. },
  294. "unkline": {
  295. oper: true,
  296. text: `UNKLINE <mask>
  297. Removes an existing ban on a mask.
  298. For example:
  299. dan
  300. dan!5*@127.*`,
  301. },
  302. "user": {
  303. text: `USER <username> 0 * <realname>
  304. Used in connection registration, sets your username and realname to the given
  305. values (though your username may also be looked up with Ident).`,
  306. },
  307. "userhost": {
  308. text: `USERHOST <nickname>{ <nickname>}
  309. Shows information about the given users. Takes up to 10 nicknames.`,
  310. },
  311. "version": {
  312. text: `VERSION [server]
  313. Views the version of software and the RPL_ISUPPORT tokens for the given server.`,
  314. },
  315. "who": {
  316. text: `WHO <name> [o]
  317. Returns information for the given user.`,
  318. },
  319. "whois": {
  320. text: `WHOIS <client>{,<client>}
  321. Returns information for the given user(s).`,
  322. },
  323. "whowas": {
  324. text: `WHOWAS <nickname>
  325. Returns historical information on the last user with the given nickname.`,
  326. },
  327. // Informational
  328. "modes": {
  329. text: cmodeHelpText + "\n\n" + umodeHelpText,
  330. },
  331. "cmode": {
  332. text: cmodeHelpText,
  333. },
  334. "cmodes": {
  335. text: cmodeHelpText,
  336. },
  337. "umode": {
  338. text: umodeHelpText,
  339. },
  340. "umodes": {
  341. text: umodeHelpText,
  342. },
  343. // RPL_ISUPPORT
  344. "casemapping": {
  345. text: `RPL_ISUPPORT CASEMAPPING
  346. Oragono supports an experimental unicode casemapping designed for extended
  347. Unicode support. This casemapping is based off RFC 7613 and the draft rfc7613
  348. casemapping spec here: http://oragono.io/specs.html`,
  349. },
  350. "prefix": {
  351. text: `RPL_ISUPPORT PREFIX
  352. Oragono supports the following channel membership prefixes:
  353. +q (~) | Founder channel mode.
  354. +a (&) | Admin channel mode.
  355. +o (@) | Operator channel mode.
  356. +h (%) | Halfop channel mode.
  357. +v (+) | Voice channel mode.`,
  358. },
  359. }
  360. // sendHelp sends the client help of the given string.
  361. func (client *Client) sendHelp(name string, text string) {
  362. splitName := strings.Split(name, " ")
  363. textLines := strings.Split(text, "\n")
  364. for i, line := range textLines {
  365. args := splitName
  366. args = append(args, line)
  367. if i == 0 {
  368. client.Send(nil, client.server.name, RPL_HELPSTART, args...)
  369. } else {
  370. client.Send(nil, client.server.name, RPL_HELPTXT, args...)
  371. }
  372. }
  373. args := splitName
  374. args = append(args, "End of /HELP")
  375. client.Send(nil, client.server.name, RPL_ENDOFHELP, args...)
  376. }
  377. // helpHandler returns the appropriate help for the given query.
  378. func helpHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
  379. argument := strings.ToLower(strings.TrimSpace(strings.Join(msg.Params, " ")))
  380. if len(argument) < 1 {
  381. client.sendHelp("HELP", `HELP <argument>
  382. Get an explanation of <argument>.`)
  383. return false
  384. }
  385. helpHandler, exists := Help[argument]
  386. if exists && (!helpHandler.oper || (helpHandler.oper && client.flags[Operator])) {
  387. client.sendHelp(strings.ToUpper(argument), helpHandler.text)
  388. } else {
  389. args := msg.Params
  390. args = append(args, "Help not found")
  391. client.Send(nil, server.name, ERR_HELPNOTFOUND, args...)
  392. }
  393. return false
  394. }