commit 7fbbcec
delthas
·
2023-11-13 12:54:37 +0000 UTC
parent d2e7791
Add AWAY and BACK commands Fixes: https://todo.sr.ht/~taiite/senpai/118
4 files changed,
+57,
-0
M
app.go
+8,
-0
1@@ -1099,6 +1099,14 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
2 return
3 }
4 }
5+ case "305", "306":
6+ app.addStatusLine(netID, ui.Line{
7+ At: time.Now(),
8+ Head: "--",
9+ HeadColor: app.cfg.Colors.Status,
10+ Body: ui.Styled(ev.Message, tcell.StyleDefault.Foreground(app.cfg.Colors.Status)),
11+ })
12+ return
13 }
14 var head string
15 var body string
+35,
-0
1@@ -209,6 +209,19 @@ func init() {
2 Desc: "search messages in a target",
3 Handle: commandDoSearch,
4 },
5+ "AWAY": {
6+ AllowHome: true,
7+ MinArgs: 0,
8+ MaxArgs: 1,
9+ Usage: "[message]",
10+ Desc: "mark yourself as away",
11+ Handle: commandDoAway,
12+ },
13+ "BACK": {
14+ AllowHome: true,
15+ Desc: "mark yourself as back from being away",
16+ Handle: commandDoBack,
17+ },
18 "SHRUG": {
19 Desc: "send a shrug to the current channel ¯\\_(ツ)_/¯",
20 Handle: commandDoShrug,
21@@ -718,6 +731,28 @@ func commandDoSearch(app *App, args []string) (err error) {
22 return nil
23 }
24
25+func commandDoAway(app *App, args []string) (err error) {
26+ reason := "Away"
27+ if len(args) > 0 {
28+ reason = args[0]
29+ }
30+ s := app.CurrentSession()
31+ if s == nil {
32+ return errOffline
33+ }
34+ s.Away(reason)
35+ return nil
36+}
37+
38+func commandDoBack(app *App, args []string) (err error) {
39+ s := app.CurrentSession()
40+ if s == nil {
41+ return errOffline
42+ }
43+ s.Away("")
44+ return nil
45+}
46+
47 // implemented from https://golang.org/src/strings/strings.go?s=8055:8085#L310
48 func fieldsN(s string, n int) []string {
49 s = strings.TrimSpace(s)
+6,
-0
1@@ -215,6 +215,12 @@ _name_ is matched case-insensitively. It can be one of the following:
2 Search messages matching the given text, in the current channel or server.
3 This opens a temporary list, which can be closed with the escape key.
4
5+*AWAY* [message]
6+ Mark yourself as away, with an optional away message.
7+
8+*BACK*
9+ Mark yourself as back from being away.
10+
11 *SHRUG*
12 Send a shrug emoji to the current channel. ¯\\\_(ツ)\_/¯
13
+8,
-0
1@@ -414,6 +414,14 @@ func (s *Session) Search(target, text string) {
2 s.out <- NewMessage("SEARCH", formatTags(attrs))
3 }
4
5+func (s *Session) Away(message string) {
6+ if message != "" {
7+ s.out <- NewMessage("AWAY", message)
8+ } else {
9+ s.out <- NewMessage("AWAY")
10+ }
11+}
12+
13 func splitChunks(s string, chunkLen int) (chunks []string) {
14 if chunkLen <= 0 {
15 return []string{s}