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

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