mirror of
https://github.com/ergochat/ergo.git
synced 2025-01-03 08:32:43 +01:00
invite command
This commit is contained in:
parent
d6ec1e719b
commit
f0305cf01a
@ -402,3 +402,22 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string) {
|
|||||||
}
|
}
|
||||||
channel.Quit(target)
|
channel.Quit(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (channel *Channel) Invite(invitee *Client, inviter *Client) {
|
||||||
|
if channel.flags[InviteOnly] && !channel.ClientIsOperator(inviter) {
|
||||||
|
inviter.ErrChanOPrivIsNeeded(channel)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !channel.members.Has(inviter) {
|
||||||
|
inviter.ErrNotOnChannel(channel)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Modify channel masks
|
||||||
|
inviter.RplInviting(invitee, channel.name)
|
||||||
|
invitee.Reply(RplInviteMsg(inviter, channel.name))
|
||||||
|
if invitee.flags[Away] {
|
||||||
|
inviter.RplAway(invitee)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -29,6 +29,7 @@ var (
|
|||||||
AWAY: NewAwayCommand,
|
AWAY: NewAwayCommand,
|
||||||
CAP: NewCapCommand,
|
CAP: NewCapCommand,
|
||||||
DEBUG: NewDebugCommand,
|
DEBUG: NewDebugCommand,
|
||||||
|
INVITE: NewInviteCommand,
|
||||||
ISON: NewIsOnCommand,
|
ISON: NewIsOnCommand,
|
||||||
JOIN: NewJoinCommand,
|
JOIN: NewJoinCommand,
|
||||||
KICK: NewKickCommand,
|
KICK: NewKickCommand,
|
||||||
@ -914,3 +915,20 @@ func NewVersionCommand(args []string) (editableCommand, error) {
|
|||||||
}
|
}
|
||||||
return cmd, nil
|
return cmd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type InviteCommand struct {
|
||||||
|
BaseCommand
|
||||||
|
nickname string
|
||||||
|
channel string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewInviteCommand(args []string) (editableCommand, error) {
|
||||||
|
if len(args) < 2 {
|
||||||
|
return nil, NotEnoughArgsError
|
||||||
|
}
|
||||||
|
|
||||||
|
return &InviteCommand{
|
||||||
|
nickname: args[0],
|
||||||
|
channel: args[1],
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
13
irc/reply.go
13
irc/reply.go
@ -128,8 +128,8 @@ func RplError(message string) string {
|
|||||||
return NewStringReply(nil, ERROR, ":%s", message)
|
return NewStringReply(nil, ERROR, ":%s", message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplInviteMsg(channel *Channel, inviter *Client) string {
|
func RplInviteMsg(inviter *Client, channel string) string {
|
||||||
return NewStringReply(inviter, INVITE, channel.name)
|
return NewStringReply(inviter, INVITE, channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplKick(channel *Channel, client *Client, target *Client, comment string) string {
|
func RplKick(channel *Channel, client *Client, target *Client, comment string) string {
|
||||||
@ -175,9 +175,9 @@ func (target *Client) RplTopic(channel *Channel) {
|
|||||||
|
|
||||||
// <nick> <channel>
|
// <nick> <channel>
|
||||||
// NB: correction in errata
|
// NB: correction in errata
|
||||||
func (target *Client) RplInvitingMsg(channel *Channel, invitee *Client) {
|
func (target *Client) RplInvitingMsg(invitee *Client, channel string) {
|
||||||
target.NumericReply(RPL_INVITING,
|
target.NumericReply(RPL_INVITING,
|
||||||
"%s %s", invitee.Nick(), channel.name)
|
"%s %s", invitee.Nick(), channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (target *Client) RplEndOfNames(channel *Channel) {
|
func (target *Client) RplEndOfNames(channel *Channel) {
|
||||||
@ -369,6 +369,11 @@ func (target *Client) RplVersion() {
|
|||||||
"ergonomadic-%s %s", SERVER_VERSION, target.server.name)
|
"ergonomadic-%s %s", SERVER_VERSION, target.server.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (target *Client) RplInviting(invitee *Client, channel string) {
|
||||||
|
target.NumericReply(RPL_INVITING,
|
||||||
|
"%s %s", invitee.Nick(), channel)
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// errors (also numeric)
|
// errors (also numeric)
|
||||||
//
|
//
|
||||||
|
@ -448,7 +448,7 @@ func (msg *PrivMsgCommand) HandleServer(server *Server) {
|
|||||||
}
|
}
|
||||||
target.Reply(RplPrivMsg(client, target, msg.message))
|
target.Reply(RplPrivMsg(client, target, msg.message))
|
||||||
if target.flags[Away] {
|
if target.flags[Away] {
|
||||||
target.RplAway(client)
|
client.RplAway(target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -772,3 +772,22 @@ func (msg *VersionCommand) HandleServer(server *Server) {
|
|||||||
|
|
||||||
client.RplVersion()
|
client.RplVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (msg *InviteCommand) HandleServer(server *Server) {
|
||||||
|
client := msg.Client()
|
||||||
|
|
||||||
|
target := server.clients.Get(msg.nickname)
|
||||||
|
if target == nil {
|
||||||
|
client.ErrNoSuchNick(msg.nickname)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
channel := server.channels[msg.channel]
|
||||||
|
if channel == nil {
|
||||||
|
client.RplInviting(target, msg.channel)
|
||||||
|
target.Reply(RplInviteMsg(client, msg.channel))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
channel.Invite(target, client)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user