Beispiel #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)
		}
	}
}
Beispiel #2
0
// New returns a mock IRC setup.
func New() (*bytes.Buffer, *irc.IRC, *IRCD, error) {
	reader := bytes.Buffer{}

	portMutex.Lock()
	p := strconv.Itoa(port)
	port++
	portMutex.Unlock()

	cmd := exec.Command("docker", "run", "--name=cbx-ircd-test-"+p, "-d", "-p", p+":6667", "xena/elemental-ircd")
	cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
	err := cmd.Run()

	if err != nil {
		return nil, nil, nil, err
	}

	// Need to wait for the ircd to startup. Otherwise we get connection errors.
	time.Sleep(50 * time.Millisecond)

	ircc, err := irc.New("cbx", "test", "localhost:"+p, "", false, &reader)

	if err != nil {
		return nil, nil, nil, err
	}

	ircd := IRCD{"docker", "rm", "-f", "cbx-ircd-test-" + p}

	return &reader, ircc, &ircd, nil
}