commit a0e0d6c
Hubert Hirtz
·
2021-05-18 10:16:13 +0000 UTC
parent 4969650
Add /nick
3 files changed,
+35,
-0
+17,
-0
1@@ -64,6 +64,14 @@ func init() {
2 Desc: "show the member list of the current channel",
3 Handle: commandDoNames,
4 },
5+ "NICK": {
6+ AllowHome: true,
7+ MinArgs: 1,
8+ MaxArgs: 1,
9+ Usage: "<nickname>",
10+ Desc: "change your nickname",
11+ Handle: commandDoNick,
12+ },
13 "PART": {
14 AllowHome: true,
15 MaxArgs: 2,
16@@ -250,6 +258,15 @@ func commandDoNames(app *App, buffer string, args []string) (err error) {
17 return
18 }
19
20+func commandDoNick(app *App, buffer string, args []string) (err error) {
21+ nick := args[0]
22+ if i := strings.IndexAny(nick, " :@!*?"); i >= 0 {
23+ return fmt.Errorf("illegal char %q in nickname", nick[i])
24+ }
25+ app.s.ChangeNick(nick)
26+ return
27+}
28+
29 func commandDoPart(app *App, buffer string, args []string) (err error) {
30 channel := buffer
31 reason := ""
+3,
-0
1@@ -143,6 +143,9 @@ _name_ is matched case-insensitively. It can be one of the following:
2 *BUFFER* <name>
3 Switch to the buffer containing _name_.
4
5+*NICK* <nickname>
6+ Change your nickname.
7+
8 # SEE ALSO
9
10 *senpai*(5)
+15,
-0
1@@ -88,6 +88,10 @@ type (
2 raw string
3 }
4
5+ actionChangeNick struct {
6+ Nick string
7+ }
8+
9 actionJoin struct {
10 Channel string
11 }
12@@ -424,6 +428,15 @@ func splitChunks(s string, chunkLen int) (chunks []string) {
13 return
14 }
15
16+func (s *Session) ChangeNick(nick string) {
17+ s.acts <- actionChangeNick{nick}
18+}
19+
20+func (s *Session) changeNick(act actionChangeNick) (err error) {
21+ err = s.send("NICK %s\r\n", act.Nick)
22+ return
23+}
24+
25 func (s *Session) PrivMsg(target, content string) {
26 s.acts <- actionPrivMsg{target, content}
27 }
28@@ -519,6 +532,8 @@ func (s *Session) run() {
29 switch act := act.(type) {
30 case actionSendRaw:
31 err = s.sendRaw(act)
32+ case actionChangeNick:
33+ err = s.changeNick(act)
34 case actionJoin:
35 err = s.join(act)
36 case actionPart: