~taiite/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH senpai] Implement /kick and /[un]ban commands

Details
Message ID
<20211201175701.541-1-yyp@disroot.org>
DKIM signature
missing
Download raw message
Patch: +84 -0
---
 commands.go    | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++
 irc/session.go |  8 ++++++
 2 files changed, 84 insertions(+)

diff --git a/commands.go b/commands.go
index 5dff158..e8e6807 100644
--- a/commands.go
+++ b/commands.go
@@ -142,6 +142,30 @@ func init() {
			Desc:      "invite someone to a channel",
			Handle:    commandDoInvite,
		},
		"KICK": {
			AllowHome: false,
			MinArgs:   1,
			MaxArgs:   2,
			Usage:     "<nick> [channel]",
			Desc:      "remove someone from the channel",
			Handle:    commandDoKick,
		},
		"BAN": {
			AllowHome: false,
			MinArgs:   1,
			MaxArgs:   2,
			Usage:     "<nick> [channel]",
			Desc:      "ban someone from entering the channel",
			Handle:    commandDoBan,
		},
		"UNBAN": {
			AllowHome: false,
			MinArgs:   1,
			MaxArgs:   2,
			Usage:     "<nick> [channel]",
			Desc:      "remove effect of a ban from the user",
			Handle:    commandDoUnban,
		},
	}
}

@@ -506,6 +530,58 @@ func commandDoInvite(app *App, args []string) (err error) {
	return nil
}

func commandDoKick(app *App, args []string) (err error) {
	nick := args[0]
	netID, channel := app.win.CurrentBuffer()
	s := app.sessions[netID]
	if s == nil {
		return errOffline
	}
	if len(args) >= 2 {
		channel = args[1]
	} else if channel == "" {
		return fmt.Errorf("either send this command from a channel, or specify the channel")
	}
	comment := ""
	if len(args) == 3 {
		comment = args[2]
	}
	s.Kick(nick, channel, comment)
	return nil
}

func commandDoBan(app *App, args []string) (err error) {
	nick := args[0]
	netID, channel := app.win.CurrentBuffer()
	s := app.sessions[netID]
	if s == nil {
		return errOffline
	}
	if len(args) == 2 {
		channel = args[1]
	} else if channel == "" {
		return fmt.Errorf("either send this command from a channel, or specify the channel")
	}
	s.ChangeMode(channel, "+b", []string{nick})
	return nil
}

func commandDoUnban(app *App, args []string) (err error) {
	nick := args[0]
	netID, channel := app.win.CurrentBuffer()
	s := app.sessions[netID]
	if s == nil {
		return errOffline
	}
	if len(args) == 2 {
		channel = args[1]
	} else if channel == "" {
		return fmt.Errorf("either send this command from a channel, or specify the channel")
	}
	s.ChangeMode(channel, "-b", []string{nick})
	return nil
}

// implemented from https://golang.org/src/strings/strings.go?s=8055:8085#L310
func fieldsN(s string, n int) []string {
	s = strings.TrimSpace(s)
diff --git a/irc/session.go b/irc/session.go
index b6d5873..4bbd0c7 100644
--- a/irc/session.go
+++ b/irc/session.go
@@ -494,6 +494,14 @@ func (s *Session) Invite(nick, channel string) {
	s.out <- NewMessage("INVITE", nick, channel)
}

func (s *Session) Kick(nick, channel, comment string) {
	if comment == "" {
		s.out <- NewMessage("KICK", channel, nick)
	} else {
		s.out <- NewMessage("KICK", channel, nick, comment)
	}
}

func (s *Session) HandleMessage(msg Message) (Event, error) {
	if s.registered {
		return s.handleRegistered(msg)
-- 
2.34.1
Details
Message ID
<93e1fdd6-3861-8e41-3935-48841c6c8d94@hirtz.pm>
In-Reply-To
<20211201175701.541-1-yyp@disroot.org> (view parent)
DKIM signature
missing
Download raw message
Thanks, looks good.

Can you update the man page?
Details
Message ID
<CG8H0NUXQ3KK.24V7YINKCKWAX@desktop>
In-Reply-To
<93e1fdd6-3861-8e41-3935-48841c6c8d94@hirtz.pm> (view parent)
DKIM signature
missing
Download raw message
On Mon Dec 6, 2021 at 1:41 PM MSK, Hubert Hirtz wrote:
> Can you update the man page?

Yeah, sure.
Details
Message ID
<83c49b8cab1bc824d68b0961fe0d33c4@dille.cc>
In-Reply-To
<CG8H0NUXQ3KK.24V7YINKCKWAX@desktop> (view parent)
DKIM signature
missing
Download raw message
This can be set as accepted, it was merged in [1].

[1]: 65718d37abc15e727c20b9b031d32b953b258d2a
Reply to thread Export thread (mbox)