123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- // Copyright (c) 2016- Daniel Oaks <daniel@danieloaks.net>
- // released under the MIT license
-
- package irc
-
- import (
- "strings"
-
- "github.com/DanielOaks/girc-go/ircmsg"
- )
-
- // HelpEntry represents an entry in the Help map.
- type HelpEntry struct {
- oper bool
- text string
- }
-
- // used for duplicates
- var (
- cmodeHelpText = `== Channel Modes ==
-
- Oragono supports the following channel modes:
-
- = Type A - list modes =
-
- +b | Client masks that are banned from the channel.
- +e | Client masks that are exempted from bans.
- +I | Client masks that are exempted from the invite-only flag.
-
- = Type C - setting modes with a parameter =
-
- +l | Client join limit for the channel.
- +k | Key required when joining the channel.
-
- = Type D - flag modes =
-
- +i | Invite-only mode, only invited clients can join the channel.
- +m | Moderated mode, only privileged clients can talk on the channel.
- +n | No-outside-messages mode, only users that are on the channel can send the channel messages.
- +t | Only channel opers can modify the topic.
- +s | Secret mode, channel won't show up in /LIST or whois replies.
-
- = Prefixes =
-
- +q (~) | Founder channel mode.
- +a (&) | Admin channel mode.
- +o (@) | Operator channel mode.
- +h (%) | Halfop channel mode.
- +v (+) | Voice channel mode.`
- umodeHelpText = `== User Modes ==
-
- Oragono supports the following user modes:
-
- +a | User is marked as being away. This mode is set with the /AWAY command.
- +i | User is marked as invisible (their channels are hidden from whois replies).
- +o | User is an IRC operator.
- +Z | User is connected via TLS.`
- )
-
- // Help contains the help strings distributed with the IRCd.
- var Help = map[string]HelpEntry{
- // Commands
- "ambiance": {
- text: `AMBIANCE <target> <text to be sent>
-
- The AMBIANCE command is used to send a scene notification to the given target.`,
- },
- "authenticate": {
- text: `AUTHENTICATE
-
- Used during SASL authentication. See the IRCv3 specs for more info:
- http://ircv3.net/specs/extensions/sasl-3.1.html`,
- },
- "away": {
- text: `AWAY [message]
-
- If [message] is sent, marks you away. If [message] is not sent, marks you no
- longer away.`,
- },
- "cap": {
- text: `CAP <subcommand> [:<capabilities>]
-
- Used in capability negotiation. See the IRCv3 specs for more info:
- http://ircv3.net/specs/core/capability-negotiation-3.1.html
- http://ircv3.net/specs/core/capability-negotiation-3.2.html`,
- },
- "debug": {
- oper: true,
- text: `DEBUG <option>
-
- Prints debug information about the IRCd. <option> can be one of:
-
- * GCSTATS: Garbage control statistics.
- * NUMGOROUTINE: Number of goroutines in use.
- * STARTCPUPROFILE: Starts the CPU profiler.
- * STOPCPUPROFILE: Stops the CPU profiler.
- * PROFILEHEAP: Writes out the CPU profiler info.`,
- },
- "help": {
- text: `HELP <argument>
-
- Get an explanation of <argument>.`,
- },
- "invite": {
- text: `INVITE <nickname> <channel>
-
- Invites the given user to the given channel, so long as you have the
- appropriate channel privs.`,
- },
- "ison": {
- text: `ISON <nickname>{ <nickname>}
-
- Returns whether the given nicks exist on the network.`,
- },
- "join": {
- text: `JOIN <channel>{,<channel>} [<key>{,<key>}]
- JOIN 0
-
- Joins the given channels with the matching keys, or if the only param is "0"
- parts all channels instead.`,
- },
- "kick": {
- text: `KICK <channel> <user> [reason]
-
- Removes the user from the given channel, so long as you have the appropriate
- channel privs.`,
- },
- "kill": {
- oper: true,
- text: `KILL <nickname> [reason]
-
- Removes the given user from the network, showing them the reason if it is
- supplied.`,
- },
- "list": {
- text: `LIST [<channel>{,<channel>}] [<elistcond>{,<elistcond>}]
-
- Shows information on the given channels (or if none are given, then on all
- channels). <elistcond>s modify how the channels are selected.`,
- //TODO(dan): Explain <elistcond>s in more specific detail
- },
- "mode": {
- text: `MODE <target> [<modestring> [<mode arguments>...]]
-
- Sets and removes modes from the given target. For more specific information on
- mode characters, see the help for "cmode" and "umode".`,
- },
- "monitor": {
- text: `MONITOR <subcmd>
-
- Allows the monitoring of nicknames, for alerts when they are online and
- offline. The subcommands are:
-
- MONITOR + target{,target}
- Adds the given names to your list of monitored nicknames.
-
- MONITOR - target{,target}
- Removes the given names from your list of monitored nicknames.
-
- MONITOR C
- Clears your list of monitored nicknames.
-
- MONITOR L
- Lists all the nicknames you are currently monitoring.
-
- MONITOR S
- Lists whether each nick in your MONITOR list is online or offline.`,
- },
- "motd": {
- text: `MOTD [server]
-
- Returns the message of the day for this, or the given, server.`,
- },
- "names": {
- text: `NAMES [<channel>{,<channel>}]
-
- Views the clients joined to a channel and their channel membership prefixes. To
- view the channel membership prefixes supported by this server, see the help for
- "PREFIX".`,
- },
- "nick": {
- text: `NICK <newnick>
-
- Sets your nickname to the new given one.`,
- },
- "notice": {
- text: `NOTICE <target>{,<target>} <text to be sent>
-
- Sends the text to the given targets as a NOTICE.`,
- },
- "npc": {
- text: `NPC <target> <sourcenick> <text to be sent>
-
- The NPC command is used to send a message to the target as the source.`,
- },
- "npca": {
- text: `NPCA <target> <sourcenick> <text to be sent>
-
- The NPC command is used to send an action to the target as the source.`,
- },
- "oper": {
- text: `OPER <name> <password>
-
- If the correct details are given, gives you IRCop privs.`,
- },
- "part": {
- text: `PART <channel>{,<channel>} [reason]
-
- Leaves the given channels and shows people the given reason.`,
- },
- "pass": {
- text: `PASS <password>
-
- When the server requires a connection password to join, used to send us the
- password.`,
- },
- "ping": {
- text: `PING <args>...
-
- Requests a PONG. Used to check link connectivity.`,
- },
- "pong": {
- text: `PONG <args>...
-
- Replies to a PING. Used to check link connectivity.`,
- },
- "privmsg": {
- text: `PRIVMSG <target>{,<target>} <text to be sent>
-
- Sends the text to the given targets as a PRIVMSG.`,
- },
- "sanick": {
- oper: true,
- text: `SANICK <currentnick> <newnick>
-
- Gives the given user a new nickname.`,
- },
- "scene": {
- text: `SCENE <target> <text to be sent>
-
- The SCENE command is used to send a scene notification to the given target.`,
- },
- "quit": {
- text: `QUIT [reason]
-
- Indicates that you're leaving the server, and shows everyone the given reason.`,
- },
- "reg": {
- text: `REG CREATE <accountname> [callback_namespace:]<callback> [cred_type] :<credential>
- REG VERIFY <accountname> <auth_code>
-
- Used in account registration. See the relevant specs for more info:
- https://github.com/DanielOaks/ircv3-specifications/blob/register-and-verify/extensions/reg-core-3.3.md`,
- },
- "rehash": {
- oper: true,
- text: `REHASH
-
- Reloads the config file and updates TLS certificates on listeners`,
- },
- "time": {
- text: `TIME [server]
-
- Shows the time of the current, or the given, server.`,
- },
- "topic": {
- text: `TOPIC <channel> [topic]
-
- If [topic] is given, sets the topic in the channel to that. If [topic] is not
- given, views the current topic on the channel.`,
- },
- "user": {
- text: `USER <username> 0 * <realname>
-
- Used in connection registration, sets your username and realname to the given
- values (though your username may also be looked up with Ident).`,
- },
- "version": {
- text: `VERSION [server]
-
- Views the version of software and the RPL_ISUPPORT tokens for the given server.`,
- },
- "who": {
- text: `WHO <name> [o]
-
- Returns information for the given user.`,
- },
- "whois": {
- text: `WHOIS <client>{,<client>}
-
- Returns information for the given user(s).`,
- },
- "whowas": {
- text: `WHOWAS <nickname>
-
- Returns historical information on the last user with the given nickname.`,
- },
-
- // Informational
- "cmode": {
- text: cmodeHelpText,
- },
- "cmodes": {
- text: cmodeHelpText,
- },
- "umode": {
- text: umodeHelpText,
- },
- "umodes": {
- text: umodeHelpText,
- },
-
- // RPL_ISUPPORT
- "casemapping": {
- text: `RPL_ISUPPORT CASEMAPPING
-
- Oragono supports an experimental unicode casemapping designed for extended
- Unicode support. This casemapping is based off RFC 7700 and the draft rfc7700
- casemapping spec here:
- https://github.com/DanielOaks/ircv3-specifications/blob/master%2Brfc7700/documentation/rfc7700.md`,
- },
- "prefix": {
- text: `RPL_ISUPPORT PREFIX
-
- Oragono supports the following channel membership prefixes:
-
- +q (~) | Founder channel mode.
- +a (&) | Admin channel mode.
- +o (@) | Operator channel mode.
- +h (%) | Halfop channel mode.
- +v (+) | Voice channel mode.`,
- },
- }
-
- // sendHelp sends the client help of the given string.
- func (client *Client) sendHelp(name string, text string) {
- splitName := strings.Split(name, " ")
- textLines := strings.Split(text, "\n")
-
- for i, line := range textLines {
- args := splitName
- args = append(args, line)
- if i == 0 {
- client.Send(nil, client.server.name, RPL_HELPSTART, args...)
- } else {
- client.Send(nil, client.server.name, RPL_HELPTXT, args...)
- }
- }
- args := splitName
- args = append(args, "End of /HELP")
- client.Send(nil, client.server.name, RPL_ENDOFHELP, args...)
- }
-
- // helpHandler returns the appropriate help for the given query.
- func helpHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
- argument := strings.ToLower(strings.TrimSpace(strings.Join(msg.Params, " ")))
-
- if len(argument) < 1 {
- client.sendHelp("HELP", `HELP <argument>
-
- Get an explanation of <argument>.`)
- return false
- }
-
- helpHandler, exists := Help[argument]
-
- if exists && (!helpHandler.oper || (helpHandler.oper && client.flags[Operator])) {
- client.sendHelp(strings.ToUpper(argument), helpHandler.text)
- } else {
- args := msg.Params
- args = append(args, "Help not found")
- client.Send(nil, server.name, ERR_HELPNOTFOUND, args...)
- }
-
- return false
- }
|