properly quit irc after sending failure/success

This commit is contained in:
Jordan Evans 2014-02-27 12:00:15 -08:00
parent 25749802ac
commit bab544261a

View file

@ -34,16 +34,11 @@ func (i *IRC) Connect() {
connected <- true})
c.Connect(i.Server)
<-connected
i.Client = c
i.ClientStarted = true
i.Client = c
}
func (i *IRC) Send(context *Context) error {
if !i.ClientStarted {
i.Connect()
}
switch {
case context.Commit.Status == "Started" && i.Started:
return i.sendStarted(context)
@ -64,17 +59,26 @@ func (i *IRC) sendStarted(context *Context) error {
func (i *IRC) sendFailure(context *Context) error {
msg := fmt.Sprintf(ircFailureMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
i.send(i.Channel, msg)
if i.ClientStarted {
i.Client.Quit()
}
return nil
}
func (i *IRC) sendSuccess(context *Context) error {
msg := fmt.Sprintf(ircSuccessMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
i.send(i.Channel, msg)
if i.ClientStarted {
i.Client.Quit()
}
return nil
}
func (i *IRC) send(channel string, message string) error {
if !i.ClientStarted {
i.Connect()
}
i.Client.Notice(channel, message)
return nil
}