commit e29587a
delthas
·
2024-04-25 21:50:59 +0000 UTC
parent e46263f
commands: Add BOUNCER command Makes it slightly easier to interact with the soju bouncer. Also show bouncer messages as noticed (in the current buffer).
3 files changed,
+40,
-2
M
app.go
+1,
-1
1@@ -1378,7 +1378,7 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
2 content = parts[1]
3 }
4
5- if !ev.TargetIsChannel && isNotice {
6+ if !ev.TargetIsChannel && (isNotice || ev.User == s.BouncerService()) {
7 curNetID, curBuffer := app.win.CurrentBuffer()
8 if curNetID == s.NetID() {
9 buffer = curBuffer
+24,
-0
1@@ -45,6 +45,14 @@ func init() {
2 Desc: "show the list of commands, or how to use the given one",
3 Handle: commandDoHelp,
4 },
5+ "BOUNCER": {
6+ AllowHome: true,
7+ MinArgs: 1,
8+ MaxArgs: 1,
9+ Usage: "<bouncer message>",
10+ Desc: "send command to the bouncer service (only works with soju); e.g. /bouncer help",
11+ Handle: commandDoBouncer,
12+ },
13 "JOIN": {
14 AllowHome: true,
15 MinArgs: 1,
16@@ -612,6 +620,22 @@ func commandDoQuit(app *App, args []string) (err error) {
17 return nil
18 }
19
20+func commandDoBouncer(app *App, args []string) (err error) {
21+ if app.cfg.Transient {
22+ return fmt.Errorf("usage of BOUNCER is disabled")
23+ }
24+ s := app.CurrentSession()
25+ if s == nil {
26+ return errOffline
27+ }
28+ b := s.BouncerService()
29+ if b == "" {
30+ return fmt.Errorf("no bouncer service found on this server")
31+ }
32+ s.PrivMsg(b, args[0])
33+ return nil
34+}
35+
36 func commandDoQuote(app *App, args []string) (err error) {
37 if app.cfg.Transient {
38 return fmt.Errorf("usage of QUOTE is disabled")
+15,
-1
1@@ -128,6 +128,7 @@ type Session struct {
2 availableCaps map[string]string
3 enabledCaps map[string]struct{}
4
5+ serverName string
6 // ISUPPORT features
7 casemap func(string) string
8 chanmodes [4]string
9@@ -223,6 +224,15 @@ func (s *Session) HasCapability(capability string) bool {
10 return ok
11 }
12
13+// BouncerService returns the optional nick of the bouncer service user.
14+func (s *Session) BouncerService() string {
15+ switch s.serverName {
16+ case "soju":
17+ return "BouncerServ"
18+ }
19+ return ""
20+}
21+
22 func (s *Session) Nick() string {
23 return s.nick
24 }
25@@ -744,6 +754,10 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er
26 if s.host == "" {
27 s.Who(s.nick)
28 }
29+ case rplMyinfo:
30+ if err := msg.ParseParams(nil, nil, &s.serverName); err != nil {
31+ return nil, err
32+ }
33 case rplIsupport:
34 if len(msg.Params) < 3 {
35 return nil, msg.errNotEnoughParams(3)
36@@ -1453,7 +1467,7 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er
37 // silence monlist full error, we don't care because we do it best-effort
38 case rplAway:
39 // we display user away status, we don't care about automatic AWAY replies
40- case rplYourhost, rplCreated, rplMyinfo:
41+ case rplYourhost, rplCreated:
42 // useless conection messages
43 case rplAdminme:
44 // useless admin info header