Authentication-Results: mail-b.sr.ht; dkim=pass header.d=disroot.org header.i=@disroot.org Received: from knopi.disroot.org (knopi.disroot.org [178.21.23.139]) by mail-b.sr.ht (Postfix) with ESMTPS id 08B4F11EF81 for <~taiite/public-inbox@lists.sr.ht>; Mon, 6 Dec 2021 20:09:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 7751C8C441; Mon, 6 Dec 2021 21:09:15 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id d2Byk93mVNhp; Mon, 6 Dec 2021 21:09:14 +0100 (CET) From: Alexey Yerin DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1638821351; bh=aeygoJNDc56x5CSb8Zn+gqxfW/wJEm2qlpHSweMAPyE=; h=From:To:Cc:Subject:Date; b=XH2oK4eWrBPmAq3bwr1jTbdHE3TnU+I3oiyp2cMVYC1UnbVRRzingBHQcAyh4REFR 0MSyt9vuOfCCnu1+uaw0Bm7bXLdqM2IBMLw66jEEEUO6KeCBLFEnZhndg4U6AiVxt1 irRv8I998SMWi+FPfDaP5naeXXqH5oBnJ3pN/Kyc280+57JLS3GxYJVMF7Yqvhj5N1 otFTymfGFoM+xsPgzxGVFHGJeFkzl+NEozYMDfLOwyvNavQPgI2BtIrtuC5o9E4hRl Jff3k6LccevdYIMnu17MBCiGCbrGhtGEoItC7LqTuXSYJBsvJ1uLICIzxgHLYeXbZJ /vKBW897fqnwA== To: ~taiite/public-inbox@lists.sr.ht Cc: Alexey Yerin Subject: [PATCH senpai v2] Implement /kick and /[un]ban commands Date: Mon, 6 Dec 2021 23:09:08 +0300 Message-Id: <20211206200908.9836-1-yyp@disroot.org> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit --- v1 -> v2: * Some minor wording changes I forgot about * Add new commands to senpai.1 man page commands.go | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ doc/senpai.1.scd | 9 ++++++ irc/session.go | 8 +++++ 3 files changed, 93 insertions(+) diff --git a/commands.go b/commands.go index 5dff158..403aec8 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: " [channel]", + Desc: "eject someone from the channel", + Handle: commandDoKick, + }, + "BAN": { + AllowHome: false, + MinArgs: 1, + MaxArgs: 2, + Usage: " [channel]", + Desc: "ban someone from entering the channel", + Handle: commandDoBan, + }, + "UNBAN": { + AllowHome: false, + MinArgs: 1, + MaxArgs: 2, + Usage: " [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/doc/senpai.1.scd b/doc/senpai.1.scd index c64a82c..81e3544 100644 --- a/doc/senpai.1.scd +++ b/doc/senpai.1.scd @@ -165,6 +165,15 @@ _name_ is matched case-insensitively. It can be one of the following: *INVITE* [channel] Invite _nick_ to _channel_ (the current channel if not given). +*KICK* [channel] + Eject _nick_ from _channel_ (the current channel if not given). + +*BAN* [channel] + Ban _nick_ from entering _channel_ (the current channel if not given). + +*UNBAN* [channel] + Allow _nick_ to enter _channel_ again (the current channel if not given). + # SEE ALSO *senpai*(5) diff --git a/irc/session.go b/irc/session.go index 87b77b6..3dd979c 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