mirror of
https://github.com/gissleh/irc.git
synced 2026-10-15 16:42:53 +00:00
Fixed NICK handler not firing, added away-notify w/tests
This commit is contained in:
+12
@@ -49,6 +49,10 @@ func (channel *Channel) Handle(event *Event, client *Client) {
|
|||||||
{
|
{
|
||||||
channel.userlist.Remove(event.Nick)
|
channel.userlist.Remove(event.Nick)
|
||||||
}
|
}
|
||||||
|
case "packet.nick":
|
||||||
|
{
|
||||||
|
channel.userlist.Rename(event.Nick, event.Arg(0))
|
||||||
|
}
|
||||||
case "packet.account":
|
case "packet.account":
|
||||||
{
|
{
|
||||||
newAccount := event.Arg(0)
|
newAccount := event.Arg(0)
|
||||||
@@ -59,6 +63,14 @@ func (channel *Channel) Handle(event *Event, client *Client) {
|
|||||||
channel.userlist.Patch(event.Nick, list.UserPatch{ClearAccount: true})
|
channel.userlist.Patch(event.Nick, list.UserPatch{ClearAccount: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case "packet.away":
|
||||||
|
{
|
||||||
|
if event.Text != "" {
|
||||||
|
channel.userlist.Patch(event.Nick, list.UserPatch{Away: event.Text})
|
||||||
|
} else {
|
||||||
|
channel.userlist.Patch(event.Nick, list.UserPatch{ClearAway: true})
|
||||||
|
}
|
||||||
|
}
|
||||||
case "packet.chghost":
|
case "packet.chghost":
|
||||||
{
|
{
|
||||||
newUser := event.Arg(0)
|
newUser := event.Arg(0)
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ var supportedCaps = []string{
|
|||||||
"multi-prefix",
|
"multi-prefix",
|
||||||
"userhost-in-names",
|
"userhost-in-names",
|
||||||
"account-notify",
|
"account-notify",
|
||||||
|
"away-notify",
|
||||||
"extended-join",
|
"extended-join",
|
||||||
"chghost",
|
"chghost",
|
||||||
}
|
}
|
||||||
@@ -630,7 +631,7 @@ func (client *Client) handleEvent(event *Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case "packer.nick":
|
case "packet.nick":
|
||||||
{
|
{
|
||||||
client.handleInTargets(event.Nick, event)
|
client.handleInTargets(event.Nick, event)
|
||||||
|
|
||||||
@@ -858,11 +859,17 @@ func (client *Client) handleEvent(event *Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Account handling
|
// account-notify
|
||||||
case "packet.account":
|
case "packet.account":
|
||||||
{
|
{
|
||||||
client.handleInTargets(event.Nick, event)
|
client.handleInTargets(event.Nick, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// away-notify
|
||||||
|
case "packet.away":
|
||||||
|
{
|
||||||
|
client.handleInTargets(event.Nick, event)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(event.targets) == 0 {
|
if len(event.targets) == 0 {
|
||||||
|
|||||||
+39
-1
@@ -71,7 +71,7 @@ func TestClient(t *testing.T) {
|
|||||||
{Kind: 'S', Data: ":Gisle!~irce@10.32.0.1 MODE #Test +N-s "},
|
{Kind: 'S', Data: ":Gisle!~irce@10.32.0.1 MODE #Test +N-s "},
|
||||||
{Kind: 'S', Data: ":Test1234!~test2@172.17.37.1 JOIN #Test Test1234"},
|
{Kind: 'S', Data: ":Test1234!~test2@172.17.37.1 JOIN #Test Test1234"},
|
||||||
{Kind: 'S', Data: ":Gisle!~irce@10.32.0.1 MODE #Test +v Test1234"},
|
{Kind: 'S', Data: ":Gisle!~irce@10.32.0.1 MODE #Test +v Test1234"},
|
||||||
{Kind: 'S', Data: "PING :archgisle.lan"},
|
{Kind: 'S', Data: "PING :archgisle.lan"}, // Ping/Pong to sync.
|
||||||
{Kind: 'C', Data: "PONG :archgisle.lan"},
|
{Kind: 'C', Data: "PONG :archgisle.lan"},
|
||||||
{Callback: func() error {
|
{Callback: func() error {
|
||||||
channel := client.Channel("#Test")
|
channel := client.Channel("#Test")
|
||||||
@@ -92,6 +92,44 @@ func TestClient(t *testing.T) {
|
|||||||
return errors.New("Test1234 did not get account from extended-join")
|
return errors.New("Test1234 did not get account from extended-join")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}},
|
||||||
|
{Kind: 'S', Data: ":Test1234!~test2@172.17.37.1 NICK Hunter2"},
|
||||||
|
{Kind: 'S', Data: ":Hunter2!~test2@172.17.37.1 AWAY :Doing stuff"},
|
||||||
|
{Kind: 'S', Data: ":Gisle!~irce@10.32.0.1 AWAY"},
|
||||||
|
{Kind: 'S', Data: ":Gisle!~irce@10.32.0.1 PART #Test :Leaving the channel"},
|
||||||
|
{Kind: 'S', Data: "PING :archgisle.lan"}, // Ping/Pong to sync.
|
||||||
|
{Kind: 'C', Data: "PONG :archgisle.lan"},
|
||||||
|
{Callback: func() error {
|
||||||
|
channel := client.Channel("#Test")
|
||||||
|
if channel == nil {
|
||||||
|
return errors.New("Channel #Test not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
err := irctest.AssertUserlist(t, channel, "@Test768", "+Hunter2")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, ok := channel.UserList().User("Test1234")
|
||||||
|
if ok {
|
||||||
|
return errors.New("Test1234 is still there")
|
||||||
|
}
|
||||||
|
|
||||||
|
userHunter2, ok := channel.UserList().User("Hunter2")
|
||||||
|
if !ok {
|
||||||
|
return errors.New("Test1234 not found")
|
||||||
|
}
|
||||||
|
if userHunter2.Account != "Test1234" {
|
||||||
|
return errors.New("Hunter2 did not persist account post nick change")
|
||||||
|
}
|
||||||
|
if !userHunter2.IsAway() {
|
||||||
|
return errors.New("Hunter2 should be away")
|
||||||
|
}
|
||||||
|
if userHunter2.Away != "Doing stuff" {
|
||||||
|
return errors.New("Hunter2 has the wrong away message: " + userHunter2.Away)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -253,6 +253,10 @@ func (list *List) Patch(nick string, patch UserPatch) (ok bool) {
|
|||||||
user.Account = patch.Account
|
user.Account = patch.Account
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if patch.Away != "" || patch.ClearAway {
|
||||||
|
user.Away = patch.Away
|
||||||
|
}
|
||||||
|
|
||||||
if patch.User != "" {
|
if patch.User != "" {
|
||||||
user.User = patch.User
|
user.User = patch.User
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ type User struct {
|
|||||||
User string `json:"user,omitempty"`
|
User string `json:"user,omitempty"`
|
||||||
Host string `json:"host,omitempty"`
|
Host string `json:"host,omitempty"`
|
||||||
Account string `json:"account,omitempty"`
|
Account string `json:"account,omitempty"`
|
||||||
|
Away string `json:"away,omitempty"`
|
||||||
Modes string `json:"modes"`
|
Modes string `json:"modes"`
|
||||||
Prefixes string `json:"prefixes"`
|
Prefixes string `json:"prefixes"`
|
||||||
PrefixedNick string `json:"prefixedNick"`
|
PrefixedNick string `json:"prefixedNick"`
|
||||||
@@ -17,6 +18,8 @@ type UserPatch struct {
|
|||||||
Host string
|
Host string
|
||||||
Account string
|
Account string
|
||||||
ClearAccount bool
|
ClearAccount bool
|
||||||
|
Away string
|
||||||
|
ClearAway bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// HighestMode returns the highest mode.
|
// HighestMode returns the highest mode.
|
||||||
@@ -28,6 +31,11 @@ func (user *User) HighestMode() rune {
|
|||||||
return rune(user.Modes[0])
|
return rune(user.Modes[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsAway returns true if user.Away is non-empty
|
||||||
|
func (user *User) IsAway() bool {
|
||||||
|
return user.Away != ""
|
||||||
|
}
|
||||||
|
|
||||||
// PrefixedNick gets the full nick.
|
// PrefixedNick gets the full nick.
|
||||||
func (user *User) updatePrefixedNick() {
|
func (user *User) updatePrefixedNick() {
|
||||||
if len(user.Prefixes) == 0 {
|
if len(user.Prefixes) == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user