xirc: move command constants over
This commit is contained in:
parent
e2e232fa9c
commit
c50fb4a26d
@ -58,7 +58,7 @@ func sendTopic(dc *downstreamConn, ch *upstreamChannel) {
|
|||||||
topicTime := strconv.FormatInt(ch.TopicTime.Unix(), 10)
|
topicTime := strconv.FormatInt(ch.TopicTime.Unix(), 10)
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
Prefix: dc.srv.prefix(),
|
Prefix: dc.srv.prefix(),
|
||||||
Command: rpl_topicwhotime,
|
Command: xirc.RPL_TOPICWHOTIME,
|
||||||
Params: []string{dc.nick, downstreamName, topicWho.String(), topicTime},
|
Params: []string{dc.nick, downstreamName, topicWho.String(), topicTime},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -876,7 +876,7 @@ func (dc *downstreamConn) handleCapCommand(cmd string, args []string) error {
|
|||||||
case "REQ":
|
case "REQ":
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return ircError{&irc.Message{
|
return ircError{&irc.Message{
|
||||||
Command: err_invalidcapcmd,
|
Command: xirc.ERR_INVALIDCAPCMD,
|
||||||
Params: []string{dc.nick, cmd, "Missing argument in CAP REQ command"},
|
Params: []string{dc.nick, cmd, "Missing argument in CAP REQ command"},
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
@ -935,7 +935,7 @@ func (dc *downstreamConn) handleCapCommand(cmd string, args []string) error {
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return ircError{&irc.Message{
|
return ircError{&irc.Message{
|
||||||
Command: err_invalidcapcmd,
|
Command: xirc.ERR_INVALIDCAPCMD,
|
||||||
Params: []string{dc.nick, cmd, "Unknown CAP command"},
|
Params: []string{dc.nick, cmd, "Unknown CAP command"},
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
@ -1187,7 +1187,7 @@ func (dc *downstreamConn) updateHost() {
|
|||||||
} else if uc.hostname != dc.hostname {
|
} else if uc.hostname != dc.hostname {
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
Prefix: dc.prefix(),
|
Prefix: dc.prefix(),
|
||||||
Command: rpl_visiblehost,
|
Command: xirc.RPL_VISIBLEHOST,
|
||||||
Params: []string{dc.nick, uc.hostname, "is now your visible host"},
|
Params: []string{dc.nick, uc.hostname, "is now your visible host"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1790,7 +1790,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
|
|||||||
|
|
||||||
if dc.network == nil {
|
if dc.network == nil {
|
||||||
return ircError{&irc.Message{
|
return ircError{&irc.Message{
|
||||||
Command: err_unknownerror,
|
Command: xirc.ERR_UNKNOWNERROR,
|
||||||
Params: []string{dc.nick, "NICK", "Cannot change nickname on the bouncer connection"},
|
Params: []string{dc.nick, "NICK", "Cannot change nickname on the bouncer connection"},
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
@ -2138,7 +2138,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
|
|||||||
if ch.creationTime != "" {
|
if ch.creationTime != "" {
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
Prefix: dc.srv.prefix(),
|
Prefix: dc.srv.prefix(),
|
||||||
Command: rpl_creationtime,
|
Command: xirc.RPL_CREATIONTIME,
|
||||||
Params: []string{dc.nick, name, ch.creationTime},
|
Params: []string{dc.nick, name, ch.creationTime},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -2375,7 +2375,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
|
|||||||
}
|
}
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
Prefix: dc.srv.prefix(),
|
Prefix: dc.srv.prefix(),
|
||||||
Command: rpl_whoisaccount,
|
Command: xirc.RPL_WHOISACCOUNT,
|
||||||
Params: []string{dc.nick, dc.nick, dc.user.Username, "is logged in as"},
|
Params: []string{dc.nick, dc.nick, dc.user.Username, "is logged in as"},
|
||||||
})
|
})
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
@ -2403,12 +2403,12 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
|
|||||||
})
|
})
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
Prefix: dc.srv.prefix(),
|
Prefix: dc.srv.prefix(),
|
||||||
Command: rpl_whoisaccount,
|
Command: xirc.RPL_WHOISACCOUNT,
|
||||||
Params: []string{dc.nick, serviceNick, serviceNick, "is logged in as"},
|
Params: []string{dc.nick, serviceNick, serviceNick, "is logged in as"},
|
||||||
})
|
})
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
Prefix: dc.srv.prefix(),
|
Prefix: dc.srv.prefix(),
|
||||||
Command: rpl_whoisbot,
|
Command: xirc.RPL_WHOISBOT,
|
||||||
Params: []string{dc.nick, serviceNick, "is a bot"},
|
Params: []string{dc.nick, serviceNick, "is a bot"},
|
||||||
})
|
})
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
|
25
irc.go
25
irc.go
@ -16,29 +16,6 @@ import (
|
|||||||
|
|
||||||
// TODO: generalize and move helpers to the xirc package
|
// TODO: generalize and move helpers to the xirc package
|
||||||
|
|
||||||
const (
|
|
||||||
rpl_statsping = "246"
|
|
||||||
rpl_localusers = "265"
|
|
||||||
rpl_globalusers = "266"
|
|
||||||
rpl_whoiscertfp = "276"
|
|
||||||
rpl_whoisregnick = "307"
|
|
||||||
rpl_whoisspecial = "320"
|
|
||||||
rpl_creationtime = "329"
|
|
||||||
rpl_whoisaccount = "330"
|
|
||||||
rpl_topicwhotime = "333"
|
|
||||||
rpl_whoisactually = "338"
|
|
||||||
rpl_whospcrpl = "354"
|
|
||||||
rpl_whoishost = "378"
|
|
||||||
rpl_whoismodes = "379"
|
|
||||||
rpl_visiblehost = "396"
|
|
||||||
err_unknownerror = "400"
|
|
||||||
err_invalidcapcmd = "410"
|
|
||||||
rpl_whoissecure = "671"
|
|
||||||
|
|
||||||
// https://ircv3.net/specs/extensions/bot-mode
|
|
||||||
rpl_whoisbot = "335"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxMessageLength = 512
|
maxMessageLength = 512
|
||||||
maxMessageParams = 15
|
maxMessageParams = 15
|
||||||
@ -787,7 +764,7 @@ func generateWHOXReply(prefix *irc.Prefix, nick, fields string, info *whoxInfo)
|
|||||||
|
|
||||||
return &irc.Message{
|
return &irc.Message{
|
||||||
Prefix: prefix,
|
Prefix: prefix,
|
||||||
Command: rpl_whospcrpl,
|
Command: xirc.RPL_WHOSPCRPL,
|
||||||
Params: append([]string{nick}, values...),
|
Params: append([]string{nick}, values...),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
upstream.go
18
upstream.go
@ -693,7 +693,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
|||||||
dc.updateAccount()
|
dc.updateAccount()
|
||||||
dc.updateHost()
|
dc.updateHost()
|
||||||
})
|
})
|
||||||
case rpl_visiblehost:
|
case xirc.RPL_VISIBLEHOST:
|
||||||
var rawHost string
|
var rawHost string
|
||||||
if err := parseMessageParams(msg, nil, &rawHost); err != nil {
|
if err := parseMessageParams(msg, nil, &rawHost); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1236,7 +1236,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case rpl_creationtime:
|
case xirc.RPL_CREATIONTIME:
|
||||||
var channel, creationTime string
|
var channel, creationTime string
|
||||||
if err := parseMessageParams(msg, nil, &channel, &creationTime); err != nil {
|
if err := parseMessageParams(msg, nil, &channel, &creationTime); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1255,12 +1255,12 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
|||||||
uc.forEachDownstream(func(dc *downstreamConn) {
|
uc.forEachDownstream(func(dc *downstreamConn) {
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
Prefix: dc.srv.prefix(),
|
Prefix: dc.srv.prefix(),
|
||||||
Command: rpl_creationtime,
|
Command: xirc.RPL_CREATIONTIME,
|
||||||
Params: []string{dc.nick, dc.marshalEntity(uc.network, ch.Name), creationTime},
|
Params: []string{dc.nick, dc.marshalEntity(uc.network, ch.Name), creationTime},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case rpl_topicwhotime:
|
case xirc.RPL_TOPICWHOTIME:
|
||||||
var channel, who, timeStr string
|
var channel, who, timeStr string
|
||||||
if err := parseMessageParams(msg, nil, &channel, &who, &timeStr); err != nil {
|
if err := parseMessageParams(msg, nil, &channel, &who, &timeStr); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1285,7 +1285,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
|||||||
topicWho := dc.marshalUserPrefix(uc.network, ch.TopicWho)
|
topicWho := dc.marshalUserPrefix(uc.network, ch.TopicWho)
|
||||||
dc.SendMessage(&irc.Message{
|
dc.SendMessage(&irc.Message{
|
||||||
Prefix: dc.srv.prefix(),
|
Prefix: dc.srv.prefix(),
|
||||||
Command: rpl_topicwhotime,
|
Command: xirc.RPL_TOPICWHOTIME,
|
||||||
Params: []string{
|
Params: []string{
|
||||||
dc.nick,
|
dc.nick,
|
||||||
dc.marshalEntity(uc.network, ch.Name),
|
dc.marshalEntity(uc.network, ch.Name),
|
||||||
@ -1417,7 +1417,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
|||||||
Command: irc.RPL_WHOREPLY,
|
Command: irc.RPL_WHOREPLY,
|
||||||
Params: []string{dc.nick, channel, username, host, server, nick, flags, trailing},
|
Params: []string{dc.nick, channel, username, host, server, nick, flags, trailing},
|
||||||
})
|
})
|
||||||
case rpl_whospcrpl:
|
case xirc.RPL_WHOSPCRPL:
|
||||||
dc, cmd := uc.currentPendingCommand("WHO")
|
dc, cmd := uc.currentPendingCommand("WHO")
|
||||||
if cmd == nil {
|
if cmd == nil {
|
||||||
return fmt.Errorf("unexpected RPL_WHOSPCRPL: no matching pending WHO")
|
return fmt.Errorf("unexpected RPL_WHOSPCRPL: no matching pending WHO")
|
||||||
@ -1449,7 +1449,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
|||||||
Command: irc.RPL_ENDOFWHO,
|
Command: irc.RPL_ENDOFWHO,
|
||||||
Params: []string{dc.nick, mask, "End of /WHO list"},
|
Params: []string{dc.nick, mask, "End of /WHO list"},
|
||||||
})
|
})
|
||||||
case rpl_whoiscertfp, rpl_whoisregnick, irc.RPL_WHOISUSER, irc.RPL_WHOISSERVER, irc.RPL_WHOISOPERATOR, irc.RPL_WHOISIDLE, rpl_whoisspecial, rpl_whoisaccount, rpl_whoisactually, rpl_whoishost, rpl_whoismodes, rpl_whoissecure:
|
case xirc.RPL_WHOISCERTFP, xirc.RPL_WHOISREGNICK, irc.RPL_WHOISUSER, irc.RPL_WHOISSERVER, irc.RPL_WHOISOPERATOR, irc.RPL_WHOISIDLE, xirc.RPL_WHOISSPECIAL, xirc.RPL_WHOISACCOUNT, xirc.RPL_WHOISACTUALLY, xirc.RPL_WHOISHOST, xirc.RPL_WHOISMODES, xirc.RPL_WHOISSECURE:
|
||||||
var nick string
|
var nick string
|
||||||
if err := parseMessageParams(msg, nil, &nick); err != nil {
|
if err := parseMessageParams(msg, nil, &nick); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1730,9 +1730,9 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
|||||||
// Ignore
|
// Ignore
|
||||||
case irc.RPL_LUSERCLIENT, irc.RPL_LUSEROP, irc.RPL_LUSERUNKNOWN, irc.RPL_LUSERCHANNELS, irc.RPL_LUSERME:
|
case irc.RPL_LUSERCLIENT, irc.RPL_LUSEROP, irc.RPL_LUSERUNKNOWN, irc.RPL_LUSERCHANNELS, irc.RPL_LUSERME:
|
||||||
fallthrough
|
fallthrough
|
||||||
case irc.RPL_STATSVLINE, rpl_statsping, irc.RPL_STATSBLINE, irc.RPL_STATSDLINE:
|
case irc.RPL_STATSVLINE, xirc.RPL_STATSPING, irc.RPL_STATSBLINE, irc.RPL_STATSDLINE:
|
||||||
fallthrough
|
fallthrough
|
||||||
case rpl_localusers, rpl_globalusers:
|
case xirc.RPL_LOCALUSERS, xirc.RPL_GLOBALUSERS:
|
||||||
fallthrough
|
fallthrough
|
||||||
case irc.RPL_MOTDSTART, irc.RPL_MOTD:
|
case irc.RPL_MOTDSTART, irc.RPL_MOTD:
|
||||||
// Ignore these messages if they're part of the initial registration
|
// Ignore these messages if they're part of the initial registration
|
||||||
|
23
xirc/xirc.go
23
xirc/xirc.go
@ -8,6 +8,29 @@ import (
|
|||||||
"gopkg.in/irc.v3"
|
"gopkg.in/irc.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
RPL_STATSPING = "246"
|
||||||
|
RPL_LOCALUSERS = "265"
|
||||||
|
RPL_GLOBALUSERS = "266"
|
||||||
|
RPL_WHOISCERTFP = "276"
|
||||||
|
RPL_WHOISREGNICK = "307"
|
||||||
|
RPL_WHOISSPECIAL = "320"
|
||||||
|
RPL_CREATIONTIME = "329"
|
||||||
|
RPL_WHOISACCOUNT = "330"
|
||||||
|
RPL_TOPICWHOTIME = "333"
|
||||||
|
RPL_WHOISACTUALLY = "338"
|
||||||
|
RPL_WHOSPCRPL = "354"
|
||||||
|
RPL_WHOISHOST = "378"
|
||||||
|
RPL_WHOISMODES = "379"
|
||||||
|
RPL_VISIBLEHOST = "396"
|
||||||
|
ERR_UNKNOWNERROR = "400"
|
||||||
|
ERR_INVALIDCAPCMD = "410"
|
||||||
|
RPL_WHOISSECURE = "671"
|
||||||
|
|
||||||
|
// https://ircv3.net/specs/extensions/bot-mode
|
||||||
|
RPL_WHOISBOT = "335"
|
||||||
|
)
|
||||||
|
|
||||||
// The server-time layout, as defined in the IRCv3 spec.
|
// The server-time layout, as defined in the IRCv3 spec.
|
||||||
const ServerTimeLayout = "2006-01-02T15:04:05.000Z"
|
const ServerTimeLayout = "2006-01-02T15:04:05.000Z"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user