~delthas/senpai-dev

4 2

[PATCH v2 0/3] A few patches for senpai

Details
Message ID
<20240730195426.26422-1-vitali64pmemail@protonmail.com>
DKIM signature
pass
Download raw message
Quit and part messages can sometimes be useful for knowing if, e.g. a
user spamming channels got K-Lined, or if a netsplit is occuring, among
other things.

As said in #senpai:

	f_	delthas: Anyway, for example, just now someone spammed a
		channel on another network (Rizon) but then quit
	f_	I cannot know if that user has already been k-lined or if
		they just left the channel.
	delthas	f_: OK, so maybe a global toggle would make sense

The following patches implement such a toggle, it is disabled by
default, so the previous behaviour of not showing quit messages is
preserved.

Showing who sent a mode change can also be useful, for example, in the
event that a user gives +o to some untrusted user, you may want to know
who did that. See https://todo.sr.ht/~delthas/senpai/159. I chose to
show these at all times, see Runxi Yu's comment on this:

> Could we also have a way to access it from the keyboard?
>
> And to be honest, I'd prefer it to be on the screen all the time
> (as opposed to only show when clicked or only show when activated
> via the keyboard) but I guess that's a personal preference

Cheers!

Ferass El Hafidi (3):
  Optionally show quit and part messages
  doc/senpai.5.scd: document "quitmessages" option
  Show mode change sender

 app.go           | 16 ++++++++++++++--
 config.go        | 11 +++++++++++
 doc/senpai.5.scd |  3 +++
 irc/events.go    |  3 +++
 irc/session.go   | 20 ++++++++++++++++++--
 5 files changed, 49 insertions(+), 4 deletions(-)

--
2.45.1

[PATCH v2 1/3] Optionally show quit and part messages

Details
Message ID
<20240730195426.26422-2-vitali64pmemail@protonmail.com>
In-Reply-To
<20240730195426.26422-1-vitali64pmemail@protonmail.com> (view parent)
DKIM signature
pass
Download raw message
These are not shown by default, enable `quitmessages` in the config
file to show them.

Also differenciate between a quit and a part by showing an "x" next
to the nickname instead of a "-" for a quit.

The way this is implemented will hide the following quit messages:

 * "connection closed"
 * "Remote host closed connection"
 * "Quit: "
 * "" (empty)

Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
---
 app.go         | 14 +++++++++++++-
 config.go      | 11 +++++++++++
 irc/events.go  |  2 ++
 irc/session.go | 18 ++++++++++++++++--
 4 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/app.go b/app.go
index 24546e7..7e3a5f7 100644
--- a/app.go
+++ b/app.go
@@ -1639,6 +1639,11 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
 			Foreground: app.cfg.Colors.Status,
 		})
 		body.WriteString(ev.User)
