kunt

golang IRC bot
git clone git://git.2f30.org/kunt
Log | Files | Refs | LICENSE

commit eae639bb78048f812ec83c72aea87db48d04deb0
parent 24134d94b0594db52df863783a980ff5179b10eb
Author: sin <sin@2f30.org>
Date:   Wed,  8 May 2013 16:12:08 +0100

remove AddChannel() and JoinChannels() - use only JoinChannel()

Diffstat:
Msrc/irc/irc.go | 41++++++++++++++++-------------------------
Msrc/kunt/kunt.go | 3+--
2 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/src/irc/irc.go b/src/irc/irc.go @@ -90,38 +90,29 @@ func (i *IrcContext) DelIntercept(ap *chan IrcMessage) error { return fmt.Errorf("Intercept not found") } -func (i *IrcContext) AddChannel(s string, key string) error { +func (i *IrcContext) JoinChannel(channel string, key string) error { + found := false for _, v := range i.network.channels { - if v.name == s { - return fmt.Errorf("Channel %s already added", s) + if v.name == channel { + found = true + break } } - i.network.channels = append(i.network.channels, ircChan{s, key, false}) - return nil -} - -func (i *IrcContext) JoinChannel(s string) error { - for c, v := range i.network.channels { - if v.name == s { - if !v.joined { - i.Join(v.name, v.key) - i.network.channels[c].joined = true - return nil - } else { - return fmt.Errorf("Already joined on channel %s", s) - } - } + if !found { + i.network.channels = append(i.network.channels, + ircChan{channel, key, false}) } - return fmt.Errorf("Can't find channel %s", s) -} - -func (i *IrcContext) JoinChannels() error { for c, v := range i.network.channels { + if v.name != channel { + continue + } if !v.joined { - if err := i.JoinChannel(v.name); err != nil { - return err - } + i.Join(v.name, v.key) i.network.channels[c].joined = true + return nil + } else { + return fmt.Errorf("Already joined channel %s", + channel) } } return nil diff --git a/src/kunt/kunt.go b/src/kunt/kunt.go @@ -391,8 +391,7 @@ func main() { log.Fatal(err) } kunt.ircCtx.Login() - kunt.ircCtx.AddChannel("#2f30", "") - kunt.ircCtx.JoinChannels() + kunt.ircCtx.JoinChannel("#2f30", "") donechan := make(chan bool) select {