commit fc101c7
Hubert Hirtz
·
2021-02-18 16:13:16 +0000 UTC
parent b4aaf60
Add the QUIT command
3 files changed,
+36,
-3
+16,
-0
1@@ -64,6 +64,12 @@ func init() {
2 Desc: "part a channel",
3 Handle: commandDoPart,
4 },
5+ "QUIT": {
6+ AllowHome: true,
7+ Usage: "[reason]",
8+ Desc: "quit senpai",
9+ Handle: commandDoQuit,
10+ },
11 "QUOTE": {
12 MinArgs: 1,
13 AllowHome: true,
14@@ -248,6 +254,16 @@ func commandDoPart(app *App, buffer string, args []string) (err error) {
15 return
16 }
17
18+func commandDoQuit(app *App, buffer string, args []string) (err error) {
19+ reason := ""
20+ if 0 < len(args) {
21+ reason = args[0]
22+ }
23+ app.s.Quit(reason)
24+ app.win.Exit()
25+ return
26+}
27+
28 func commandDoQuote(app *App, buffer string, args []string) (err error) {
29 app.s.SendRaw(args[0])
30 return
+6,
-3
1@@ -109,12 +109,15 @@ _name_ is matched case-insensitively. It can be one of the following:
2 *HELP* [search]
3 Show the list of command (or a commands that match the given search terms).
4
5-*J*, *JOIN* <channel>
6+*JOIN* <channel>
7 Join the given channel.
8
9-*PART* [channel]
10+*PART* [channel] [reason]
11 Part the given channel, defaults to the current one if omitted.
12
13+*QUIT* [reason]
14+ Quits senpai.
15+
16 *NAMES*
17 Show the member list of the current channel. Powerlevels (such as _@_ for
18 "operator", or _+_ for "voice") are shown in green.
19@@ -128,7 +131,7 @@ _name_ is matched case-insensitively. It can be one of the following:
20 *MSG* <target> <content>
21 Send _content_ to _target_.
22
23-*R* <content>
24+*REPLY* <content>
25 Reply to the last person who sent a private message.
26
27 *ME* <content>
+14,
-0
1@@ -96,6 +96,9 @@ type (
2 Channel string
3 Topic string
4 }
5+ actionQuit struct {
6+ Reason string
7+ }
8
9 actionPrivMsg struct {
10 Target string
11@@ -390,6 +393,15 @@ func (s *Session) setTopic(act actionSetTopic) (err error) {
12 return
13 }
14
15+func (s *Session) Quit(reason string) {
16+ s.acts <- actionQuit{reason}
17+}
18+
19+func (s *Session) quit(act actionQuit) (err error) {
20+ err = s.send("QUIT :%s\r\n", act.Reason)
21+ return
22+}
23+
24 func (s *Session) PrivMsg(target, content string) {
25 s.acts <- actionPrivMsg{target, content}
26 }
27@@ -469,6 +481,8 @@ func (s *Session) run() {
28 err = s.part(act)
29 case actionSetTopic:
30 err = s.setTopic(act)
31+ case actionQuit:
32+ err = s.quit(act)
33 case actionPrivMsg:
34 err = s.privMsg(act)
35 case actionTyping: