Exemple #1
0
func connect(w io.Writer, r io.Reader) {
	ircc, err := irc.New(*nick, *user, *server, *pass, *tls, w)
	if err != nil {
		fmt.Fprintln(w, events.ConnectionError(err.Error()))
		os.Exit(1)
	}

	err = ircc.WaitForConnection(connectionTimeout)

	if err != nil {
		os.Exit(2)
	}

	inReader := bufio.NewReader(os.Stdin)

	for {
		input, err := inReader.ReadString('\n')

		if err != nil {
			fmt.Fprintln(w, events.InternalError(err.Error()))
		}

		status := parser.Parse(ircc, w, input)

		if status != -1 {
			os.Exit(status)
		}
	}
}
Exemple #2
0
// WaitForConnection blocks until the irc connection succeeds or times out
func (i *IRC) WaitForConnection(timeout time.Duration) error {
	start := time.Now()

	for {
		if i.Connected == true {
			return nil
		}

		if time.Since(start) > timeout {
			err := errors.New("connection timeout")
			fmt.Fprintln(i.Output, events.ConnectionError(err.Error()))
			return err
		}

		time.Sleep(100 * time.Millisecond)
	}
}