예제 #1
0
파일: main.go 프로젝트: kybernetyk/cyberklo
func main() {
	log.Println("Starting ...")
	c := irc.New()
	c.Tls = true
	c.Nick = "karkowka"
	c.Channels = append(c.Channels, "#polska")
	c.Connect("irc.hackint.eu")

	go udpServe()

	for {
		select {
		case str := <-to_world_chan:
			dec := bencode.NewDecoder([]byte(str))
			o, err := dec.Decode()
			if err != nil {
				log.Println("bencoding decode error: " + err.String())
			}

			dict := o.(map[string]interface{})
			name := dict["name"].(string)
			req := dict["req"].(string)

			if req == "data" {
				data := dict["data"].(map[string]interface{})

				str = fmt.Sprintf("[Sensor: %s State: %d]",
					name,
					data["state"].(int64))
			} else {
				str = fmt.Sprintf("[Sensor: %s Req: %s]",
					name,
					req)
			}
			//propagate to IRC
			line := "PRIVMSG #polska :" + str
			c.Send(line)

			//propagate to twitter ...
		}
	}

}
예제 #2
0
func test0r(in string) {
	fmt.Printf("testoring: '%s' ...\n", in)
	p := bencode.NewDecoder([]byte(in))

	for !p.Consumed {
		l, err := p.Decode()
		if err != nil {
			fmt.Printf("\tparser error: %s\n", err.String())
			break
		}
		switch l.(type) {
		case []interface{}:
			x := l.([]interface{})
			fmt.Printf("\tlist:\n")
			for _, o := range x {
				fmt.Printf("\t\tobj(%s): %#v\n", reflect.TypeOf(o).Name(), o)
			}
			fmt.Printf("\tlist_end\n")
		default:
			fmt.Printf("\tobj(%s): %#v\n", reflect.TypeOf(l).Name(), l)
		}
	}
}