mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
remove prefix from local replies; fix topic message
This commit is contained in:
parent
db2a21fee0
commit
52dd2521c2
@ -195,14 +195,17 @@ func (m *TopicCommand) HandleChannel(channel *Channel) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.topic == "" {
|
if m.setTopic {
|
||||||
|
channel.topic = m.topic
|
||||||
channel.GetTopic(client)
|
channel.GetTopic(client)
|
||||||
|
reply := RplTopicMsg(client, channel)
|
||||||
|
client.Reply(reply)
|
||||||
|
channel.Reply(reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.topic = m.topic
|
channel.GetTopic(client)
|
||||||
|
return
|
||||||
channel.GetTopic(channel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PrivMsgCommand) HandleChannel(channel *Channel) {
|
func (m *PrivMsgCommand) HandleChannel(channel *Channel) {
|
||||||
|
@ -201,19 +201,18 @@ func (c *Client) ModeString() (str string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UserHost() string {
|
func (c *Client) UserHost() string {
|
||||||
nick := c.nick
|
username := "*"
|
||||||
if nick == "" {
|
if c.HasUsername() {
|
||||||
nick = "*"
|
username = c.username
|
||||||
}
|
}
|
||||||
username := c.username
|
return fmt.Sprintf("%s!%s@%s", c.Nick(), username, c.hostname)
|
||||||
if username == "" {
|
|
||||||
username = "*"
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s!%s@%s", nick, username, c.hostname)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Nick() string {
|
func (c *Client) Nick() string {
|
||||||
return c.nick
|
if c.HasNick() {
|
||||||
|
return c.nick
|
||||||
|
}
|
||||||
|
return "*"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Id() string {
|
func (c *Client) Id() string {
|
||||||
|
@ -357,8 +357,9 @@ func (m *PrivMsgCommand) TargetIsChannel() bool {
|
|||||||
|
|
||||||
type TopicCommand struct {
|
type TopicCommand struct {
|
||||||
BaseCommand
|
BaseCommand
|
||||||
channel string
|
channel string
|
||||||
topic string
|
setTopic bool
|
||||||
|
topic string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *TopicCommand) String() string {
|
func (cmd *TopicCommand) String() string {
|
||||||
@ -373,6 +374,7 @@ func NewTopicCommand(args []string) (editableCommand, error) {
|
|||||||
channel: args[0],
|
channel: args[0],
|
||||||
}
|
}
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
|
msg.setTopic = true
|
||||||
msg.topic = args[1]
|
msg.topic = args[1]
|
||||||
}
|
}
|
||||||
return msg, nil
|
return msg, nil
|
||||||
|
@ -162,18 +162,6 @@ const (
|
|||||||
ERR_UMODEUNKNOWNFLAG = 501
|
ERR_UMODEUNKNOWNFLAG = 501
|
||||||
ERR_USERSDONTMATCH = 502
|
ERR_USERSDONTMATCH = 502
|
||||||
|
|
||||||
// message codes
|
|
||||||
RPL_ERROR = "ERROR"
|
|
||||||
RPL_INVITE = "INVITE"
|
|
||||||
RPL_JOIN = "JOIN"
|
|
||||||
RPL_NICK = "NICK"
|
|
||||||
RPL_NOTICE = "NOTICE"
|
|
||||||
RPL_PART = "PART"
|
|
||||||
RPL_PING = "PING"
|
|
||||||
RPL_PONG = "PONG"
|
|
||||||
RPL_PRIVMSG = "PRIVMSG"
|
|
||||||
RPL_QUIT = "QUIT"
|
|
||||||
|
|
||||||
Add ModeOp = '+'
|
Add ModeOp = '+'
|
||||||
List ModeOp = '='
|
List ModeOp = '='
|
||||||
Remove ModeOp = '-'
|
Remove ModeOp = '-'
|
||||||
|
75
irc/reply.go
75
irc/reply.go
@ -24,25 +24,26 @@ func (reply *BaseReply) Source() Identifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StringReply struct {
|
type StringReply struct {
|
||||||
*BaseReply
|
BaseReply
|
||||||
code string
|
code string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStringReply(source Identifier, code string,
|
func NewStringReply(source Identifier, code string,
|
||||||
format string, args ...interface{}) *StringReply {
|
format string, args ...interface{}) *StringReply {
|
||||||
message := fmt.Sprintf(format, args...)
|
reply := &StringReply{
|
||||||
fullMessage := fmt.Sprintf(":%s %s %s", source.Id(), code, message)
|
|
||||||
return &StringReply{
|
|
||||||
BaseReply: &BaseReply{
|
|
||||||
source: source,
|
|
||||||
message: fullMessage,
|
|
||||||
},
|
|
||||||
code: code,
|
code: code,
|
||||||
}
|
}
|
||||||
|
reply.message = fmt.Sprintf(format, args...)
|
||||||
|
reply.source = source
|
||||||
|
return reply
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reply *StringReply) Format(client *Client) []string {
|
func (reply *StringReply) Format(client *Client) []string {
|
||||||
return []string{reply.message}
|
message := fmt.Sprintf("%s %s", reply.code, reply.message)
|
||||||
|
if Identifier(client.server) != reply.source {
|
||||||
|
message = fmt.Sprintf(":%s %s", reply.source.Id(), message)
|
||||||
|
}
|
||||||
|
return []string{message}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reply *StringReply) String() string {
|
func (reply *StringReply) String() string {
|
||||||
@ -51,25 +52,27 @@ func (reply *StringReply) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type NumericReply struct {
|
type NumericReply struct {
|
||||||
*BaseReply
|
BaseReply
|
||||||
code int
|
code int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNumericReply(source Identifier, code int, format string,
|
func NewNumericReply(source Identifier, code int, format string,
|
||||||
args ...interface{}) *NumericReply {
|
args ...interface{}) *NumericReply {
|
||||||
return &NumericReply{
|
reply := &NumericReply{
|
||||||
BaseReply: &BaseReply{source, fmt.Sprintf(format, args...)},
|
code: code,
|
||||||
code: code,
|
|
||||||
}
|
}
|
||||||
|
reply.message = fmt.Sprintf(format, args...)
|
||||||
|
reply.source = source
|
||||||
|
return reply
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reply *NumericReply) Format(client *Client) []string {
|
func (reply *NumericReply) Format(client *Client) []string {
|
||||||
return []string{reply.FormatString(client)}
|
message := fmt.Sprintf("%03d %s %s",
|
||||||
}
|
reply.code, client.Nick(), reply.message)
|
||||||
|
if Identifier(client.server) != reply.source {
|
||||||
func (reply *NumericReply) FormatString(client *Client) string {
|
message = fmt.Sprintf(":%s %s", reply.source.Id(), message)
|
||||||
return fmt.Sprintf(":%s %03d %s %s", reply.Source().Id(), reply.code,
|
}
|
||||||
client.Nick(), reply.message)
|
return []string{message}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reply *NumericReply) String() string {
|
func (reply *NumericReply) String() string {
|
||||||
@ -96,7 +99,7 @@ func NewNamesReply(channel *Channel) Reply {
|
|||||||
func (reply *NamesReply) Format(client *Client) []string {
|
func (reply *NamesReply) Format(client *Client) []string {
|
||||||
lines := make([]string, 0)
|
lines := make([]string, 0)
|
||||||
base := RplNamReply(reply.channel, []string{})
|
base := RplNamReply(reply.channel, []string{})
|
||||||
baseLen := len(base.FormatString(client))
|
baseLen := len(base.Format(client)[0])
|
||||||
tooLong := func(names []string) bool {
|
tooLong := func(names []string) bool {
|
||||||
return (baseLen + joinedLen(names)) > MAX_REPLY_LEN
|
return (baseLen + joinedLen(names)) > MAX_REPLY_LEN
|
||||||
}
|
}
|
||||||
@ -125,43 +128,47 @@ func (reply *NamesReply) String() string {
|
|||||||
// messaging replies
|
// messaging replies
|
||||||
|
|
||||||
func RplPrivMsg(source Identifier, target Identifier, message string) Reply {
|
func RplPrivMsg(source Identifier, target Identifier, message string) Reply {
|
||||||
return NewStringReply(source, RPL_PRIVMSG, "%s :%s", target.Nick(), message)
|
return NewStringReply(source, "PRIVMSG", "%s :%s", target.Nick(), message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplNotice(source Identifier, target Identifier, message string) Reply {
|
func RplNotice(source Identifier, target Identifier, message string) Reply {
|
||||||
return NewStringReply(source, RPL_NOTICE, "%s :%s", target.Nick(), message)
|
return NewStringReply(source, "NOTICE", "%s :%s", target.Nick(), message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplNick(source Identifier, newNick string) Reply {
|
func RplNick(source Identifier, newNick string) Reply {
|
||||||
return NewStringReply(source, RPL_NICK, newNick)
|
return NewStringReply(source, "NICK", newNick)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplJoin(client *Client, channel *Channel) Reply {
|
func RplJoin(client *Client, channel *Channel) Reply {
|
||||||
return NewStringReply(client, RPL_JOIN, channel.name)
|
return NewStringReply(client, "JOIN", channel.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplPart(client *Client, channel *Channel, message string) Reply {
|
func RplPart(client *Client, channel *Channel, message string) Reply {
|
||||||
return NewStringReply(client, RPL_PART, "%s :%s", channel.name, message)
|
return NewStringReply(client, "PART", "%s :%s", channel.name, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RplTopicMsg(source Identifier, channel *Channel) Reply {
|
||||||
|
return NewStringReply(source, "TOPIC", "%s :%s", channel.name, channel.topic)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplPing(server *Server, target Identifier) Reply {
|
func RplPing(server *Server, target Identifier) Reply {
|
||||||
return NewStringReply(server, RPL_PING, target.Nick())
|
return NewStringReply(server, "PING", target.Nick())
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplPong(server *Server, client *Client) Reply {
|
func RplPong(server *Server, client *Client) Reply {
|
||||||
return NewStringReply(server, RPL_PONG, client.Nick())
|
return NewStringReply(server, "PONG", client.Nick())
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplQuit(client *Client, message string) Reply {
|
func RplQuit(client *Client, message string) Reply {
|
||||||
return NewStringReply(client, RPL_QUIT, ":%s", message)
|
return NewStringReply(client, "QUIT", ":%s", message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplError(server *Server, target Identifier) Reply {
|
func RplError(server *Server, target Identifier) Reply {
|
||||||
return NewStringReply(server, RPL_ERROR, target.Nick())
|
return NewStringReply(server, "ERROR", target.Nick())
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplInviteMsg(channel *Channel, inviter *Client) Reply {
|
func RplInviteMsg(channel *Channel, inviter *Client) Reply {
|
||||||
return NewStringReply(inviter, RPL_INVITE, channel.name)
|
return NewStringReply(inviter, "INVITE", channel.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// numeric replies
|
// numeric replies
|
||||||
@ -222,7 +229,7 @@ func RplYoureOper(server *Server) Reply {
|
|||||||
|
|
||||||
func RplWhoisUser(server *Server, client *Client) Reply {
|
func RplWhoisUser(server *Server, client *Client) Reply {
|
||||||
return NewNumericReply(server, RPL_WHOISUSER, "%s %s %s * :%s",
|
return NewNumericReply(server, RPL_WHOISUSER, "%s %s %s * :%s",
|
||||||
client.nick, client.username, client.hostname, client.realname)
|
client.Nick(), client.username, client.hostname, client.realname)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplEndOfWhois(server *Server) Reply {
|
func RplEndOfWhois(server *Server) Reply {
|
||||||
@ -242,7 +249,7 @@ func RplWhoReply(server *Server, channel *Channel, client *Client) Reply {
|
|||||||
channelName = channel.name
|
channelName = channel.name
|
||||||
}
|
}
|
||||||
return NewNumericReply(server, RPL_WHOREPLY, "%s %s %s %s %s H :0 %s",
|
return NewNumericReply(server, RPL_WHOREPLY, "%s %s %s %s %s H :0 %s",
|
||||||
channelName, client.username, client.hostname, server.name, client.nick,
|
channelName, client.username, client.hostname, server.name, client.Nick(),
|
||||||
client.realname)
|
client.realname)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +279,7 @@ func RplUnAway(server *Server) Reply {
|
|||||||
|
|
||||||
func RplAway(server *Server, client *Client) Reply {
|
func RplAway(server *Server, client *Client) Reply {
|
||||||
return NewNumericReply(server, RPL_AWAY,
|
return NewNumericReply(server, RPL_AWAY,
|
||||||
"%s :%s", client.nick, client.awayMessage)
|
"%s :%s", client.Nick(), client.awayMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplIsOn(server *Server, nicks []string) Reply {
|
func RplIsOn(server *Server, nicks []string) Reply {
|
||||||
@ -331,7 +338,7 @@ func ErrNoSuchChannel(server *Server, channel string) Reply {
|
|||||||
|
|
||||||
func ErrUserOnChannel(channel *Channel, member *Client) Reply {
|
func ErrUserOnChannel(channel *Channel, member *Client) Reply {
|
||||||
return NewNumericReply(channel.server, ERR_USERONCHANNEL,
|
return NewNumericReply(channel.server, ERR_USERONCHANNEL,
|
||||||
"%s %s :is already on channel", member.nick, channel.name)
|
"%s %s :is already on channel", member.Nick(), channel.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrNotOnChannel(channel *Channel) Reply {
|
func ErrNotOnChannel(channel *Channel) Reply {
|
||||||
|
@ -348,7 +348,8 @@ func (m *PrivMsgCommand) HandleServer(s *Server) {
|
|||||||
|
|
||||||
func (m *ModeCommand) HandleServer(s *Server) {
|
func (m *ModeCommand) HandleServer(s *Server) {
|
||||||
client := m.Client()
|
client := m.Client()
|
||||||
if client.Nick() == m.nickname {
|
target := s.clients[m.nickname]
|
||||||
|
if client == target {
|
||||||
for _, change := range m.changes {
|
for _, change := range m.changes {
|
||||||
if change.mode == Invisible {
|
if change.mode == Invisible {
|
||||||
switch change.op {
|
switch change.op {
|
||||||
@ -363,7 +364,7 @@ func (m *ModeCommand) HandleServer(s *Server) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
client.Reply(ErrUsersDontMatch(client))
|
client.Reply(ErrUsersDontMatch(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *WhoisCommand) HandleServer(server *Server) {
|
func (m *WhoisCommand) HandleServer(server *Server) {
|
||||||
|
Loading…
Reference in New Issue
Block a user