Beispiel #1
0
func (sys *JabberSubSystem) Run(channelIn, channelOut chan msgsystem.Message) {
	if len(sys.server) == 0 {
		return
	}

	var talk *xmpp.Client
	var err error
	if sys.notls {
		talk, err = xmpp.NewClientNoTLS(sys.server, sys.username, sys.password, false)
	} else {
		talk, err = xmpp.NewClient(sys.server, sys.username, sys.password, false)
	}
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		for {
			chat, err := talk.Recv()
			if err != nil {
				log.Fatal(err)
			}
			switch v := chat.(type) {
			case xmpp.Chat:
				if len(v.Text) > 0 {
					fmt.Println(v.Remote, v.Text)

					msg := msgsystem.Message{
						//						To:     []string{sys.username},
						Msg:    v.Text,
						Source: v.Remote,
						Authed: auth.IsAuthed(v.Remote),
					}
					channelIn <- msg
				}
			case xmpp.Presence:
				fmt.Println(v.From, v.Show)
			}
		}
	}()
}
Beispiel #2
0
func (sys *IrcSubSystem) Run(channelIn, channelOut chan msgsystem.Message) {
	if len(sys.irchost) == 0 {
		return
	}

	// channel signaling irc connection status
	sys.ConnectedState = make(chan bool)

	// setup IRC client:
	cfg := irc.NewConfig(sys.ircnick, "ircflu", "ircflu")
	cfg.SSL = sys.ircssl
	cfg.Server = sys.irchost
	cfg.Pass = sys.ircpassword
	cfg.NewNick = func(n string) string { return n + "_" }
	sys.client = irc.Client(cfg)

	sys.client.HandleFunc("connected", func(conn *irc.Conn, line *irc.Line) {
		sys.ConnectedState <- true
	})
	sys.client.HandleFunc("disconnected", func(conn *irc.Conn, line *irc.Line) {
		sys.ConnectedState <- false
	})
	sys.client.HandleFunc("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {
		channel := line.Args[0]
		text := ""
		if len(line.Args) > 1 {
			text = line.Args[1]
		}
		if channel == sys.client.Config().Me.Nick {
			log.Println("PM from " + line.Src)
			channel = line.Src // replies go via PM too.
		} else {
			log.Println("Message in channel " + line.Args[0] + " from " + line.Src)
		}

		msg := msgsystem.Message{
			To:     []string{channel},
			Msg:    text,
			Source: line.Src,
			Authed: auth.IsAuthed(line.Src),
		}
		channelIn <- msg
	})

	// loop on IRC dis/connected events
	go func() {
		for {
			log.Println("Connecting to IRC:", sys.irchost)
			err := sys.client.Connect()
			if err != nil {
				log.Println("Failed to connect to IRC:", sys.irchost)
				log.Println(err)
				continue
			}
			for {
				status := <-sys.ConnectedState
				if status {
					log.Println("Connected to IRC:", sys.irchost)

					if len(sys.channels) == 0 {
						// join default channel
						sys.Join(sys.ircchannel)
					} else {
						// we must have been disconnected, rejoin channels
						sys.Rejoin()
					}
				} else {
					log.Println("Disconnected from IRC:", sys.irchost)
					break
				}
			}
			time.Sleep(5 * time.Second)
		}
	}()
}
Beispiel #3
0
func (sys *IrcSubSystem) Run(channelIn, channelOut chan msgsystem.Message) {
	if len(sys.irchost) == 0 {
		return
	}

	// channel signaling irc connection status
	sys.ConnectedState = make(chan bool)

	// setup IRC client:
	sys.client = irc.SimpleClient(sys.ircnick, "ircflu", "ircflu")
	sys.client.SSL = sys.ircssl

	sys.client.AddHandler(irc.CONNECTED, func(conn *irc.Conn, line *irc.Line) {
		sys.ConnectedState <- true
	})
	sys.client.AddHandler(irc.DISCONNECTED, func(conn *irc.Conn, line *irc.Line) {
		sys.ConnectedState <- false
	})
	sys.client.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {
		channel := line.Args[0]
		if channel == sys.client.Me.Nick {
			log.Println("PM from " + line.Src)
			channel = line.Src // replies go via PM too.
		} else {
			log.Println("Message in channel " + line.Args[0] + " from " + line.Src)
		}

		msg := msgsystem.Message{
			To:     []string{channel},
			Msg:    line.Args[1],
			Source: line.Src,
			Authed: auth.IsAuthed(line.Src),
		}
		channelIn <- msg
	})

	// loop on IRC dis/connected events
	go func() {
		for {
			log.Println("Connecting to IRC:", sys.irchost)
			err := sys.client.Connect(sys.irchost, sys.ircpassword)
			if err != nil {
				log.Println("Failed to connect to IRC:", sys.irchost)
				log.Println(err)
				continue
			}
			for {
				status := <-sys.ConnectedState
				if status {
					log.Println("Connected to IRC:", sys.irchost)

					if len(sys.channels) == 0 {
						// join default channel
						sys.Join(sys.ircchannel)
					} else {
						// we must have been disconnected, rejoin channels
						sys.Rejoin()
					}
				} else {
					log.Println("Disconnected from IRC:", sys.irchost)
					break
				}
			}
			time.Sleep(5 * time.Second)
		}
	}()
}