3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-29 07:29:31 +01:00

Merge pull request #1748 from ProgVal/patch-2

Add support for KICK #chan user1,user2
This commit is contained in:
Shivaram Lingamneni 2021-07-13 08:55:44 -04:00 committed by GitHub
commit dc0bf1a02d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1273,11 +1273,14 @@ func sajoinHandler(server *Server, client *Client, msg ircmsg.Message, rb *Respo
} }
// KICK <channel>{,<channel>} <user>{,<user>} [<comment>] // KICK <channel>{,<channel>} <user>{,<user>} [<comment>]
// RFC 2812 requires the number of channels to be either 1 or equal to
// the number of users.
// Addditionally, we support multiple channels and a single user.
func kickHandler(server *Server, client *Client, msg ircmsg.Message, rb *ResponseBuffer) bool { func kickHandler(server *Server, client *Client, msg ircmsg.Message, rb *ResponseBuffer) bool {
hasPrivs := client.HasRoleCapabs("samode") hasPrivs := client.HasRoleCapabs("samode")
channels := strings.Split(msg.Params[0], ",") channels := strings.Split(msg.Params[0], ",")
users := strings.Split(msg.Params[1], ",") users := strings.Split(msg.Params[1], ",")
if (len(channels) != len(users)) && (len(users) != 1) { if (len(channels) != len(users)) && (len(users) != 1) && (len(channels) != 1) {
rb.Add(nil, server.name, ERR_NEEDMOREPARAMS, client.nick, "KICK", client.t("Not enough parameters")) rb.Add(nil, server.name, ERR_NEEDMOREPARAMS, client.nick, "KICK", client.t("Not enough parameters"))
return false return false
} }
@ -1286,15 +1289,30 @@ func kickHandler(server *Server, client *Client, msg ircmsg.Message, rb *Respons
channel string channel string
nick string nick string
} }
kicks := make([]kickCmd, 0, len(channels)) var kicks []kickCmd
for index, channel := range channels { if len(users) == 1 {
kicks = make([]kickCmd, 0, len(channels))
// Single user, possibly multiple channels
user := users[0]
for _, channel := range channels {
if channel == "" { if channel == "" {
continue // #679 continue // #679
} }
if len(users) == 1 { kicks = append(kicks, kickCmd{channel, user})
kicks = append(kicks, kickCmd{channel, users[0]}) }
} else { } else {
kicks = append(kicks, kickCmd{channel, users[index]}) // Multiple users, either a single channel or as many channels
// as users.
kicks = make([]kickCmd, 0, len(users))
channel := channels[0]
for index, user := range users {
if len(channels) > 1 {
channel = channels[index]
}
if channel == "" {
continue // #679
}
kicks = append(kicks, kickCmd{channel, user})
} }
} }