3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 11:59:40 +01:00

add UNINVITE command (#1171)

This commit is contained in:
Shivaram Lingamneni 2020-10-25 22:16:19 -04:00
parent 42d246b557
commit 4b1e6b04c4
5 changed files with 39 additions and 1 deletions

View File

@ -1524,6 +1524,22 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client, rb *ResponseBuf
}
}
// Uninvite rescinds a channel invitation, if the inviter can do so.
func (channel *Channel) Uninvite(invitee *Client, inviter *Client, rb *ResponseBuffer) {
if !channel.flags.HasMode(modes.InviteOnly) {
rb.Add(nil, channel.server.name, "FAIL", "UNINVITE", "NOT_INVITE_ONLY", channel.Name(), inviter.t("Channel is not invite-only"))
return
}
if !channel.ClientIsAtLeast(inviter, modes.ChannelOperator) {
rb.Add(nil, channel.server.name, "FAIL", "UNINVITE", "NOT_PRIVED", channel.Name(), inviter.t("You're not a channel operator"))
return
}
invitee.Uninvite(channel.NameCasefolded())
rb.Add(nil, channel.server.name, "UNINVITE", invitee.Nick(), channel.Name())
}
// returns who the client can "see" in the channel, respecting the auditorium mode
func (channel *Channel) auditoriumFriends(client *Client) (friends []*Client) {
channel.stateMutex.RLock()

View File

@ -1787,6 +1787,12 @@ func (client *Client) Invite(casefoldedChannel string, channelCreatedAt time.Tim
return
}
func (client *Client) Uninvite(casefoldedChannel string) {
client.stateMutex.Lock()
defer client.stateMutex.Unlock()
delete(client.invitedTo, casefoldedChannel)
}
// Checks that the client was invited to join a given channel
func (client *Client) CheckInvited(casefoldedChannel string, createdTime time.Time) (invited bool) {
config := client.server.Config()

View File

@ -324,6 +324,10 @@ func init() {
minParams: 1,
oper: true,
},
"UNINVITE": {
handler: inviteHandler,
minParams: 2,
},
"UNKLINE": {
handler: unKLineHandler,
minParams: 1,

View File

@ -1113,7 +1113,9 @@ func infoHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
}
// INVITE <nickname> <channel>
// UNINVITE <nickname> <channel>
func inviteHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
invite := msg.Command == "INVITE"
nickname := msg.Params[0]
channelName := msg.Params[1]
@ -1129,7 +1131,12 @@ func inviteHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
return false
}
channel.Invite(target, client, rb)
if invite {
channel.Invite(target, client, rb)
} else {
channel.Uninvite(target, client, rb)
}
return false
}

View File

@ -541,6 +541,11 @@ For example:
Used in connection registration, sets your username and realname to the given
values (though your username may also be looked up with Ident).`,
},
"uninvite": {
text: `UNINVITE <nickname> <channel>
UNINVITE rescinds a channel invitation sent for an invite-only channel.`,
},
"users": {
text: `USERS [parameters]