mirror of
https://github.com/fluffle/goirc
synced 2025-07-07 14:00:33 +00:00
Remove golog
This commit is contained in:
parent
06a9cb5d0f
commit
2cbbdd6d7e
8 changed files with 3 additions and 124 deletions
|
@ -2,7 +2,6 @@ package state
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fluffle/golog/logging"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
|
@ -121,8 +120,6 @@ func (ch *Channel) addNick(nk *Nick, cp *ChanPrivs) {
|
|||
if _, ok := ch.nicks[nk]; !ok {
|
||||
ch.nicks[nk] = cp
|
||||
ch.lookup[nk.Nick] = nk
|
||||
} else {
|
||||
logging.Warn("Channel.addNick(): %s already on %s.", nk.Nick, ch.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,23 +128,18 @@ func (ch *Channel) delNick(nk *Nick) {
|
|||
if _, ok := ch.nicks[nk]; ok {
|
||||
delete(ch.nicks, nk)
|
||||
delete(ch.lookup, nk.Nick)
|
||||
} else {
|
||||
logging.Warn("Channel.delNick(): %s not on %s.", nk.Nick, ch.Name)
|
||||
}
|
||||
}
|
||||
|
||||
// Parses mode strings for a channel.
|
||||
func (ch *Channel) ParseModes(modes string, modeargs ...string) {
|
||||
var modeop bool // true => add mode, false => remove mode
|
||||
var modestr string
|
||||
for i := 0; i < len(modes); i++ {
|
||||
switch m := modes[i]; m {
|
||||
case '+':
|
||||
modeop = true
|
||||
modestr = string(m)
|
||||
case '-':
|
||||
modeop = false
|
||||
modestr = string(m)
|
||||
case 'i':
|
||||
ch.Modes.InviteOnly = modeop
|
||||
case 'm':
|
||||
|
@ -173,9 +165,6 @@ func (ch *Channel) ParseModes(modes string, modeargs ...string) {
|
|||
ch.Modes.Key, modeargs = modeargs[0], modeargs[1:]
|
||||
} else if !modeop {
|
||||
ch.Modes.Key = ""
|
||||
} else {
|
||||
logging.Warn("Channel.ParseModes(): not enough arguments to "+
|
||||
"process MODE %s %s%c", ch.Name, modestr, m)
|
||||
}
|
||||
case 'l':
|
||||
if modeop && len(modeargs) != 0 {
|
||||
|
@ -183,9 +172,6 @@ func (ch *Channel) ParseModes(modes string, modeargs ...string) {
|
|||
modeargs = modeargs[1:]
|
||||
} else if !modeop {
|
||||
ch.Modes.Limit = 0
|
||||
} else {
|
||||
logging.Warn("Channel.ParseModes(): not enough arguments to "+
|
||||
"process MODE %s %s%c", ch.Name, modestr, m)
|
||||
}
|
||||
case 'q', 'a', 'o', 'h', 'v':
|
||||
if len(modeargs) != 0 {
|
||||
|
@ -204,16 +190,8 @@ func (ch *Channel) ParseModes(modes string, modeargs ...string) {
|
|||
cp.Voice = modeop
|
||||
}
|
||||
modeargs = modeargs[1:]
|
||||
} else {
|
||||
logging.Warn("Channel.ParseModes(): untracked nick %s "+
|
||||
"received MODE on channel %s", modeargs[0], ch.Name)
|
||||
}
|
||||
} else {
|
||||
logging.Warn("Channel.ParseModes(): not enough arguments to "+
|
||||
"process MODE %s %s%c", ch.Name, modestr, m)
|
||||
}
|
||||
default:
|
||||
logging.Info("Channel.ParseModes(): unknown mode char %c", m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package state
|
||||
|
||||
import (
|
||||
"github.com/fluffle/golog/logging"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
|
@ -69,8 +68,6 @@ func (nk *Nick) addChannel(ch *Channel, cp *ChanPrivs) {
|
|||
if _, ok := nk.chans[ch]; !ok {
|
||||
nk.chans[ch] = cp
|
||||
nk.lookup[ch.Name] = ch
|
||||
} else {
|
||||
logging.Warn("Nick.addChannel(): %s already on %s.", nk.Nick, ch.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,8 +76,6 @@ func (nk *Nick) delChannel(ch *Channel) {
|
|||
if _, ok := nk.chans[ch]; ok {
|
||||
delete(nk.chans, ch)
|
||||
delete(nk.lookup, ch.Name)
|
||||
} else {
|
||||
logging.Warn("Nick.delChannel(): %s not on %s.", nk.Nick, ch.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,8 +100,6 @@ func (nk *Nick) ParseModes(modes string) {
|
|||
nk.Modes.HiddenHost = modeop
|
||||
case 'z':
|
||||
nk.Modes.SSL = modeop
|
||||
default:
|
||||
logging.Info("Nick.ParseModes(): unknown mode char %c", m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package state
|
||||
|
||||
import (
|
||||
"github.com/fluffle/golog/logging"
|
||||
)
|
||||
|
||||
// The state manager interface
|
||||
type Tracker interface {
|
||||
// Nick methods
|
||||
|
@ -63,7 +59,6 @@ func (st *stateTracker) Wipe() {
|
|||
// can be properly tracked for state management purposes.
|
||||
func (st *stateTracker) NewNick(n string) *Nick {
|
||||
if _, ok := st.nicks[n]; ok {
|
||||
logging.Warn("Tracker.NewNick(): %s already tracked.", n)
|
||||
return nil
|
||||
}
|
||||
st.nicks[n] = NewNick(n)
|
||||
|
@ -92,11 +87,7 @@ func (st *stateTracker) ReNick(old, neu string) {
|
|||
delete(ch.lookup, old)
|
||||
ch.lookup[neu] = nk
|
||||
}
|
||||
} else {
|
||||
logging.Warn("Tracker.ReNick(): %s already exists.", neu)
|
||||
}
|
||||
} else {
|
||||
logging.Warn("Tracker.ReNick(): %s not tracked.", old)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,30 +96,19 @@ func (st *stateTracker) DelNick(n string) {
|
|||
if nk, ok := st.nicks[n]; ok {
|
||||
if nk != st.me {
|
||||
st.delNick(nk)
|
||||
} else {
|
||||
logging.Warn("Tracker.DelNick(): won't delete myself.")
|
||||
}
|
||||
} else {
|
||||
logging.Warn("Tracker.DelNick(): %s not tracked.", n)
|
||||
}
|
||||
}
|
||||
|
||||
func (st *stateTracker) delNick(nk *Nick) {
|
||||
if nk == st.me {
|
||||
// Shouldn't get here => internal state tracking code is fubar.
|
||||
logging.Error("Tracker.DelNick(): TRYING TO DELETE ME :-(")
|
||||
return
|
||||
}
|
||||
delete(st.nicks, nk.Nick)
|
||||
for ch, _ := range nk.chans {
|
||||
nk.delChannel(ch)
|
||||
ch.delNick(nk)
|
||||
if len(ch.nicks) == 0 {
|
||||
// Deleting a nick from tracking shouldn't empty any channels as
|
||||
// *we* should be on the channel with them to be tracking them.
|
||||
logging.Error("Tracker.delNick(): deleting nick %s emptied "+
|
||||
"channel %s, this shouldn't happen!", nk.Nick, ch.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,7 +116,6 @@ func (st *stateTracker) delNick(nk *Nick) {
|
|||
// can be properly tracked for state management purposes.
|
||||
func (st *stateTracker) NewChannel(c string) *Channel {
|
||||
if _, ok := st.chans[c]; ok {
|
||||
logging.Warn("Tracker.NewChannel(): %s already tracked.", c)
|
||||
return nil
|
||||
}
|
||||
st.chans[c] = NewChannel(c)
|
||||
|
@ -155,8 +134,6 @@ func (st *stateTracker) GetChannel(c string) *Channel {
|
|||
func (st *stateTracker) DelChannel(c string) {
|
||||
if ch, ok := st.chans[c]; ok {
|
||||
st.delChannel(ch)
|
||||
} else {
|
||||
logging.Warn("Tracker.DelChannel(): %s not tracked.", c)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,22 +168,15 @@ func (st *stateTracker) IsOn(c, n string) (*ChanPrivs, bool) {
|
|||
// Associates an already known nick with an already known channel.
|
||||
func (st *stateTracker) Associate(ch *Channel, nk *Nick) *ChanPrivs {
|
||||
if ch == nil || nk == nil {
|
||||
logging.Error("Tracker.Associate(): passed nil values :-(")
|
||||
return nil
|
||||
} else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch {
|
||||
// As we can implicitly delete both nicks and channels from being
|
||||
// tracked by dissociating one from the other, we should verify that
|
||||
// we're not being passed an old Nick or Channel.
|
||||
logging.Error("Tracker.Associate(): channel %s not found in "+
|
||||
"(or differs from) internal state.", ch.Name)
|
||||
return nil
|
||||
} else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk {
|
||||
logging.Error("Tracker.Associate(): nick %s not found in "+
|
||||
"(or differs from) internal state.", nk.Nick)
|
||||
return nil
|
||||
} else if _, ok := nk.IsOn(ch); ok {
|
||||
logging.Warn("Tracker.Associate(): %s already on %s.",
|
||||
nk.Nick, ch.Name)
|
||||
return nil
|
||||
}
|
||||
cp := new(ChanPrivs)
|
||||
|
@ -220,19 +190,12 @@ func (st *stateTracker) Associate(ch *Channel, nk *Nick) *ChanPrivs {
|
|||
// any common channels with, and channels we're no longer on.
|
||||
func (st *stateTracker) Dissociate(ch *Channel, nk *Nick) {
|
||||
if ch == nil || nk == nil {
|
||||
logging.Error("Tracker.Dissociate(): passed nil values :-(")
|
||||
} else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch {
|
||||
// As we can implicitly delete both nicks and channels from being
|
||||
// tracked by dissociating one from the other, we should verify that
|
||||
// we're not being passed an old Nick or Channel.
|
||||
logging.Error("Tracker.Dissociate(): channel %s not found in "+
|
||||
"(or differs from) internal state.", ch.Name)
|
||||
} else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk {
|
||||
logging.Error("Tracker.Dissociate(): nick %s not found in "+
|
||||
"(or differs from) internal state.", nk.Nick)
|
||||
} else if _, ok := nk.IsOn(ch); !ok {
|
||||
logging.Warn("Tracker.Dissociate(): %s not on %s.",
|
||||
nk.Nick, ch.Name)
|
||||
} else if nk == st.me {
|
||||
// I'm leaving the channel for some reason, so it won't be tracked.
|
||||
st.delChannel(ch)
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
package state
|
||||
|
||||
import (
|
||||
"github.com/fluffle/golog/logging"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// This is probably a dirty hack...
|
||||
logging.InitFromFlags()
|
||||
logging.SetLogLevel(logging.LogFatal)
|
||||
}
|
||||
|
||||
func TestSTNewTracker(t *testing.T) {
|
||||
st := NewTracker("mynick")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue