Skip to content

Instantly share code, notes, and snippets.

@fuzzy
Last active August 29, 2015 14:10
Show Gist options
  • Save fuzzy/3b7faa00cb06def71565 to your computer and use it in GitHub Desktop.
Save fuzzy/3b7faa00cb06def71565 to your computer and use it in GitHub Desktop.
package main
import (
// Stdlib
"log"
// 3rd party
"github.com/husio/go-irc"
)
/////////////////////
// BotInstance Object
/////////////////////
type BotInstance struct {
address string
port string
channels []string
nick string
name string
conn irc.Client
err error
}
//////////////////////
// BotInstance methods
//////////////////////
// BotInstance.Connect()
func (b BotInstance) Connect() bool {
// If we have not been given an address error
if b.address == nil { return false } else {
// if we don't have a port, set the default
if b.port == nil { b.port = "6667" }
// if we don't have a nick, set the default
if b.nick == nil { b.nick = "GehenBot" }
// likewise with our name
if b.name == nil { b.name = b.nick }
// at this point, if we don't have a channel it isn't a showstopper
// but it doesn't make much sense either.
b.conn, b.err = irc.Connect(b.address)
if b.err != nil { log.Fatal(b.err) }
}
// well we made it
return true
}
// BotInstance.Nick(nick string)
func (b BotInstance) Nick(nick string) { b.conn.Send("NICK %s", nick) }
// BotInstance.User(name string)
func (b BotInstance) User(name string) { b.conn.Send("USER %s * * :...", b.name) }
// BotInstance.Join(chanName string)
func (b BotInstance) Join(chanName string) { b.conn.Send("JOIN %s", chanName) }
// BotInstance.Say(sendTo string, message string)
func (b BotInstance) Say(sndTo string, msg string) { b.conn.Send("PRIVMSG %s :%s\n", sndTo, msg) }
// BotInstance.Pong(msg string)
func (b BotInstance) Pong(msg string) { b.conn.Send("PONG %s", msg) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment