Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

help.go 9.6KB

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