+		if app.cfg.QuitMessages && ev.Message != "" {
+			body.WriteString(" (")
+			body.WriteString(ev.Message)
+			body.WriteByte(')')
+		}
 		return ui.Line{
 			At:        ev.Time,
 			Head:      "--",
@@ -1654,11 +1659,18 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
 		body.SetStyle(vaxis.Style{
 			Foreground: ui.ColorRed,
 		})
-		body.WriteByte('-')
+		body.WriteByte('x')
 		body.SetStyle(vaxis.Style{
 			Foreground: app.cfg.Colors.Status,
 		})
 		body.WriteString(ev.User)
+		if app.cfg.QuitMessages && ev.Message != "" &&
+			// Few checks for useless messages
+			ev.Message != "Quit: " && ev.Message != "Client Quit" &&
+			ev.Message != "connection closed" && ev.Message != "Remote host has closed the connection" {
+			body.WriteString(" (")
+			body.WriteString(ev.Message)
+			body.WriteByte(')')
+		}
 		return ui.Line{
 			At:        ev.Time,
 			Head:      "--",
diff --git a/config.go b/config.go
index 3b6c40b..69cee97 100644
--- a/config.go
+++ b/config.go
@@ -108,6 +108,7 @@ type Config struct {
 	ChanColEnabled   bool
 	MemberColWidth   int
 	MemberColEnabled bool
+	QuitMessages     bool
 	TextMaxWidth     int
 	StatusEnabled    bool

@@ -146,6 +147,7 @@ func Defaults() Config {
 		ChanColEnabled:   true,
 		MemberColWidth:   16,
 		MemberColEnabled: true,
+		QuitMessages:     false,
 		TextMaxWidth:     0,
 		StatusEnabled:    true,
 		Colors: ui.ConfigColors{
@@ -425,6 +427,15 @@ func unmarshal(filename string, cfg *Config) (err error) {
 					return fmt.Errorf("unknown colors directive %q", child.Name)
 				}
 			}
+		case "quitmessages":
+			var quitmessages string
+			if err := d.ParseParams(&quitmessages); err != nil {
+				return err
+			}
+
+			if cfg.QuitMessages, err = strconv.ParseBool(quitmessages); err != nil {
+				return err
+			}
 		case "debug":
 			var debug string
 			if err := d.ParseParams(&debug); err != nil {
diff --git a/irc/events.go b/irc/events.go
index 9bb61ba..716a9c1 100644
--- a/irc/events.go
+++ b/irc/events.go
@@ -48,12 +48,14 @@ type UserPartEvent struct {
 	User    string
 	Channel string
 	Time    time.Time
+	Message string
 }

 type UserQuitEvent struct {
 	User     string
 	Channels []string
 	Time     time.Time
+	Message string
 }

 type UserOnlineEvent struct {
diff --git a/irc/session.go b/irc/session.go
index 9132e65..d972679 100644
--- a/irc/session.go
+++ b/irc/session.go
@@ -901,8 +901,11 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er
 		}

 		var channel string
-		if err := msg.ParseParams(&channel); err != nil {
-			return nil, err
+		var partmessage string
+		if len(msg.Params) == 2 {
+			if err := msg.ParseParams(&channel, &partmessage); err != nil {
+				return nil, err
+			}
 		}

 		if playback {
@@ -910,6 +913,7 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er
 				User:    msg.Prefix.Name,
 				Channel: channel,
 				Time:    msg.TimeOrNow(),
+				Message: partmessage,
 			}, nil
 		}

@@ -982,10 +986,19 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er
 			return nil, errMissingPrefix
 		}

+		var quitmessage string
+
+		if len(msg.Params) == 1 {
+			if err := msg.ParseParams(&quitmessage); err != nil {
+				return nil, err
+			}
+		}
+
 		if playback {
 			return UserQuitEvent{
 				User: msg.Prefix.Name,
 				Time: msg.TimeOrNow(),
+				Message: quitmessage,
 			}, nil
 		}

@@ -1006,6 +1019,7 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er
 				User:     u.Name.Name,
 				Channels: channels,
 				Time:     msg.TimeOrNow(),
+				Message:  quitmessage,
 			}, nil
 		}
 	case rplMononline:
--
2.45.1

[PATCH v2 2/3] doc/senpai.5.scd: document "quitmessages" option

Details
Message ID
<20240730195426.26422-3-vitali64pmemail@protonmail.com>
In-Reply-To
<20240730195426.26422-1-vitali64pmemail@protonmail.com> (view parent)
DKIM signature
pass
Download raw message
Patch: +3 -0
See previous commit.

Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
---
 doc/senpai.5.scd | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/doc/senpai.5.scd b/doc/senpai.5.scd
index b6a29f9..17331e3 100644
--- a/doc/senpai.5.scd
+++ b/doc/senpai.5.scd
@@ -153,6 +153,9 @@ pane-widths {
*mouse*
	Enable or disable mouse support.  Defaults to true.

*quitmessages*
	Enable or disable showing quit and part messages.  Defaults to false.

*colors* { ... }
	Settings for colors of different UI elements.

-- 
2.45.1

[PATCH v2 3/3] Show mode change sender

Details
Message ID
<20240730195426.26422-4-vitali64pmemail@protonmail.com>
In-Reply-To
<20240730195426.26422-1-vitali64pmemail@protonmail.com> (view parent)
DKIM signature
pass
Download raw message
Patch: +4 -1
Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
---
 app.go         | 2 +-
 irc/events.go  | 1 +
 irc/session.go | 2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/app.go b/app.go
index 7e3a5f7..5750d43 100644
--- a/app.go
+++ b/app.go
@@ -1695,7 +1695,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
			Readable: true,
		}
	case irc.ModeChangeEvent:
		body := fmt.Sprintf("[%s]", ev.Mode)
		body := fmt.Sprintf("[%s] by %s", ev.Mode, ev.Who)
		// simple mode event: <+/-><mode> <nick>
		mergeable := len(strings.Split(ev.Mode, " ")) == 2
		return ui.Line{
diff --git a/irc/events.go b/irc/events.go
index 716a9c1..2fbafd5 100644
--- a/irc/events.go
+++ b/irc/events.go
@@ -77,6 +77,7 @@ type ModeChangeEvent struct {
	Channel string
	Mode    string
	Time    time.Time
	Who	string
}

type InviteEvent struct {
diff --git a/irc/session.go b/irc/session.go
index d972679..b86cd2d 100644
--- a/irc/session.go
+++ b/irc/session.go
@@ -1197,6 +1197,7 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er
				Channel: channel,
				Mode:    mode,
				Time:    msg.TimeOrNow(),
				Who:     msg.Prefix.Name,
			}, nil
		}

@@ -1237,6 +1238,7 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er
				Channel: c.Name,
				Mode:    mode,
				Time:    msg.TimeOrNow(),
				Who:     msg.Prefix.Name,
			}, nil
		}
	case "INVITE":
-- 
2.45.1
Details
Message ID
<D335DMUG1KBB.JES9T58HZQY3@protonmail.com>
In-Reply-To
<20240730195426.26422-1-vitali64pmemail@protonmail.com> (view parent)
DKIM signature
pass
Download raw message
Forgot to put in changes since v1 in the cover letter, so here goes:

* `QUIT` received without arguments are now properly handled
* Empty quit/part messages or useless messages are no longer shown

Cheers.
Reply to thread Export thread (mbox)