Gisle Aune
7 years ago
8 changed files with 384 additions and 2 deletions
-
66channel.go
-
192client.go
-
16event.go
-
31list/list.go
-
8list/user.go
-
44query.go
-
20status.go
-
9target.go
@ -0,0 +1,66 @@ |
|||
package irc |
|||
|
|||
import "git.aiterp.net/gisle/irc/list" |
|||
|
|||
// A Channel is a target that manages the userlist
|
|||
type Channel struct { |
|||
name string |
|||
userlist list.List |
|||
} |
|||
|
|||
// Kind returns "channel"
|
|||
func (channel *Channel) Kind() string { |
|||
return "channel" |
|||
} |
|||
|
|||
// Name gets the channel name
|
|||
func (channel *Channel) Name() string { |
|||
return channel.name |
|||
} |
|||
|
|||
// UserList gets the channel userlist
|
|||
func (channel *Channel) UserList() list.Immutable { |
|||
return channel.userlist.Immutable() |
|||
} |
|||
|
|||
// Handle handles messages routed to this channel by the client's event loop
|
|||
func (channel *Channel) Handle(event *Event, client *Client) { |
|||
switch event.Name() { |
|||
case "packet.join": |
|||
{ |
|||
// Support extended-join
|
|||
account := "" |
|||
if accountArg := event.Arg(1); accountArg != "" && accountArg != "*" { |
|||
account = accountArg |
|||
} |
|||
|
|||
channel.userlist.Insert(list.User{ |
|||
Nick: event.Nick, |
|||
User: event.User, |
|||
Host: event.Host, |
|||
Account: account, |
|||
}) |
|||
} |
|||
case "packet.part", "packet.quit": |
|||
{ |
|||
channel.userlist.Remove(event.Nick) |
|||
} |
|||
case "packet.account": |
|||
{ |
|||
newAccount := event.Arg(0) |
|||
|
|||
if newAccount != "*" && newAccount != "" { |
|||
channel.userlist.Patch(event.Nick, list.UserPatch{Account: newAccount}) |
|||
} else { |
|||
channel.userlist.Patch(event.Nick, list.UserPatch{ClearAccount: true}) |
|||
} |
|||
} |
|||
case "packet.chghost": |
|||
{ |
|||
newUser := event.Arg(0) |
|||
newHost := event.Arg(1) |
|||
|
|||
channel.userlist.Patch(event.Nick, list.UserPatch{User: newUser, Host: newHost}) |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,44 @@ |
|||
package irc |
|||
|
|||
import ( |
|||
"git.aiterp.net/gisle/irc/list" |
|||
) |
|||
|
|||
// A Query is a target for direct messages to and from a specific nick.
|
|||
type Query struct { |
|||
user list.User |
|||
} |
|||
|
|||
// Kind returns "channel"
|
|||
func (query *Query) Kind() string { |
|||
return "query" |
|||
} |
|||
|
|||
// Name gets the query name
|
|||
func (query *Query) Name() string { |
|||
return query.user.Nick |
|||
} |
|||
|
|||
// Handle 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) |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,20 @@ |
|||
package irc |
|||
|
|||
// A Status contains
|
|||
type Status struct { |
|||
} |
|||
|
|||
// Kind returns "status"
|
|||
func (status *Status) Kind() string { |
|||
return "status" |
|||
} |
|||
|
|||
// Name returns "status"
|
|||
func (status *Status) Name() string { |
|||
return "Status" |
|||
} |
|||
|
|||
// Handle handles messages routed to this status by the client's event loop
|
|||
func (status *Status) Handle(event *Event, client *Client) { |
|||
|
|||
} |
@ -0,0 +1,9 @@ |
|||
package irc |
|||
|
|||
// A Target is a handler for a message meant for a limited part of the client, like a channel or
|
|||
// query
|
|||
type Target interface { |
|||
Kind() string |
|||
Name() string |
|||
Handle(event *Event, client *Client) |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue