mirror of https://github.com/fluffle/goirc
add nick search by hostmask
This commit is contained in:
parent
c981f8f568
commit
c86f5d58eb
|
@ -1,6 +1,8 @@
|
||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/fluffle/goirc/logging"
|
"github.com/fluffle/goirc/logging"
|
||||||
|
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -11,6 +13,7 @@ type Tracker interface {
|
||||||
// Nick methods
|
// Nick methods
|
||||||
NewNick(nick string) *Nick
|
NewNick(nick string) *Nick
|
||||||
GetNick(nick string) *Nick
|
GetNick(nick string) *Nick
|
||||||
|
GetNickByHostmask(host string) *Nick
|
||||||
ReNick(old, neu string) *Nick
|
ReNick(old, neu string) *Nick
|
||||||
DelNick(nick string) *Nick
|
DelNick(nick string) *Nick
|
||||||
NickInfo(nick, ident, host, name string) *Nick
|
NickInfo(nick, ident, host, name string) *Nick
|
||||||
|
@ -100,6 +103,18 @@ func (st *stateTracker) GetNick(n string) *Nick {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a nick for the hostmask h, if we're tracking it.
|
||||||
|
func (st *stateTracker) GetNickByHostmask(h string) *Nick {
|
||||||
|
st.mu.Lock()
|
||||||
|
defer st.mu.Unlock()
|
||||||
|
for n := range st.nicks {
|
||||||
|
if fmt.Sprintf("%s@%s", st.nicks[n].ident, st.nicks[n].host) == h {
|
||||||
|
return st.nicks[n].Nick()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Signals to the tracker that a nick should be tracked
|
// Signals to the tracker that a nick should be tracked
|
||||||
// under a "neu" nick rather than the old one.
|
// under a "neu" nick rather than the old one.
|
||||||
func (st *stateTracker) ReNick(old, neu string) *Nick {
|
func (st *stateTracker) ReNick(old, neu string) *Nick {
|
||||||
|
|
|
@ -58,6 +58,22 @@ func TestSTGetNick(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSTGetNickByHostmask(t *testing.T) {
|
||||||
|
st := NewTracker("mynick")
|
||||||
|
test1 := st.NewNick("test1")
|
||||||
|
test1 = st.NickInfo("test1", "test", "test", "test")
|
||||||
|
|
||||||
|
if n := st.GetNickByHostmask("test@test"); !test1.Equals(n) {
|
||||||
|
t.Errorf("Incorrect nick returned by GetNickByHostmask.")
|
||||||
|
}
|
||||||
|
if n := st.GetNickByHostmask("test2@test"); n != nil {
|
||||||
|
t.Errorf("Nick unexpectedly returned by GetNickByHostmask.")
|
||||||
|
}
|
||||||
|
if len(st.nicks) != 2 {
|
||||||
|
t.Errorf("Nick list changed size during GetNickByHostmask.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSTReNick(t *testing.T) {
|
func TestSTReNick(t *testing.T) {
|
||||||
st := NewTracker("mynick")
|
st := NewTracker("mynick")
|
||||||
test1 := st.NewNick("test1")
|
test1 := st.NewNick("test1")
|
||||||
|
|
Loading…
Reference in New Issue