Add AWAY command support

This commit is contained in:
Sergey Matveev 2014-11-14 23:26:32 +03:00
parent 990937d451
commit 8702ace766
3 changed files with 16 additions and 2 deletions

2
README
View File

@ -40,7 +40,7 @@ SUPPORTED IRC COMMANDS
* PASS/NICK/USER during registration workflow * PASS/NICK/USER during registration workflow
* PING/PONGs * PING/PONGs
* NOTICE/PRIVMSG * NOTICE/PRIVMSG
* MOTD, LUSERS, WHO, WHOIS, VERSION, QUIT * AWAY, MOTD, LUSERS, WHO, WHOIS, VERSION, QUIT
* LIST, JOIN, TOPIC, +k/-k channel MODE * LIST, JOIN, TOPIC, +k/-k channel MODE
USAGE USAGE

View File

@ -38,6 +38,7 @@ type Client struct {
username string username string
realname string realname string
password string password string
away *string
} }
type ClientAlivenessState struct { type ClientAlivenessState struct {

View File

@ -111,6 +111,9 @@ func (daemon *Daemon) SendWhois(client *Client, nicknames []string) {
} }
client.ReplyNicknamed("311", c.nickname, c.username, h, "*", c.realname) client.ReplyNicknamed("311", c.nickname, c.username, h, "*", c.realname)
client.ReplyNicknamed("312", c.nickname, *daemon.hostname, *daemon.hostname) client.ReplyNicknamed("312", c.nickname, *daemon.hostname, *daemon.hostname)
if c.away != nil {
client.ReplyNicknamed("301", c.nickname, *c.away)
}
subscriptions := []string{} subscriptions := []string{}
for _, room := range daemon.rooms { for _, room := range daemon.rooms {
for subscriber := range room.members { for subscriber := range room.members {
@ -347,7 +350,14 @@ func (daemon *Daemon) Processor(events <-chan ClientEvent) {
} }
switch command { switch command {
case "AWAY": case "AWAY":
if len(cols) == 1 {
client.away = nil
client.ReplyNicknamed("305", "You are no longer marked as being away")
continue continue
}
msg := strings.TrimLeft(cols[1], ":")
client.away = &msg
client.ReplyNicknamed("306", "You have been marked as being away")
case "JOIN": case "JOIN":
if len(cols) == 1 || len(cols[1]) < 1 { if len(cols) == 1 || len(cols[1]) < 1 {
client.ReplyNotEnoughParameters("JOIN") client.ReplyNotEnoughParameters("JOIN")
@ -422,6 +432,9 @@ func (daemon *Daemon) Processor(events <-chan ClientEvent) {
if c.nickname == target { if c.nickname == target {
msg = fmt.Sprintf(":%s %s %s %s", client, command, c.nickname, cols[1]) msg = fmt.Sprintf(":%s %s %s %s", client, command, c.nickname, cols[1])
c.Msg(msg) c.Msg(msg)
if c.away != nil {
client.ReplyNicknamed("301", c.nickname, *c.away)
}
break break
} }
} }