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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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 the channel messages.
  28. +t | Only channel opers can modify the topic.
  29. +s | Secret mode, channel won't show up in /LIST or whois replies.
  30. = Prefixes =
  31. +q (~) | Founder channel mode.
  32. +a (&) | Admin channel mode.
  33. +o (@) | Operator channel mode.
  34. +h (%) | Halfop channel mode.
  35. +v (+) | Voice channel mode.`
  36. umodeHelpText = `== User Modes ==
  37. Oragono supports the following user modes:
  38. +a | User is marked as being away. This mode is set with the /AWAY command.
  39. +i | User is marked as invisible (their channels are hidden from whois replies).
  40. +o | User is an IRC operator.
  41. +Z | User is connected via TLS.`
  42. )
  43. // Help contains the help strings distributed with the IRCd.
  44. var Help = map[string]HelpEntry{
  45. // Commands
  46. "authenticate": {
  47. text: `AUTHENTICATE
  48. Used during SASL authentication. See the IRCv3 specs for more info:
  49. http://ircv3.net/specs/extensions/sasl-3.1.html`,
  50. },
  51. "away": {
  52. text: `AWAY [message]
  53. If [message] is sent, marks you away. If [message] is not sent, marks you no
  54. longer away.`,
  55. },
  56. "cap": {
  57. text: `CAP <subcommand> [:<capabilities>]
  58. Used in capability negotiation. See the IRCv3 specs for more info:
  59. http://ircv3.net/specs/core/capability-negotiation-3.1.html
  60. http://ircv3.net/specs/core/capability-negotiation-3.2.html`,
  61. },
  62. "debug": {
  63. oper: true,
  64. text: `DEBUG <option>
  65. Prints debug information about the IRCd. <option> can be one of:
  66. * GCSTATS: Garbage control statistics.
  67. * NUMGOROUTINE: Number of goroutines in use.
  68. * STARTCPUPROFILE: Starts the CPU profiler.
  69. * STOPCPUPROFILE: Stops the CPU profiler.
  70. * PROFILEHEAP: Writes out the CPU profiler info.`,
  71. },
  72. "help": {
  73. text: `HELP <argument>
  74. Get an explanation of <argument>.`,
  75. },
  76. "invite": {
  77. text: `INVITE <nickname> <channel>
  78. Invites the given user to the given channel, so long as you have the
  79. appropriate channel privs.`,
  80. },
  81. "ison": {
  82. text: `ISON <nickname>{ <nickname>}
  83. Returns whether the given nicks exist on the network.`,
  84. },
  85. "join": {
  86. text: `JOIN <channel>{,<channel>} [<key>{,<key>}]
  87. JOIN 0
  88. Joins the given channels with the matching keys, or if the only param is "0"
  89. parts all channels instead.`,
  90. },
  91. "kick": {
  92. text: `KICK <channel> <user> [reason]
  93. Removes the user from the given channel, so long as you have the appropriate
  94. channel privs.`,
  95. },
  96. "kill": {
  97. oper: true,
  98. text: `KILL <nickname> [reason]
  99. Removes the given user from the network, showing them the reason if it is
  100. supplied.`,
  101. },
  102. "list": {
  103. text: `LIST [<channel>{,<channel>}] [<elistcond>{,<elistcond>}]
  104. Shows information on the given channels (or if none are given, then on all
  105. channels). <elistcond>s modify how the channels are selected.`,
  106. //TODO(dan): Explain <elistcond>s in more specific detail
  107. },
  108. "mode": {
  109. text: `MODE <target> [<modestring> [<mode arguments>...]]
  110. Sets and removes modes from the given target. For more specific information on
  111. mode characters, see the help for "cmode" and "umode".`,
  112. },
  113. "monitor": {
  114. text: `MONITOR <subcmd>
  115. Allows the monitoring of nicknames, for alerts when they are online and
  116. offline. The subcommands are:
  117. MONITOR + target{,target}
  118. Adds the given names to your list of monitored nicknames.
  119. MONITOR - target{,target}
  120. Removes the given names from your list of monitored nicknames.
  121. MONITOR C
  122. Clears your list of monitored nicknames.
  123. MONITOR L
  124. Lists all the nicknames you are currently monitoring.
  125. MONITOR S
  126. Lists whether each nick in your MONITOR list is online or offline.`,
  127. },
  128. "motd": {
  129. text: `MOTD [server]
  130. Returns the message of the day for this, or the given, server.`,
  131. },
  132. "names": {
  133. text: `NAMES [<channel>{,<channel>}]
  134. Views the clients joined to a channel and their channel membership prefixes. To
  135. view the channel membership prefixes supported by this server, see the help for
  136. "PREFIX".`,
  137. },
  138. "nick": {
  139. text: `NICK <newnick>
  140. Sets your nickname to the new given one.`,
  141. },
  142. "notice": {
  143. text: `NOTICE <target>{,<target>} <text to be sent>
  144. Sends the text to the given targets as a NOTICE.`,
  145. },
  146. "oper": {
  147. text: `OPER <name> <password>
  148. If the correct details are given, gives you IRCop privs.`,
  149. },
  150. "part": {
  151. text: `PART <channel>{,<channel>} [reason]
  152. Leaves the given channels and shows people the given reason.`,
  153. },
  154. "pass": {
  155. text: `PASS <password>
  156. When the server requires a connection password to join, used to send us the
  157. password.`,
  158. },
  159. "ping": {
  160. text: `PING <args>...
  161. Requests a PONG. Used to check link connectivity.`,
  162. },
  163. "pong": {
  164. text: `PONG <args>...
  165. Replies to a PING. Used to check link connectivity.`,
  166. },
  167. "privmsg": {
  168. text: `PRIVMSG <target>{,<target>} <text to be sent>
  169. Sends the text to the given targets as a PRIVMSG.`,
  170. },
  171. "sanick": {
  172. oper: true,
  173. text: `SANICK <currentnick> <newnick>
  174. Gives the given user a new nickname.`,
  175. },
  176. "quit": {
  177. text: `QUIT [reason]
  178. Indicates that you're leaving the server, and shows everyone the given reason.`,
  179. },
  180. "reg": {
  181. text: `REG CREATE <accountname> [callback_namespace:]<callback> [cred_type] :<credential>
  182. REG VERIFY <accountname> <auth_code>
  183. Used in account registration. See the relevant specs for more info:
  184. https://github.com/DanielOaks/ircv3-specifications/blob/register-and-verify/extensions/reg-core-3.3.md`,
  185. },
  186. "rehash": {
  187. oper: true,
  188. text: `REHASH
  189. Reloads the config file and updates TLS certificates on listeners`,
  190. },
  191. "time": {
  192. text: `TIME [server]
  193. Shows the time of the current, or the given, server.`,
  194. },
  195. "topic": {
  196. text: `TOPIC <channel> [topic]
  197. If [topic] is given, sets the topic in the channel to that. If [topic] is not
  198. given, views the current topic on the channel.`,
  199. },
  200. "user": {
  201. text: `USER <username> 0 * <realname>
  202. Used in connection registration, sets your username and realname to the given
  203. values (though your username may also be looked up with Ident).`,
  204. },
  205. "version": {
  206. text: `VERSION [server]
  207. Views the version of software and the RPL_ISUPPORT tokens for the given server.`,
  208. },
  209. "who": {
  210. text: `WHO <name> [o]
  211. Returns information for the given user.`,
  212. },
  213. "whois": {
  214. text: `WHOIS <client>{,<client>}
  215. Returns information for the given user(s).`,
  216. },
  217. "whowas": {
  218. text: `WHOWAS <nickname>
  219. Returns historical information on the last user with the given nickname.`,
  220. },
  221. // Informational
  222. "cmode": {
  223. text: cmodeHelpText,
  224. },
  225. "cmodes": {
  226. text: cmodeHelpText,
  227. },
  228. "umode": {
  229. text: umodeHelpText,
  230. },
  231. "umodes": {
  232. text: umodeHelpText,
  233. },
  234. // RPL_ISUPPORT
  235. "casemapping": {
  236. text: `RPL_ISUPPORT CASEMAPPING
  237. Oragono supports an experimental unicode casemapping designed for extended
  238. Unicode support. This casemapping is based off RFC 7700 and the draft rfc7700
  239. casemapping spec here:
  240. https://github.com/DanielOaks/ircv3-specifications/blob/master%2Brfc7700/documentation/rfc7700.md`,
  241. },
  242. "prefix": {
  243. text: `RPL_ISUPPORT PREFIX
  244. Oragono supports the following channel membership prefixes:
  245. +q (~) | Founder channel mode.
  246. +a (&) | Admin channel mode.
  247. +o (@) | Operator channel mode.
  248. +h (%) | Halfop channel mode.
  249. +v (+) | Voice channel mode.`,
  250. },
  251. }
  252. // sendHelp sends the client help of the given string.
  253. func (client *Client) sendHelp(name string, text string) {
  254. splitName := strings.Split(name, " ")
  255. textLines := strings.Split(text, "\n")
  256. for i, line := range textLines {
  257. args := splitName
  258. args = append(args, line)
  259. if i == 0 {
  260. client.Send(nil, client.server.name, RPL_HELPSTART, args...)
  261. } else {
  262. client.Send(nil, client.server.name, RPL_HELPTXT, args...)
  263. }
  264. }
  265. args := splitName
  266. args = append(args, "End of /HELP")
  267. client.Send(nil, client.server.name, RPL_ENDOFHELP, args...)
  268. }
  269. // helpHandler returns the appropriate help for the given query.
  270. func helpHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
  271. argument := strings.ToLower(strings.TrimSpace(strings.Join(msg.Params, " ")))
  272. if len(argument) < 1 {
  273. client.sendHelp("HELP", `HELP <argument>
  274. Get an explanation of <argument>.`)
  275. return false
  276. }
  277. helpHandler, exists := Help[argument]
  278. if exists && (!helpHandler.oper || (helpHandler.oper && client.flags[Operator])) {
  279. client.sendHelp(strings.ToUpper(argument), helpHandler.text)
  280. } else {
  281. args := msg.Params
  282. args = append(args, "Help not found")
  283. client.Send(nil, server.name, ERR_HELPNOTFOUND, args...)
  284. }
  285. return false
  286. }