diff options
author | Hubert Hirtz <hubert@hirtz.pm> | 2021-05-18 12:16:13 +0200 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-05-18 12:17:12 +0200 |
commit | a0e0d6c3a7a93db7a3caec9c2fd3ecaab47d31a8 (patch) | |
tree | 3e201e0b7ce741cd2823fc9d251e9b73056f5d66 | |
parent | Add port if missing (v2) and don't set keepalives (diff) |
Add /nick
Diffstat (limited to '')
-rw-r--r-- | commands.go | 17 | ||||
-rw-r--r-- | doc/senpai.1.scd | 3 | ||||
-rw-r--r-- | irc/states.go | 15 |
3 files changed, 35 insertions, 0 deletions
diff --git a/commands.go b/commands.go index 621b034..9bf2f13 100644 --- a/commands.go +++ b/commands.go @@ -64,6 +64,14 @@ func init() { Desc: "show the member list of the current channel", Handle: commandDoNames, }, + "NICK": { + AllowHome: true, + MinArgs: 1, + MaxArgs: 1, + Usage: "<nickname>", + Desc: "change your nickname", + Handle: commandDoNick, + }, "PART": { AllowHome: true, MaxArgs: 2, @@ -250,6 +258,15 @@ func commandDoNames(app *App, buffer string, args []string) (err error) { return } +func commandDoNick(app *App, buffer string, args []string) (err error) { + nick := args[0] + if i := strings.IndexAny(nick, " :@!*?"); i >= 0 { + return fmt.Errorf("illegal char %q in nickname", nick[i]) + } + app.s.ChangeNick(nick) + return +} + func commandDoPart(app *App, buffer string, args []string) (err error) { channel := buffer reason := "" diff --git a/doc/senpai.1.scd b/doc/senpai.1.scd index 3aecb3a..c1d69c0 100644 --- a/doc/senpai.1.scd +++ b/doc/senpai.1.scd @@ -143,6 +143,9 @@ _name_ is matched case-insensitively. It can be one of the following: *BUFFER* <name> Switch to the buffer containing _name_. +*NICK* <nickname> + Change your nickname. + # SEE ALSO *senpai*(5) diff --git a/irc/states.go b/irc/states.go index 957286d..d1ead27 100644 --- a/irc/states.go +++ b/irc/states.go @@ -88,6 +88,10 @@ type ( raw string } + actionChangeNick struct { + Nick string + } + actionJoin struct { Channel string } @@ -424,6 +428,15 @@ func splitChunks(s string, chunkLen int) (chunks []string) { return } +func (s *Session) ChangeNick(nick string) { + s.acts <- actionChangeNick{nick} +} + +func (s *Session) changeNick(act actionChangeNick) (err error) { + err = s.send("NICK %s\r\n", act.Nick) + return +} + func (s *Session) PrivMsg(target, content string) { s.acts <- actionPrivMsg{target, content} } @@ -519,6 +532,8 @@ func (s *Session) run() { switch act := act.(type) { case actionSendRaw: err = s.sendRaw(act) + case actionChangeNick: + err = s.changeNick(act) case actionJoin: err = s.join(act) case actionPart: |