Esempio n. 1
0
func (t *TelnetConfig) readUnitl(tn *telnet.Conn, d ...string) (err error) {
	var data []byte
	data, err = tn.ReadUntil(d...)
	if err != nil {
		return err
	}

	if t.Debug {
		os.Stdout.WriteString("\n")
		os.Stdout.Write(data)
		os.Stdout.WriteString("\n")
	}

	return nil
}
Esempio n. 2
0
func checkForMessages(t *telnet.Conn, disco *discord.Discord) (err error) {
	data := []byte{}
	message := ""
	for {
		if data, err = t.ReadUntil("\n"); err != nil {
			err = fmt.Errorf("Error reading", err.Error())
			return
		}
		message = string(data)
		//log.Printf("[DEBUG OOC] %s", message)
		if len(message) < 3 { //ignore small messages
			continue
		}
		if !strings.Contains(message, "says ooc,") { //ignore non-ooc
			continue
		}
		if strings.Index(message, ">") > 0 && strings.Index(message, ">") < strings.Index(message, " ") { //ignore prompts
			message = message[strings.Index(message, ">")+1:]
		}
		if message[0:1] == "*" { //ignore echo backs
			continue
		}

		sender := message[0:strings.Index(message, " says ooc,")]
		message = message[strings.Index(message, "says ooc, '")+11 : len(message)-3]
		sender = strings.Replace(sender, "_", " ", -1)

		message = convertLinks(config.Discord.ItemUrl, message)

		if _, err = disco.SendMessage(channelID, fmt.Sprintf("**%s OOC**: %s", sender, message)); err != nil {
			log.Printf("[OOC] Error sending message (%s: %s) %s", sender, message, err.Error())
			continue
		}
		log.Printf("[OOC] %s: %s\n", sender, message)
	}
}