本文整理匯總了Golang中github.com/fluffle/goirc/client.SimpleClient函數的典型用法代碼示例。如果您正苦於以下問題:Golang SimpleClient函數的具體用法?Golang SimpleClient怎麽用?Golang SimpleClient使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了SimpleClient函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CreateGobot
// Create a new Gobot from the given gesture config
func CreateGobot(config *Config) *Gobot {
bot := &Gobot{config.BotName, config, nil, make(chan bool), nil}
flag.Parse()
bot.client = irc.SimpleClient(config.BotName)
bot.client.SSL = config.SSL
bot.client.Flood = config.DisableFloodProtection
bot.client.EnableStateTracking()
bot.client.AddHandler(irc.CONNECTED,
func(conn *irc.Conn, line *irc.Line) {
log.Println("Connected to", config.Hostname, "!")
for _, channel := range config.Channels {
conn.Join(channel)
}
})
bot.client.AddHandler("JOIN", func(conn *irc.Conn, line *irc.Line) {
if line.Nick == bot.Name {
log.Printf("Joined %+v\n", line.Args)
}
})
bot.client.AddHandler(irc.DISCONNECTED, func(conn *irc.Conn, line *irc.Line) {
bot.quitter <- true
})
bot.client.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {
bot.messageReceived(conn, line)
})
return bot
}
示例2: Init
func Init() {
lock.Lock()
defer lock.Unlock()
if irc != nil {
return
}
if *server == "" {
// Don't call logging.Fatal as we don't want a backtrace in this case
logging.Error("--server option required. \nOptions are:\n")
flag.PrintDefaults()
os.Exit(1)
}
// Configure IRC client
irc = client.SimpleClient(*nick, "boing", "not really sp0rkle")
irc.SSL = *ssl
irc.Flood = true
HandleFunc(bot_connected, "connected")
HandleFunc(bot_disconnected, "disconnected")
// This is a special handler that dispatches commands from the command set
HandleFunc(bot_command, "privmsg")
// This is a special handler that triggers a rebuild and re-exec
HandleFunc(bot_rebuild, "notice")
// This is a special handler that triggers a shutdown and disconnect
HandleFunc(bot_shutdown, "notice")
CommandFunc(bot_help, "help", "If you need to ask, you're beyond help.")
}
示例3: main
func main() {
flag.Parse()
last_message = make(map[string]string)
c := irc.SimpleClient(*nick)
// Add handlers to do things here!
// e.g. join a channel on connect.
c.HandleFunc("connected",
func(conn *irc.Conn, line *irc.Line) {
log.Printf("Connected to %s as %s", c.Config().Server, c.Config().Me.Nick)
conn.Join(*channel)
})
// And a signal on disconnect
quit := make(chan bool)
c.HandleFunc("disconnected",
func(conn *irc.Conn, line *irc.Line) {
log.Print("Disconnected")
quit <- true
})
// Watch for messages
c.HandleFunc("PRIVMSG", privmsg)
// Tell client to connect.
if err := c.ConnectTo(*server); err != nil {
fmt.Printf("Connection error: %s\n", err)
return
}
// Wait for disconnect
<-quit
}
示例4: main
func main() {
if len(os.Args) != 4 {
log.Fatalf("Usage: %v nickname server channel", os.Args[0])
}
var nickname = os.Args[1]
var server = os.Args[2]
var channel = os.Args[3]
log.Printf("Running Pipo")
ns, err := nonsentence.New("nonsentence.db")
if err != nil {
log.Fatal(err)
}
defer ns.Close()
quit := make(chan bool)
client := irc.SimpleClient(nickname)
client.HandleFunc(irc.CONNECTED, func(conn *irc.Conn, line *irc.Line) {
conn.Join(channel)
})
client.HandleFunc(irc.DISCONNECTED, func(conn *irc.Conn, line *irc.Line) {
quit <- true
})
client.HandleFunc(irc.PRIVMSG, func(conn *irc.Conn, line *irc.Line) {
log.Printf("Message to %v: %v", line.Target(), line.Text())
// If a channel message is received, store it
if line.Target() == channel {
// If the message mentioned my name, reply
if strings.Contains(line.Text(), nickname) {
saySomething(client, channel, ns)
}
// Ignore first word if it ends with a ':'
var words = strings.Fields(line.Text())
if (len(words) > 0) && strings.HasSuffix(words[0], ":") {
words = words[1:]
}
if err := ns.Add(strings.Join(words, " ")); err != nil {
log.Printf("Error while adding sentence: %v", err)
}
} else if !strings.HasPrefix(line.Target(), "#") {
// If a private message is received, say something
saySomething(client, channel, ns)
}
})
log.Printf("Connecting...")
if err := client.ConnectTo(server); err != nil {
log.Fatal(err)
}
defer client.Quit("Terminating")
log.Printf("Connected!")
<-quit
}
示例5: main
func main() {
var p toml.Parser
d := p.ParseFile("config/app.conf")
twitch := Twitch{
host: d.GetString("twitch.host"),
user: d.GetString("twitch.user"),
token: d.GetString("twitch.token"),
channel: "#" + d.GetString("twitch.channel"),
}
in := make(chan Input)
go inputHandler(in)
// make sure emulator window is open
h := win32.FindWindow("DeSmuME", "DeSmuME 0.9.10 x64")
if h == nil {
panic("Couldn't find emulator window.")
}
fmt.Printf("Emulator Window: %v\n", h)
// connect to TwitchTV chat
c := irc.SimpleClient(twitch.user)
c.AddHandler("connected", func(conn *irc.Conn, line *irc.Line) {
c.Join(twitch.channel)
})
quit := make(chan bool)
c.AddHandler("disconnected", func(conn *irc.Conn, line *irc.Line) {
quit <- true
})
c.AddHandler("privmsg", func(conn *irc.Conn, line *irc.Line) {
if line.Args[0] != twitch.channel {
return
}
user, message := line.Nick, line.Args[1]
key, ok := validKeys[message]
if !ok {
return
}
in <- Input{
user: user,
message: message,
key: key,
}
})
if err := c.Connect(twitch.host, twitch.token); err != nil {
panic("Couldn't connect to TwitchTV.")
}
// keep the connection alive
<-quit
}
示例6: Connect
func Connect() {
conn = irc.SimpleClient("gmb0t", "gmb0t", "Game Master")
conn.EnableStateTracking()
conn.AddHandler("connected", postConnect)
conn.AddHandler("disconnected", func(c *irc.Conn, l *irc.Line) { Quit <- true })
conn.AddHandler("NOTICE", parseNotice)
go parseCommands()
conn.Connect(server)
}
示例7: main
func main() {
quit = make(chan bool)
c = irc.SimpleClient("cognito")
setupIRCHandlers()
if err := c.Connect(server); err != nil {
fmt.Printf("Connection error: %s\n", err.Error())
}
<-quit
}
示例8: Open
// Open opens the service and returns a channel which all messages will be sent on.
func (i *IRC) Open() (<-chan Message, error) {
i.Conn = client.SimpleClient(i.nick, i.nick, i.nick)
i.Conn.Config().Version = i.nick
i.Conn.Config().QuitMessage = ""
i.Conn.HandleFunc("connected", i.onConnect)
i.Conn.HandleFunc("disconnected", i.onDisconnect)
i.Conn.HandleFunc(client.PRIVMSG, i.onMessage)
go i.Conn.ConnectTo(i.host, i.password)
return i.messageChan, nil
}
示例9: Connect
func (i *IRC) Connect() {
c := irc.SimpleClient(i.Nick)
c.SSL = i.SSL
connected := make(chan bool)
c.AddHandler(irc.CONNECTED,
func(conn *irc.Conn, line *irc.Line) {
conn.Join(i.Channel)
connected <- true
})
c.Connect(i.Server)
<-connected
i.ClientStarted = true
i.Client = c
}
示例10: main
func main() {
flag.Parse()
readConfig(flag.Arg(0)) // config.go
client := irc.SimpleClient(config.Nick)
client.SSL = true
client.AddHandler("connected", connected)
client.AddHandler("privmsg", message)
client.AddHandler("disconnected", disconnected)
quit := make(chan bool)
err := client.Connect(config.Server)
if err != nil {
fmt.Printf("Connection Error: %s\n", err)
}
<-quit
}
示例11: NewMettbot
func NewMettbot(nick string, args ...string) *Mettbot {
bot := &Mettbot{
irc.SimpleClient(nick, args...), // *irc.Conn
make(chan bool), // Quitted
make(chan string), // QuotesPrnt
make(chan string), // MettsPrnt
make(chan int), // QuotesLinesPrnt
make(chan int), // MettsLinesPrnt
make(chan string, 4), // Input
make(chan bool), // IsMett
false, // ReallyQuit
make(map[string]string), // Topics
0, // MsgSinceMett
}
bot.EnableStateTracking()
return bot
}
示例12: main
func main() {
// prepare our zmq sockets
context, _ := zmq.NewContext()
reqsocket, _ := context.NewSocket(zmq.REQ)
subsocket, _ := context.NewSocket(zmq.SUB)
defer context.Close()
defer reqsocket.Close()
defer subsocket.Close()
reqsocket.Connect(REQ_SOCKET)
subsocket.SetSockOptString(zmq.SUBSCRIBE, SUB_KEY)
subsocket.Connect(SUB_SOCKET)
// configure our IRC client
c := irc.SimpleClient(NICK)
// most of the functionality is arranged by adding handlers
c.AddHandler("connected", func(conn *irc.Conn, line *irc.Line) {
conn.Join(CHANNEL)
sendMessage(reqsocket, statusMessage("joined "+CHANNEL))
// spawn a goroutine that will do the ZMQ -> IRC bridge
go zmqToIrcLoop(conn, subsocket)
})
quit := make(chan bool)
c.AddHandler("disconnected", func(conn *irc.Conn, line *irc.Line) {
sendMessage(reqsocket, statusMessage("disconnected"))
quit <- true
})
// this is the handler that gets triggered whenever someone posts
// in the channel
c.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {
// forward messages from IRC -> zmq PUB socket
if line.Nick != NICK {
sendMessage(reqsocket, Message{"message", line.Nick, line.Args[1]})
}
})
// Now we can connect
if err := c.Connect("irc.freenode.net"); err != nil {
sendMessage(reqsocket, statusMessage("error connecting: "+err.Error()))
fmt.Printf("Connection error: %s\n", err.Error())
}
// Wait for disconnect
<-quit
}
示例13: init
// init must be called first on a non-initialized irc
// client. It will connect with SSL to a given irc server using a given
// username, join a channel and wait for messages
func init() {
var err error
config, err = common.ReadConfigFrom(configurationFilename)
if err != nil {
panic(err)
}
// IRC INIT
Log("Create irc client")
ircClient = irc.SimpleClient(config.Get("ajaxchat", "user"))
ircClient.EnableStateTracking()
ircClient.SSL = true
ircClient.AddHandler(irc.CONNECTED, func(conn *irc.Conn, line *irc.Line) { conn.Join(ircChannel) })
ircClient.AddHandler(irc.DISCONNECTED, func(conn *irc.Conn, line *irc.Line) { Connect() })
ircClient.AddHandler("privmsg", func(conn *irc.Conn, line *irc.Line) { FromIrcMessage <- createMessageFromIrc(line) })
}
示例14: initServerConnection
func initServerConnection(server Server, quit chan bool) {
c := irc.SimpleClient(server.Nick)
c.SSL = server.SSL
c.SSLConfig = &tls.Config{InsecureSkipVerify: true}
c.AddHandler("connected",
func(conn *irc.Conn, line *irc.Line) {
for _, channel := range server.Channels {
conn.Join(channel)
}
})
c.AddHandler("disconnected", func(conn *irc.Conn, line *irc.Line) { quit <- true })
c.AddHandler("privmsg", func(conn *irc.Conn, line *irc.Line) {
matches := urlRegex.FindAllString(line.Args[1], -1)
for _, match := range matches {
if len(match) >= server.MinLength {
blacklist := false
for _, item := range server.Blacklist {
if strings.Contains(match, item) {
blacklist = true
continue
}
}
if blacklist {
continue
}
uri, err := goisgd.Shorten(match)
if err != nil {
continue
}
conn.Privmsg(line.Args[0], uri)
}
}
})
// Tell client to connect
if err := c.Connect(fmt.Sprintf("%s:%d", server.Server, server.Port), server.Password); err != nil {
fmt.Printf("Connection error: %v\n", err)
}
}
示例15: NewWeierBot
func NewWeierBot(server, nick, password string, channels []string) *WeierBot {
w := &WeierBot{
server: server,
client: irc.SimpleClient(nick),
log: make(chan Message, 512),
disconnect: make(chan bool),
}
w.client.Me.Name = nick
w.client.Me.Ident = nick
w.client.AddHandler("connected", func(conn *irc.Conn, line *irc.Line) {
if password != "" {
conn.Privmsg("NickServ", "identify "+password)
}
for _, ch := range channels {
log.Printf("Joining %s\n", ch)
conn.Join(ch)
}
})
w.client.AddHandler("disconnected", func(conn *irc.Conn, line *irc.Line) {
w.disconnect <- true
})
w.client.AddHandler("join", func(conn *irc.Conn, line *irc.Line) {
if len(line.Args) >= 1 && strings.HasPrefix(line.Args[0], "#") {
conn.Privmsg(line.Nick, fmt.Sprintf("Hallo %s, willkommen auf %s. "+
"Dieser Channel wird unter http://weierbot.tux21b.org/ mitgespeichert.",
line.Nick, line.Args[0]))
}
})
w.client.AddHandler("privmsg", func(conn *irc.Conn, line *irc.Line) {
if len(line.Args) < 2 {
return
}
w.handleMessage(line.Args[0], Message{
Nick: line.Nick,
Time: line.Time,
Message: line.Args[1],
})
})
go w.writeLog()
return w
}