2012-12-09 07:54:58 +01:00
|
|
|
package irc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2012-12-09 21:51:50 +01:00
|
|
|
"strings"
|
2012-12-09 07:54:58 +01:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2014-03-13 01:52:25 +01:00
|
|
|
type ReplyCode interface {
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type StringCode string
|
|
|
|
|
|
|
|
func (code StringCode) String() string {
|
|
|
|
return string(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
type NumericCode uint
|
|
|
|
|
|
|
|
func (code NumericCode) String() string {
|
|
|
|
return fmt.Sprintf("%03d", code)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewStringReply(source Identifiable, code StringCode,
|
2014-02-20 07:20:34 +01:00
|
|
|
format string, args ...interface{}) string {
|
2014-02-21 04:55:17 +01:00
|
|
|
var header string
|
2014-02-21 05:08:32 +01:00
|
|
|
if source == nil {
|
2014-02-22 21:15:34 +01:00
|
|
|
header = code.String() + " "
|
2014-02-21 05:08:32 +01:00
|
|
|
} else {
|
2014-02-21 04:55:17 +01:00
|
|
|
header = fmt.Sprintf(":%s %s ", source, code)
|
|
|
|
}
|
2014-02-22 21:15:34 +01:00
|
|
|
var message string
|
|
|
|
if len(args) > 0 {
|
|
|
|
message = fmt.Sprintf(format, args...)
|
|
|
|
} else {
|
|
|
|
message = format
|
|
|
|
}
|
2014-02-20 20:15:42 +01:00
|
|
|
return header + message
|
2012-12-17 04:13:53 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func NewNumericReply(target *Client, code NumericCode,
|
|
|
|
format string, args ...interface{}) string {
|
|
|
|
header := fmt.Sprintf(":%s %s %s ", target.server.Id(), code, target.Nick())
|
2014-02-22 21:15:34 +01:00
|
|
|
var message string
|
|
|
|
if len(args) > 0 {
|
|
|
|
message = fmt.Sprintf(format, args...)
|
|
|
|
} else {
|
|
|
|
message = format
|
|
|
|
}
|
2014-02-20 20:15:42 +01:00
|
|
|
return header + message
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) NumericReply(code NumericCode,
|
|
|
|
format string, args ...interface{}) {
|
2014-02-22 20:40:32 +01:00
|
|
|
target.Reply(NewNumericReply(target, code, format, args...))
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-18 05:47:41 +01:00
|
|
|
//
|
|
|
|
// multiline replies
|
|
|
|
//
|
2013-06-03 07:07:50 +02:00
|
|
|
|
2014-02-18 05:47:41 +01:00
|
|
|
func joinedLen(names []string) int {
|
|
|
|
var l = len(names) - 1 // " " between names
|
|
|
|
for _, name := range names {
|
|
|
|
l += len(name)
|
2013-06-03 07:07:50 +02:00
|
|
|
}
|
2014-02-18 05:47:41 +01:00
|
|
|
return l
|
2013-06-03 07:07:50 +02:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) MultilineReply(names []string, code NumericCode, format string,
|
|
|
|
args ...interface{}) {
|
|
|
|
baseLen := len(NewNumericReply(target, code, format))
|
2013-06-03 07:07:50 +02:00
|
|
|
tooLong := func(names []string) bool {
|
|
|
|
return (baseLen + joinedLen(names)) > MAX_REPLY_LEN
|
|
|
|
}
|
2014-02-20 07:20:34 +01:00
|
|
|
argsAndNames := func(names []string) []interface{} {
|
|
|
|
return append(args, strings.Join(names, " "))
|
|
|
|
}
|
2014-02-08 22:18:11 +01:00
|
|
|
from, to := 0, 1
|
2014-02-18 05:47:41 +01:00
|
|
|
for to < len(names) {
|
|
|
|
if (from < (to - 1)) && tooLong(names[from:to]) {
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(code, format, argsAndNames(names[from:to-1])...)
|
2014-03-28 20:11:01 +01:00
|
|
|
from = to - 1
|
2014-02-08 22:18:11 +01:00
|
|
|
} else {
|
|
|
|
to += 1
|
2013-06-03 07:07:50 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-18 05:47:41 +01:00
|
|
|
if from < len(names) {
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(code, format, argsAndNames(names[from:])...)
|
2013-06-03 07:07:50 +02:00
|
|
|
}
|
2014-02-18 05:47:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-12-13 08:33:09 +01:00
|
|
|
// messaging replies
|
2014-02-18 05:47:41 +01:00
|
|
|
//
|
2012-12-09 07:54:58 +01:00
|
|
|
|
2014-03-13 20:38:44 +01:00
|
|
|
func RplPrivMsg(source Identifiable, target Identifiable, message Text) string {
|
2014-02-17 02:23:47 +01:00
|
|
|
return NewStringReply(source, PRIVMSG, "%s :%s", target.Nick(), message)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-03-23 06:47:21 +01:00
|
|
|
func RplCTCPAction(source Identifiable, target Identifiable, action CTCPText) string {
|
|
|
|
return RplPrivMsg(source, target, NewText(fmt.Sprintf("\x01ACTION %s\x01", action)))
|
|
|
|
}
|
|
|
|
|
2014-03-13 20:38:44 +01:00
|
|
|
func RplNotice(source Identifiable, target Identifiable, message Text) string {
|
2014-02-17 02:23:47 +01:00
|
|
|
return NewStringReply(source, NOTICE, "%s :%s", target.Nick(), message)
|
2014-02-12 02:11:59 +01:00
|
|
|
}
|
|
|
|
|
2014-03-13 20:38:44 +01:00
|
|
|
func RplNick(source Identifiable, newNick Name) string {
|
2014-03-09 21:45:36 +01:00
|
|
|
return NewStringReply(source, NICK, newNick.String())
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func RplJoin(client *Client, channel *Channel) string {
|
2014-03-09 21:45:36 +01:00
|
|
|
return NewStringReply(client, JOIN, channel.name.String())
|
2012-12-13 08:27:17 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func RplPart(client *Client, channel *Channel, message Text) string {
|
2014-02-17 02:23:47 +01:00
|
|
|
return NewStringReply(client, PART, "%s :%s", channel, message)
|
2014-02-16 04:49:20 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func RplMode(client *Client, target *Client, changes ModeChanges) string {
|
|
|
|
return NewStringReply(client, MODE, "%s :%s", target.Nick(), changes)
|
2014-02-16 04:49:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func RplChannelMode(client *Client, channel *Channel,
|
2014-02-20 07:20:34 +01:00
|
|
|
changes ChannelModeChanges) string {
|
2014-02-17 02:23:47 +01:00
|
|
|
return NewStringReply(client, MODE, "%s %s", channel, changes)
|
2014-02-13 03:14:19 +01:00
|
|
|
}
|
|
|
|
|
2014-03-13 01:52:25 +01:00
|
|
|
func RplTopicMsg(source Identifiable, channel *Channel) string {
|
2014-02-17 02:23:47 +01:00
|
|
|
return NewStringReply(source, TOPIC, "%s :%s", channel, channel.topic)
|
2012-12-13 08:27:17 +01:00
|
|
|
}
|
|
|
|
|
2014-03-13 01:52:25 +01:00
|
|
|
func RplPing(target Identifiable) string {
|
2014-02-21 05:08:32 +01:00
|
|
|
return NewStringReply(nil, PING, ":%s", target.Nick())
|
2014-02-09 21:13:09 +01:00
|
|
|
}
|
|
|
|
|
2014-02-21 05:08:32 +01:00
|
|
|
func RplPong(client *Client) string {
|
2014-03-09 21:45:36 +01:00
|
|
|
return NewStringReply(nil, PONG, client.Nick().String())
|
2012-12-13 08:27:17 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func RplQuit(client *Client, message Text) string {
|
2014-02-17 02:23:47 +01:00
|
|
|
return NewStringReply(client, QUIT, ":%s", message)
|
2012-12-09 22:47:02 +01:00
|
|
|
}
|
|
|
|
|
2014-02-21 05:08:32 +01:00
|
|
|
func RplError(message string) string {
|
|
|
|
return NewStringReply(nil, ERROR, ":%s", message)
|
2014-02-09 02:10:04 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func RplInviteMsg(inviter *Client, invitee *Client, channel Name) string {
|
2014-03-06 07:54:50 +01:00
|
|
|
return NewStringReply(inviter, INVITE, "%s :%s", invitee.Nick(), channel)
|
2012-12-13 08:33:09 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func RplKick(channel *Channel, client *Client, target *Client, comment Text) string {
|
2014-02-17 08:29:11 +01:00
|
|
|
return NewStringReply(client, KICK, "%s %s :%s",
|
|
|
|
channel, target.Nick(), comment)
|
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func RplKill(client *Client, target *Client, comment Text) string {
|
2014-02-25 18:10:16 +01:00
|
|
|
return NewStringReply(client, KICK,
|
|
|
|
"%s :%s", target.Nick(), comment)
|
|
|
|
}
|
|
|
|
|
2014-03-08 22:59:48 +01:00
|
|
|
func RplCap(client *Client, subCommand CapSubCommand, arg interface{}) string {
|
|
|
|
return NewStringReply(nil, CAP, "%s %s :%s", client.Nick(), subCommand, arg)
|
|
|
|
}
|
|
|
|
|
2012-12-13 08:33:09 +01:00
|
|
|
// numeric replies
|
2012-12-09 07:54:58 +01:00
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplWelcome() {
|
|
|
|
target.NumericReply(RPL_WELCOME,
|
|
|
|
":Welcome to the Internet Relay Network %s", target.Id())
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplYourHost() {
|
|
|
|
target.NumericReply(RPL_YOURHOST,
|
2014-02-26 01:13:47 +01:00
|
|
|
":Your host is %s, running version %s", target.server.name, SEM_VER)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplCreated() {
|
|
|
|
target.NumericReply(RPL_CREATED,
|
|
|
|
":This server was created %s", target.server.ctime.Format(time.RFC1123))
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplMyInfo() {
|
|
|
|
target.NumericReply(RPL_MYINFO,
|
2014-03-13 21:18:40 +01:00
|
|
|
"%s %s %s %s",
|
|
|
|
target.server.name, SEM_VER, SupportedUserModes, SupportedChannelModes)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplUModeIs(client *Client) {
|
|
|
|
target.NumericReply(RPL_UMODEIS, client.ModeString())
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplNoTopic(channel *Channel) {
|
|
|
|
target.NumericReply(RPL_NOTOPIC,
|
2012-12-15 23:34:20 +01:00
|
|
|
"%s :No topic is set", channel.name)
|
2012-12-10 00:20:21 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplTopic(channel *Channel) {
|
|
|
|
target.NumericReply(RPL_TOPIC,
|
2012-12-15 23:34:20 +01:00
|
|
|
"%s :%s", channel.name, channel.topic)
|
2012-12-10 00:20:21 +01:00
|
|
|
}
|
|
|
|
|
2014-02-16 04:49:20 +01:00
|
|
|
// <nick> <channel>
|
|
|
|
// NB: correction in errata
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) RplInvitingMsg(invitee *Client, channel Name) {
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(RPL_INVITING,
|
2014-02-25 16:28:09 +01:00
|
|
|
"%s %s", invitee.Nick(), channel)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplEndOfNames(channel *Channel) {
|
|
|
|
target.NumericReply(RPL_ENDOFNAMES,
|
2014-02-08 22:18:11 +01:00
|
|
|
"%s :End of NAMES list", channel.name)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 19:07:40 +01:00
|
|
|
// :You are now an IRC operator
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplYoureOper() {
|
|
|
|
target.NumericReply(RPL_YOUREOPER,
|
|
|
|
":You are now an IRC operator")
|
2012-12-10 05:24:53 +01:00
|
|
|
}
|
|
|
|
|
2014-03-06 20:56:32 +01:00
|
|
|
func (target *Client) RplWhois(client *Client) {
|
|
|
|
target.RplWhoisUser(client)
|
|
|
|
if client.flags[Operator] {
|
|
|
|
target.RplWhoisOperator(client)
|
|
|
|
}
|
|
|
|
target.RplWhoisIdle(client)
|
|
|
|
target.RplWhoisChannels(client)
|
|
|
|
target.RplEndOfWhois()
|
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplWhoisUser(client *Client) {
|
|
|
|
target.NumericReply(RPL_WHOISUSER,
|
|
|
|
"%s %s %s * :%s", client.Nick(), client.username, client.hostname,
|
|
|
|
client.realname)
|
2014-02-09 02:43:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplWhoisOperator(client *Client) {
|
|
|
|
target.NumericReply(RPL_WHOISOPERATOR,
|
2014-02-18 04:08:57 +01:00
|
|
|
"%s :is an IRC operator", client.Nick())
|
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplWhoisIdle(client *Client) {
|
|
|
|
target.NumericReply(RPL_WHOISIDLE,
|
2014-02-18 04:56:06 +01:00
|
|
|
"%s %d %d :seconds idle, signon time",
|
|
|
|
client.Nick(), client.IdleSeconds(), client.SignonTime())
|
2014-02-18 04:08:57 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplEndOfWhois() {
|
|
|
|
target.NumericReply(RPL_ENDOFWHOIS,
|
|
|
|
":End of WHOIS list")
|
2014-02-09 02:43:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplChannelModeIs(channel *Channel) {
|
|
|
|
target.NumericReply(RPL_CHANNELMODEIS,
|
2014-02-22 21:49:33 +01:00
|
|
|
"%s %s", channel, channel.ModeString(target))
|
2014-02-09 03:14:39 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 03:49:52 +01:00
|
|
|
// <channel> <user> <host> <server> <nick> ( "H" / "G" ) ["*"] [ ( "@" / "+" ) ]
|
|
|
|
// :<hopcount> <real name>
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplWhoReply(channel *Channel, client *Client) {
|
2014-02-11 18:09:16 +01:00
|
|
|
channelName := "*"
|
2014-02-18 06:30:14 +01:00
|
|
|
flags := ""
|
|
|
|
|
|
|
|
if client.flags[Away] {
|
|
|
|
flags = "G"
|
|
|
|
} else {
|
|
|
|
flags = "H"
|
|
|
|
}
|
|
|
|
if client.flags[Operator] {
|
|
|
|
flags += "*"
|
|
|
|
}
|
|
|
|
|
2014-02-11 18:09:16 +01:00
|
|
|
if channel != nil {
|
2014-03-09 21:45:36 +01:00
|
|
|
channelName = channel.name.String()
|
2014-03-01 04:21:33 +01:00
|
|
|
if target.capabilities[MultiPrefix] {
|
|
|
|
if channel.members[client][ChannelOperator] {
|
|
|
|
flags += "@"
|
|
|
|
}
|
|
|
|
if channel.members[client][Voice] {
|
|
|
|
flags += "+"
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if channel.members[client][ChannelOperator] {
|
|
|
|
flags += "@"
|
|
|
|
} else if channel.members[client][Voice] {
|
|
|
|
flags += "+"
|
|
|
|
}
|
2014-02-18 06:30:14 +01:00
|
|
|
}
|
2014-02-11 18:09:16 +01:00
|
|
|
}
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(RPL_WHOREPLY,
|
|
|
|
"%s %s %s %s %s %s :%d %s", channelName, client.username, client.hostname,
|
|
|
|
client.server.name, client.Nick(), flags, client.hops, client.realname)
|
2014-02-09 03:49:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// <name> :End of WHO list
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) RplEndOfWho(name Name) {
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(RPL_ENDOFWHO,
|
|
|
|
"%s :End of WHO list", name)
|
2014-02-09 03:49:52 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) RplMaskList(mode ChannelMode, channel *Channel, mask Name) {
|
2014-02-23 00:01:11 +01:00
|
|
|
switch mode {
|
|
|
|
case BanMask:
|
|
|
|
target.RplBanList(channel, mask)
|
|
|
|
|
|
|
|
case ExceptMask:
|
|
|
|
target.RplExceptList(channel, mask)
|
|
|
|
|
|
|
|
case InviteMask:
|
|
|
|
target.RplInviteList(channel, mask)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (target *Client) RplEndOfMaskList(mode ChannelMode, channel *Channel) {
|
|
|
|
switch mode {
|
|
|
|
case BanMask:
|
|
|
|
target.RplEndOfBanList(channel)
|
|
|
|
|
|
|
|
case ExceptMask:
|
|
|
|
target.RplEndOfExceptList(channel)
|
|
|
|
|
|
|
|
case InviteMask:
|
|
|
|
target.RplEndOfInviteList(channel)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) RplBanList(channel *Channel, mask Name) {
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(RPL_BANLIST,
|
2014-02-23 00:01:11 +01:00
|
|
|
"%s %s", channel, mask)
|
2014-02-09 07:06:10 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplEndOfBanList(channel *Channel) {
|
|
|
|
target.NumericReply(RPL_ENDOFBANLIST,
|
2014-02-23 00:01:11 +01:00
|
|
|
"%s :End of channel ban list", channel)
|
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) RplExceptList(channel *Channel, mask Name) {
|
2014-02-23 00:01:11 +01:00
|
|
|
target.NumericReply(RPL_EXCEPTLIST,
|
|
|
|
"%s %s", channel, mask)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (target *Client) RplEndOfExceptList(channel *Channel) {
|
|
|
|
target.NumericReply(RPL_ENDOFEXCEPTLIST,
|
|
|
|
"%s :End of channel exception list", channel)
|
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) RplInviteList(channel *Channel, mask Name) {
|
2014-02-23 00:01:11 +01:00
|
|
|
target.NumericReply(RPL_INVITELIST,
|
|
|
|
"%s %s", channel, mask)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (target *Client) RplEndOfInviteList(channel *Channel) {
|
|
|
|
target.NumericReply(RPL_ENDOFINVITELIST,
|
|
|
|
"%s :End of channel invite list", channel)
|
2014-02-12 00:44:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplNowAway() {
|
|
|
|
target.NumericReply(RPL_NOWAWAY,
|
2014-02-12 00:44:58 +01:00
|
|
|
":You have been marked as being away")
|
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplUnAway() {
|
|
|
|
target.NumericReply(RPL_UNAWAY,
|
2014-02-12 00:44:58 +01:00
|
|
|
":You are no longer marked as being away")
|
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplAway(client *Client) {
|
|
|
|
target.NumericReply(RPL_AWAY,
|
2014-02-13 03:14:19 +01:00
|
|
|
"%s :%s", client.Nick(), client.awayMessage)
|
2014-02-09 07:06:10 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplIsOn(nicks []string) {
|
|
|
|
target.NumericReply(RPL_ISON,
|
2014-02-12 00:58:54 +01:00
|
|
|
":%s", strings.Join(nicks, " "))
|
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplMOTDStart() {
|
|
|
|
target.NumericReply(RPL_MOTDSTART,
|
|
|
|
":- %s Message of the day - ", target.server.name)
|
2014-02-12 01:35:32 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplMOTD(line string) {
|
|
|
|
target.NumericReply(RPL_MOTD,
|
2014-02-12 01:35:32 +01:00
|
|
|
":- %s", line)
|
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplMOTDEnd() {
|
|
|
|
target.NumericReply(RPL_ENDOFMOTD,
|
2014-02-12 01:35:32 +01:00
|
|
|
":End of MOTD command")
|
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplList(channel *Channel) {
|
|
|
|
target.NumericReply(RPL_LIST,
|
|
|
|
"%s %d :%s", channel, len(channel.members), channel.topic)
|
2014-02-17 08:51:27 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) RplListEnd(server *Server) {
|
|
|
|
target.NumericReply(RPL_LISTEND,
|
|
|
|
":End of LIST")
|
2014-02-17 08:51:27 +01:00
|
|
|
}
|
|
|
|
|
2014-02-22 22:15:31 +01:00
|
|
|
func (target *Client) RplNamReply(channel *Channel) {
|
2014-03-01 04:21:33 +01:00
|
|
|
target.MultilineReply(channel.Nicks(target), RPL_NAMREPLY,
|
2014-02-22 22:15:31 +01:00
|
|
|
"= %s :%s", channel)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (target *Client) RplWhoisChannels(client *Client) {
|
|
|
|
target.MultilineReply(client.WhoisChannelsNames(), RPL_WHOISCHANNELS,
|
|
|
|
"%s :%s", client.Nick())
|
|
|
|
}
|
|
|
|
|
2014-02-25 07:04:11 +01:00
|
|
|
func (target *Client) RplVersion() {
|
|
|
|
target.NumericReply(RPL_VERSION,
|
2014-02-26 01:13:47 +01:00
|
|
|
"%s %s", SEM_VER, target.server.name)
|
2014-02-25 07:04:11 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) RplInviting(invitee *Client, channel Name) {
|
2014-02-25 16:28:09 +01:00
|
|
|
target.NumericReply(RPL_INVITING,
|
|
|
|
"%s %s", invitee.Nick(), channel)
|
|
|
|
}
|
|
|
|
|
2014-02-25 16:45:40 +01:00
|
|
|
func (target *Client) RplTime() {
|
|
|
|
target.NumericReply(RPL_TIME,
|
|
|
|
"%s :%s", target.server.name, time.Now().Format(time.RFC1123))
|
|
|
|
}
|
|
|
|
|
2014-03-06 22:55:25 +01:00
|
|
|
func (target *Client) RplWhoWasUser(whoWas *WhoWas) {
|
2014-03-06 21:14:21 +01:00
|
|
|
target.NumericReply(RPL_WHOWASUSER,
|
2014-03-06 22:55:25 +01:00
|
|
|
"%s %s %s * :%s",
|
|
|
|
whoWas.nickname, whoWas.username, whoWas.hostname, whoWas.realname)
|
2014-03-06 21:14:21 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) RplEndOfWhoWas(nickname Name) {
|
2014-03-06 21:14:21 +01:00
|
|
|
target.NumericReply(RPL_ENDOFWHOWAS,
|
|
|
|
"%s :End of WHOWAS", nickname)
|
|
|
|
}
|
|
|
|
|
2014-02-12 00:58:54 +01:00
|
|
|
//
|
2012-12-13 08:33:09 +01:00
|
|
|
// errors (also numeric)
|
2014-02-12 00:58:54 +01:00
|
|
|
//
|
2012-12-09 07:54:58 +01:00
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrAlreadyRegistered() {
|
|
|
|
target.NumericReply(ERR_ALREADYREGISTRED,
|
2012-12-15 23:34:20 +01:00
|
|
|
":You may not reregister")
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) ErrNickNameInUse(nick Name) {
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(ERR_NICKNAMEINUSE,
|
2012-12-15 23:34:20 +01:00
|
|
|
"%s :Nickname is already in use", nick)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrUnknownCommand(code StringCode) {
|
|
|
|
target.NumericReply(ERR_UNKNOWNCOMMAND,
|
2014-02-17 08:29:11 +01:00
|
|
|
"%s :Unknown command", code)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrUsersDontMatch() {
|
|
|
|
target.NumericReply(ERR_USERSDONTMATCH,
|
2012-12-09 22:47:02 +01:00
|
|
|
":Cannot change mode for other users")
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) ErrNeedMoreParams(command StringCode) {
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(ERR_NEEDMOREPARAMS,
|
2012-12-15 23:34:20 +01:00
|
|
|
"%s :Not enough parameters", command)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) ErrNoSuchChannel(channel Name) {
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(ERR_NOSUCHCHANNEL,
|
2012-12-15 23:34:20 +01:00
|
|
|
"%s :No such channel", channel)
|
2012-12-09 22:47:02 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrUserOnChannel(channel *Channel, member *Client) {
|
|
|
|
target.NumericReply(ERR_USERONCHANNEL,
|
2014-02-13 03:14:19 +01:00
|
|
|
"%s %s :is already on channel", member.Nick(), channel.name)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrNotOnChannel(channel *Channel) {
|
|
|
|
target.NumericReply(ERR_NOTONCHANNEL,
|
2012-12-15 23:34:20 +01:00
|
|
|
"%s :You're not on that channel", channel.name)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrInviteOnlyChannel(channel *Channel) {
|
|
|
|
target.NumericReply(ERR_INVITEONLYCHAN,
|
2012-12-15 23:34:20 +01:00
|
|
|
"%s :Cannot join channel (+i)", channel.name)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrBadChannelKey(channel *Channel) {
|
|
|
|
target.NumericReply(ERR_BADCHANNELKEY,
|
2012-12-15 23:34:20 +01:00
|
|
|
"%s :Cannot join channel (+k)", channel.name)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) ErrNoSuchNick(nick Name) {
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(ERR_NOSUCHNICK,
|
2012-12-15 23:34:20 +01:00
|
|
|
"%s :No such nick/channel", nick)
|
2012-12-09 07:54:58 +01:00
|
|
|
}
|
2012-12-10 05:24:53 +01:00
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrPasswdMismatch() {
|
|
|
|
target.NumericReply(ERR_PASSWDMISMATCH, ":Password incorrect")
|
2012-12-10 05:24:53 +01:00
|
|
|
}
|
2012-12-12 08:04:03 +01:00
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrNoChanModes(channel *Channel) {
|
|
|
|
target.NumericReply(ERR_NOCHANMODES,
|
2014-02-17 08:29:11 +01:00
|
|
|
"%s :Channel doesn't support modes", channel)
|
2012-12-15 23:34:20 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrNoPrivileges() {
|
|
|
|
target.NumericReply(ERR_NOPRIVILEGES, ":Permission Denied")
|
2012-12-15 23:34:20 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrRestricted() {
|
|
|
|
target.NumericReply(ERR_RESTRICTED, ":Your connection is restricted!")
|
2012-12-12 08:04:03 +01:00
|
|
|
}
|
2014-02-09 02:43:59 +01:00
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) ErrNoSuchServer(server Name) {
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(ERR_NOSUCHSERVER, "%s :No such server", server)
|
2014-02-09 02:43:59 +01:00
|
|
|
}
|
2014-02-09 03:14:39 +01:00
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrUserNotInChannel(channel *Channel, client *Client) {
|
|
|
|
target.NumericReply(ERR_USERNOTINCHANNEL,
|
2014-02-17 08:29:11 +01:00
|
|
|
"%s %s :They aren't on that channel", client.Nick(), channel)
|
2014-02-09 03:14:39 +01:00
|
|
|
}
|
2014-02-09 08:33:56 +01:00
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrCannotSendToChan(channel *Channel) {
|
|
|
|
target.NumericReply(ERR_CANNOTSENDTOCHAN,
|
2014-02-17 08:29:11 +01:00
|
|
|
"%s :Cannot send to channel", channel)
|
2014-02-09 08:33:56 +01:00
|
|
|
}
|
2014-02-10 04:59:59 +01:00
|
|
|
|
|
|
|
// <channel> :You're not channel operator
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrChanOPrivIsNeeded(channel *Channel) {
|
|
|
|
target.NumericReply(ERR_CHANOPRIVSNEEDED,
|
2014-02-17 08:29:11 +01:00
|
|
|
"%s :You're not channel operator", channel)
|
2014-02-10 04:59:59 +01:00
|
|
|
}
|
2014-02-12 00:33:02 +01:00
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrNoMOTD() {
|
|
|
|
target.NumericReply(ERR_NOMOTD, ":MOTD File is missing")
|
2014-02-12 00:33:02 +01:00
|
|
|
}
|
2014-02-13 19:57:00 +01:00
|
|
|
|
2014-02-20 07:20:34 +01:00
|
|
|
func (target *Client) ErrNoNicknameGiven() {
|
|
|
|
target.NumericReply(ERR_NONICKNAMEGIVEN, ":No nickname given")
|
2014-02-13 19:57:00 +01:00
|
|
|
}
|
2014-02-18 02:58:22 +01:00
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) ErrErroneusNickname(nick Name) {
|
2014-02-20 07:20:34 +01:00
|
|
|
target.NumericReply(ERR_ERRONEUSNICKNAME,
|
2014-02-18 02:58:22 +01:00
|
|
|
"%s :Erroneous nickname", nick)
|
|
|
|
}
|
2014-02-22 21:15:34 +01:00
|
|
|
|
|
|
|
func (target *Client) ErrUnknownMode(mode ChannelMode, channel *Channel) {
|
|
|
|
target.NumericReply(ERR_UNKNOWNMODE,
|
|
|
|
"%s :is unknown mode char to me for %s", mode, channel)
|
|
|
|
}
|
2014-02-22 21:49:33 +01:00
|
|
|
|
2014-03-13 09:55:46 +01:00
|
|
|
func (target *Client) ErrConfiguredMode(mode ChannelMode) {
|
|
|
|
target.NumericReply(ERR_UNKNOWNMODE,
|
|
|
|
"%s :can only change this mode in daemon configuration", mode)
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:49:33 +01:00
|
|
|
func (target *Client) ErrChannelIsFull(channel *Channel) {
|
|
|
|
target.NumericReply(ERR_CHANNELISFULL,
|
|
|
|
"%s :Cannot join channel (+l)", channel)
|
|
|
|
}
|
2014-03-06 21:14:21 +01:00
|
|
|
|
2014-03-09 21:45:36 +01:00
|
|
|
func (target *Client) ErrWasNoSuchNick(nickname Name) {
|
2014-03-06 21:14:21 +01:00
|
|
|
target.NumericReply(ERR_WASNOSUCHNICK,
|
|
|
|
"%s :There was no such nickname", nickname)
|
|
|
|
}
|
2014-03-07 02:44:37 +01:00
|
|
|
|
2014-03-01 04:21:33 +01:00
|
|
|
func (target *Client) ErrInvalidCapCmd(subCommand CapSubCommand) {
|
|
|
|
target.NumericReply(ERR_INVALIDCAPCMD,
|
|
|
|
"%s :Invalid CAP subcommand", subCommand)
|
|
|
|
}
|
2014-03-08 02:09:49 +01:00
|
|
|
|
|
|
|
func (target *Client) ErrBannedFromChan(channel *Channel) {
|
|
|
|
target.NumericReply(ERR_BANNEDFROMCHAN,
|
|
|
|
"%s :Cannot join channel (+b)", channel)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (target *Client) ErrInviteOnlyChan(channel *Channel) {
|
|
|
|
target.NumericReply(ERR_INVITEONLYCHAN,
|
|
|
|
"%s :Cannot join channel (+i)", channel)
|
|
|
|
}
|