2016-04-02 01:27:48 +00:00
|
|
|
// +build ignore
|
|
|
|
|
|
|
|
// This sample file demonstrates use of the libnmdc.go library. It's excluded
|
|
|
|
// when building the library package, but you can run it via `go run libnmdc_sample.go`.
|
2016-11-29 06:30:33 +00:00
|
|
|
// This version demonstrates the channel API.
|
2016-04-02 01:27:48 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"libnmdc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
opts := libnmdc.HubConnectionOptions{
|
|
|
|
Address: "127.0.0.1",
|
2016-11-29 06:25:41 +00:00
|
|
|
Self: libnmdc.NewUserInfo("slowpoke9"),
|
2016-04-02 01:27:48 +00:00
|
|
|
}
|
|
|
|
hub := opts.Connect()
|
|
|
|
|
|
|
|
for {
|
|
|
|
event := <-hub.OnEvent
|
|
|
|
switch event.EventType {
|
|
|
|
case libnmdc.EVENT_CONNECTION_STATE_CHANGED:
|
|
|
|
fmt.Printf("Connection -- %s (%s)\n", event.StateChange.Format(), event.Message)
|
|
|
|
|
|
|
|
case libnmdc.EVENT_PUBLIC:
|
|
|
|
fmt.Printf("Message from '%s': '%s'\n", event.Nick, event.Message)
|
|
|
|
if event.Message == "how are you" {
|
|
|
|
hub.SayPublic("good thanks!")
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
fmt.Printf("%+v\n", event)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|