Esempio n. 1
0
// Send sends an IRC message to the server. If the message cannot be converted
// to a raw IRC line, an error is returned.
func (sc *ServerConnection) Send(tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error {
	ircmsg := ircmsg.MakeMessage(tags, prefix, command, params...)
	line, err := ircmsg.Line()
	if err != nil {
		return err
	}
	fmt.Fprintf(sc.RawConnection, line)

	// dispatch raw event
	info := eventmgr.NewInfoMap()
	info["server"] = sc
	info["direction"] = "out"
	info["data"] = line
	sc.dispatchRawOut(info)

	// dispatch real event
	info = eventmgr.NewInfoMap()
	info["server"] = sc
	info["direction"] = "out"
	info["tags"] = tags
	info["prefix"] = prefix
	info["command"] = command
	info["params"] = params

	// IRC commands are case-insensitive
	sc.dispatchOut(strings.ToUpper(command), info)

	return nil
}
Esempio n. 2
0
func sendMessage(conn net.Conn, tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) {
	ircmsg := ircmsg.MakeMessage(tags, prefix, command, params...)
	line, err := ircmsg.Line()
	if err != nil {
		return
	}
	fmt.Fprintf(conn, line)

	// need to wait for a quick moment here for TLS to process any changes this
	// message has caused
	runtime.Gosched()
	waitTime, _ := time.ParseDuration("10ms")
	time.Sleep(waitTime)
}