Files
irc/query.go
T
gisle 714b80d6e7
continuous-integration/drone/push Build is passing
rework target ID handling to be less clunky.
2020-11-01 17:23:37 +01:00

59 lines
1.1 KiB
Go

package irc
import (
"github.com/gissleh/irc/list"
)
// A Query is a target for direct messages to and from a specific nick.
type Query struct {
id string
user list.User
}
// ID returns a unique ID for the channel target.
func (query *Query) ID() string {
return query.id
}
// Kind returns "channel"
func (query *Query) Kind() string {
return "query"
}
// Name gets the query name
func (query *Query) Name() string {
return query.user.Nick
}
func (query *Query) State() ClientStateTarget {
return ClientStateTarget{
Kind: "query",
Name: query.user.Nick,
Users: []list.User{query.user},
}
}
// AddHandler handles messages routed to this channel by the client's event loop
func (query *Query) Handle(event *Event, client *Client) {
switch event.Name() {
case "packet.nick":
{
query.user.Nick = event.Arg(0)
}
case "packet.account":
{
account := ""
if accountArg := event.Arg(0); accountArg != "" && accountArg != "*" {
account = accountArg
}
query.user.Account = account
}
case "packet.chghost":
{
query.user.User = event.Arg(0)
query.user.Host = event.Arg(1)
}
}
}