3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

Merge pull request #588 from slingamn/servicehelp.5

refactor /HELP for services
This commit is contained in:
Daniel Oaks 2019-07-12 23:30:50 +10:00 committed by GitHub
commit 23974af345
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 61 deletions

View File

@ -17,13 +17,7 @@ import (
"github.com/oragono/oragono/irc/sno" "github.com/oragono/oragono/irc/sno"
) )
const chanservHelp = `ChanServ lets you register and manage channels. const chanservHelp = `ChanServ lets you register and manage channels.`
To see in-depth help for a specific ChanServ command, try:
$b/CS HELP <command>$b
Here are the commands you can use:
%s`
func chanregEnabled(config *Config) bool { func chanregEnabled(config *Config) bool {
return config.Channels.Registration.Enabled return config.Channels.Registration.Enabled

View File

@ -1091,7 +1091,7 @@ Get an explanation of <argument>, or "index" for a list of help topics.`), rb)
if exists && (!helpHandler.oper || (helpHandler.oper && client.HasMode(modes.Operator))) { if exists && (!helpHandler.oper || (helpHandler.oper && client.HasMode(modes.Operator))) {
if helpHandler.textGenerator != nil { if helpHandler.textGenerator != nil {
client.sendHelp(strings.ToUpper(argument), client.t(helpHandler.textGenerator(client)), rb) client.sendHelp(strings.ToUpper(argument), helpHandler.textGenerator(client), rb)
} else { } else {
client.sendHelp(strings.ToUpper(argument), client.t(helpHandler.text), rb) client.sendHelp(strings.ToUpper(argument), client.t(helpHandler.text), rb)
} }

View File

@ -135,11 +135,6 @@ message (and as your quit message if you don't return in time).`,
Used in capability negotiation. See the IRCv3 specs for more info: 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.1.html
http://ircv3.net/specs/core/capability-negotiation-3.2.html`, http://ircv3.net/specs/core/capability-negotiation-3.2.html`,
},
"chanserv": {
text: `CHANSERV <subcommand> [params]
ChanServ controls channel registrations.`,
}, },
"chathistory": { "chathistory": {
text: `CHATHISTORY [params] text: `CHATHISTORY [params]
@ -147,11 +142,6 @@ ChanServ controls channel registrations.`,
CHATHISTORY is an experimental history replay command. See these documents: CHATHISTORY is an experimental history replay command. See these documents:
https://github.com/MuffinMedic/ircv3-specifications/blob/chathistory/extensions/chathistory.md https://github.com/MuffinMedic/ircv3-specifications/blob/chathistory/extensions/chathistory.md
https://gist.github.com/DanielOaks/c104ad6e8759c01eb5c826d627caf80d`, https://gist.github.com/DanielOaks/c104ad6e8759c01eb5c826d627caf80d`,
},
"cs": {
text: `CS <subcommand> [params]
ChanServ controls channel registrations.`,
}, },
"debug": { "debug": {
oper: true, oper: true,
@ -212,18 +202,6 @@ Replay message history. <target> can be a channel name, "me" to replay direct
message history, or a nickname to replay another client's direct message message history, or a nickname to replay another client's direct message
history (they must be logged into the same account as you). At most [limit] history (they must be logged into the same account as you). At most [limit]
messages will be replayed.`, messages will be replayed.`,
},
"hostserv": {
text: `HOSTSERV <command> [params]
HostServ lets you manage your vhost (a string displayed in place of your
real hostname).`,
},
"hs": {
text: `HS <command> [params]
HostServ lets you manage your vhost (a string displayed in place of your
real hostname).`,
}, },
"info": { "info": {
text: `INFO text: `INFO
@ -350,11 +328,6 @@ view the channel membership prefixes supported by this server, see the help for
text: `NICK <newnick> text: `NICK <newnick>
Sets your nickname to the new given one.`, Sets your nickname to the new given one.`,
},
"nickserv": {
text: `NICKSERV <subcommand> [params]
NickServ controls accounts and user registrations.`,
}, },
"notice": { "notice": {
text: `NOTICE <target>{,<target>} <text to be sent> text: `NOTICE <target>{,<target>} <text to be sent>
@ -374,11 +347,6 @@ Requires the roleplay mode (+E) to be set on the target.`,
The NPC command is used to send an action to the target as the source. The NPC command is used to send an action to the target as the source.
Requires the roleplay mode (+E) to be set on the target.`, Requires the roleplay mode (+E) to be set on the target.`,
},
"ns": {
text: `NS <subcommand> [params]
NickServ controls accounts and user registrations.`,
}, },
"oper": { "oper": {
text: `OPER <name> <password> text: `OPER <name> <password>

View File

@ -11,13 +11,7 @@ import (
) )
const hostservHelp = `HostServ lets you manage your vhost (i.e., the string displayed const hostservHelp = `HostServ lets you manage your vhost (i.e., the string displayed
in place of your client's hostname/IP). in place of your client's hostname/IP).`
To see in-depth help for a specific HostServ command, try:
$b/HS HELP <command>$b
Here are the commands you can use:
%s`
var ( var (
errVHostBadCharacters = errors.New("Vhost contains prohibited characters") errVHostBadCharacters = errors.New("Vhost contains prohibited characters")

View File

@ -41,13 +41,7 @@ const (
nsTimeoutNotice = `This nickname is reserved. Please login within %v (using $b/msg NickServ IDENTIFY <password>$b or SASL), or switch to a different nickname.` nsTimeoutNotice = `This nickname is reserved. Please login within %v (using $b/msg NickServ IDENTIFY <password>$b or SASL), or switch to a different nickname.`
) )
const nickservHelp = `NickServ lets you register and login to an account. const nickservHelp = `NickServ lets you register and log into an account.`
To see in-depth help for a specific NickServ command, try:
$b/NS HELP <command>$b
Here are the commands you can use:
%s`
var ( var (
nickservCommands = map[string]*serviceCommand{ nickservCommands = map[string]*serviceCommand{

View File

@ -4,6 +4,7 @@
package irc package irc
import ( import (
"bytes"
"fmt" "fmt"
"log" "log"
"sort" "sort"
@ -190,6 +191,14 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
sendNotice(ircfmt.Unescape(fmt.Sprintf("*** $b%s HELP$b ***", service.Name))) sendNotice(ircfmt.Unescape(fmt.Sprintf("*** $b%s HELP$b ***", service.Name)))
if len(params) == 0 { if len(params) == 0 {
helpBannerLines := strings.Split(client.t(service.HelpBanner), "\n")
helpBannerLines = append(helpBannerLines, []string{
"",
client.t("To see in-depth help for a specific command, try:"),
ircfmt.Unescape(fmt.Sprintf(client.t(" $b/msg %s HELP <command>$b"), service.Name)),
"",
client.t("Here are the commands you can use:"),
}...)
// show general help // show general help
var shownHelpLines sort.StringSlice var shownHelpLines sort.StringSlice
var disabledCommands bool var disabledCommands bool
@ -206,7 +215,7 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
continue continue
} }
shownHelpLines = append(shownHelpLines, " "+client.t(commandInfo.helpShort)) shownHelpLines = append(shownHelpLines, ircfmt.Unescape(" "+client.t(commandInfo.helpShort)))
} }
if disabledCommands { if disabledCommands {
@ -216,12 +225,11 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
// sort help lines // sort help lines
sort.Sort(shownHelpLines) sort.Sort(shownHelpLines)
// assemble help text
assembledHelpLines := strings.Join(shownHelpLines, "\n")
fullHelp := ircfmt.Unescape(fmt.Sprintf(client.t(service.HelpBanner), assembledHelpLines))
// push out help text // push out help text
for _, line := range strings.Split(fullHelp, "\n") { for _, line := range helpBannerLines {
sendNotice(line)
}
for _, line := range shownHelpLines {
sendNotice(line) sendNotice(line)
} }
} else { } else {
@ -249,6 +257,18 @@ func serviceHelpHandler(service *ircService, server *Server, client *Client, par
sendNotice(ircfmt.Unescape(fmt.Sprintf(client.t("*** $bEnd of %s HELP$b ***"), service.Name))) sendNotice(ircfmt.Unescape(fmt.Sprintf(client.t("*** $bEnd of %s HELP$b ***"), service.Name)))
} }
func makeServiceHelpTextGenerator(cmd string, banner string) func(*Client) string {
return func(client *Client) string {
var buf bytes.Buffer
fmt.Fprintf(&buf, client.t("%s <subcommand> [params]"), cmd)
buf.WriteRune('\n')
buf.WriteString(client.t(banner)) // may contain newlines, that's fine
buf.WriteRune('\n')
fmt.Fprintf(&buf, client.t("For more details, try /%s HELP"), cmd)
return buf.String()
}
}
func initializeServices() { func initializeServices() {
// this modifies the global Commands map, // this modifies the global Commands map,
// so it must be called from irc/commands.go's init() // so it must be called from irc/commands.go's init()
@ -263,12 +283,16 @@ func initializeServices() {
// reserve the nickname // reserve the nickname
restrictedNicknames = append(restrictedNicknames, service.Name) restrictedNicknames = append(restrictedNicknames, service.Name)
// register the protocol-level commands (NICKSERV, NS) that talk to the service // register the protocol-level commands (NICKSERV, NS) that talk to the service,
// and their associated help entries
var ircCmdDef Command var ircCmdDef Command
ircCmdDef.handler = serviceCmdHandler ircCmdDef.handler = serviceCmdHandler
for _, ircCmd := range service.CommandAliases { for _, ircCmd := range service.CommandAliases {
Commands[ircCmd] = ircCmdDef Commands[ircCmd] = ircCmdDef
oragonoServicesByCommandAlias[ircCmd] = service oragonoServicesByCommandAlias[ircCmd] = service
Help[strings.ToLower(ircCmd)] = HelpEntry{
textGenerator: makeServiceHelpTextGenerator(ircCmd, service.HelpBanner),
}
} }
// force devs to write a help entry for every command // force devs to write a help entry for every command