示例#1
0
func main() {
	irccon := irc.IRC("testgo", "testgo")
	err := irccon.Connect("irc.efnet.net:6667")
	if err != nil {
		fmt.Printf("%s\n", err)
		fmt.Printf("%#v\n", irccon)
		os.Exit(1)
	}
	irccon.AddCallback("001", func(e *irc.IRCEvent) { irccon.Join("#testgo") })
	irccon.Loop()
}
示例#2
0
func main() {
	irccon := irc.IRC("testgo", "testgo", "testgo")
	err := irccon.Connect("irc.efnet.net:6667")
	if err != nil {
		fmt.Printf("%s\n", err)
		fmt.Printf("%#v\n", irccon)
		os.Exit(1)
	}
	irccon.AddCallback("001", func(e *irc.IRCEvent) { irccon.Join("#testgo1") })
	irccon.AddCallback("001", func(e *irc.IRCEvent) { irccon.Join("#testgo2") })
	irccon.AddCallback("001", func(e *irc.IRCEvent) { irccon.Join("#testgo3") })
	irccon.AddCallback("001", func(e *irc.IRCEvent) { irccon.Join("#testgo4") })
	irccon.AddCallback("001", func(e *irc.IRCEvent) { irccon.Join("#testgo5") })
	irccon.AddCallback("001", func(e *irc.IRCEvent) { irccon.Join("#testgo6") })
	irccon.ReplaceCallback("001", 0, func(e *irc.IRCEvent) { irccon.Join("#testgo01") })
	irccon.ReplaceCallback("001", 1, func(e *irc.IRCEvent) { irccon.Join("#testgo02") })
	irccon.ReplaceCallback("001", 2, func(e *irc.IRCEvent) { irccon.Join("#testgo03") })
	irccon.ReplaceCallback("001", 3, func(e *irc.IRCEvent) { irccon.Join("#testgo04") })
	irccon.ReplaceCallback("001", 4, func(e *irc.IRCEvent) { irccon.Join("#testgo05") })
	irccon.ReplaceCallback("001", 6, func(e *irc.IRCEvent) { irccon.Join("#testgo06") })
	irccon.Loop()
}
示例#3
0
func ircStuff() {
	var nick string
	var peers []string
	type payload struct {
		Author    string
		Text      string
		Timestamp string
	}

	irccon := irc.IRC("testgo", "testgo")
	irccon.Connect("irc.freenode.net:6667")

	irccon.AddCallback("JOIN", func(e *irc.IRCEvent) {
		fmt.Println(e)
		if nick == e.Nick {
			go irccon.SendRaw("who #bootstrap")

			time.Sleep(5e9)
			WritePeers(peers)
			go DialRelays()

		}
	})
	irccon.AddCallback("NOTICE", func(e *irc.IRCEvent) {
		if strings.Contains(e.Message, "PING") {
			fmt.Println("received response from", e.Host)
			PingResponse <- e.Host
		}
	})
	irccon.AddCallback("311", func(e *irc.IRCEvent) {
		//irccon.Privmsg("#bootstrap",e.Arguments[3])
	})
	irccon.AddCallback("352", func(e *irc.IRCEvent) { // who response from server
		//irccon.Privmsg("#bootstrap",e.Arguments[3])
		peers = append(peers, e.Arguments[3])
		fmt.Println("GOT WHO RESPONSE:", e)
		//WritePeer(e.Arguments[3])
	})
	irccon.AddCallback("372", func(e *irc.IRCEvent) {
		//fmt.Println(e)
	})

	irccon.AddCallback("353", func(e *irc.IRCEvent) { //channel name list
		names := strings.Split(e.Message, " ", -1)
		fmt.Println(e)
		//fmt.Println(e.Message)
		for i := range names {
			if names[i] != nick {
				fmt.Println(names[i])
			}
		}
	})

	irccon.AddCallback("001", func(e *irc.IRCEvent) {
		irccon.Join("#bootstrap")
		fmt.Println(e)
		nick = e.Arguments[0]
	})

	go func() {
		for {
			v := <-ircChan
			timestamp := time.LocalTime().String()
			author := myUsername
			payload := `{"author":"` + author + `","text":"` + string(v) + `","timestamp":"` + timestamp + `"}`
			msg := `{"type":"newtweet","tweetbody":` + payload + `}`
			irccon.Privmsg("#bootstrap", msg)
		}
	}()
}