<commit_before><commit_msg>Add Telnet class (#11)<commit_after>package main

import (
	"bufio"
	"fmt"
	"net"

	"github.com/Sirupsen/logrus"
)

type LiquidsoapTelnet struct {
	Host string
	Port int
	Conn net.Conn
}

func NewLiquidsoapTelnet(host string, port int) *LiquidsoapTelnet {
	return &LiquidsoapTelnet{
		Host: host,
		Port: port,
	}
}

func (t *LiquidsoapTelnet) Dest() string {
	return fmt.Sprintf("%s:%d", t.Host, t.Port)
}

func (t *LiquidsoapTelnet) Open() error {
	logrus.Infof("Connecting to Liquidsoap telnet: %s:%d", t.Host, t.Port)
	conn, err := net.Dial("tcp", t.Dest())
	if err != nil {
		return err
	}
	t.Conn = conn
	return nil
}

func (t *LiquidsoapTelnet) Close() {
	if t.Conn != nil {
		t.Conn.Close()
	}
}

func (t *LiquidsoapTelnet) Command(command string) (string, error) {
	if err := t.Open(); err != nil {
		logrus.Errorf("Failed to connect to liquidsoap telnet socket")
		return "", err
	}
	defer t.Close()
	logrus.Infof("Sending to telnet: %q", command)
	fmt.Fprintf(t.Conn, "%s\n", command)
	message, err := bufio.NewReader(t.Conn).ReadString('\n')
	if err != nil {
		return "", err
	}
	fmt.Printf("Received from telnet: %q", message)
	return message, nil
}
{'fraction_non_alphanumeric': 0.15895710681244743, 'fraction_numerical': 0.001682085786375105, 'mean_word_length': 4.151515151515151, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2315040', 'n_tokens_mistral': 492, 'n_tokens_neox': 470, 'n_words': 120}