<commit_before>package main

import (
	"encoding/json"
	"flag"
	"github.com/ChimeraCoder/anaconda"
	irc "github.com/fluffle/goirc/client"
	"github.com/iceskel/lastfm"
	"github.com/lxn/win"
	"io/ioutil"
	"log"
	"syscall"
	"time"
	"unsafe"
)

type configuration struct {
	Channel               string
	Botname               string
	Aouth                 string
	LastfmKey             string
	LastfmSecret          string
	LastfmUser            string
	RepeatMsg             string
	TwitterConsumerKey    string
	TwitterConsumerSecret string
	TwitterAccessToken    string
	TwitterAccessSecret   string
}

const (
	vkA = 0x41 // win32 virtual key A code
	vkX = 0x42 // win32 virtual key B code
)

var (
	config      configuration
	tweet       *anaconda.TwitterApi
	timeoutList = make(map[string]bool)
	opList      = make(map[string]bool)
	hwnd        win.HWND
	delay       = time.Now()
	total       = 0
)

func main() {
	configFile := flag.String("c", "conf.json", "config file")
	flag.Parse()

	file, err := ioutil.ReadFile(*configFile)
	if err != nil {
		log.Fatal(err)
	}

	if err := json.Unmarshal(file, &config); err != nil {
		log.Fatal(err)
	}

	foobar2kwindowclass := syscall.StringToUTF16Ptr("{97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}")
	foobar2kwindowname := syscall.StringToUTF16Ptr("foobar2000 v1.2.9")
	hwnd = win.FindWindow(foobar2kwindowclass, foobar2kwindowname)
	if unsafe.Pointer(hwnd) == nil {
		log.Fatal("Foobar2k not open or not in default state (press the stop button)")
	}

	anaconda.SetConsumerKey(config.TwitterConsumerKey)
	anaconda.SetConsumerSecret(config.TwitterConsumerSecret)
	tweet = anaconda.NewTwitterApi(config.TwitterAccessToken, config.TwitterAccessSecret)

	opList[config.Channel[1:]] = true // op's for channel, gets op only commands

	c := irc.SimpleClient(config.Botname, config.Botname, "simple bot")
	c.AddHandler(irc.CONNECTED, func(conn *irc.Conn, line *irc.Line) {
		conn.Join(config.Channel)
	})
	c.AddHandler("PRIVMSG", repeatMessenger)
	c.AddHandler("PRIVMSG", tweetHandler)
	c.AddHandler("PRIVMSG", songHandler)
	c.AddHandler("PRIVMSG", addTimeoutListHandler)
	c.AddHandler("PRIVMSG", timeoutHandler)
	c.AddHandler("PRIVMSG", foobar2kHandler)

	quit := make(chan bool)
	c.AddHandler(irc.DISCONNECTED, func(conn *irc.Conn, line *irc.Line) {
		quit <- true
	})
	if err := c.Connect("irc.twitch.tv", config.Aouth); err != nil {
		log.Fatal(err)
	}
	log.Printf("Joined %s", config.Channel)

	<-quit
}

func repeatMessenger(conn *irc.Conn, line *irc.Line) {
	ticker := time.NewTicker(5 * time.Minute)
	go func() {
		for {
			<-ticker.C
			conn.Privmsg(config.Channel, "► "+config.RepeatMsg)
		}
	}()
	time.Sleep(5001 * time.Millisecond)
}

func tweetHandler(conn *irc.Conn, line *irc.Line) {
	if !(time.Since(delay).Seconds() > 10) {
		return
	}
	if line.Args[1] != "!tweet" && line.Args[1] != "!twitter" {
		return
	}

	thetweet, err := tweet.GetUserTimeline(nil)<commit_msg>cleanup<commit_after>package main

import (
	"encoding/json"
	"flag"
	"github.com/ChimeraCoder/anaconda"
	irc "github.com/fluffle/goirc/client"
	"github.com/iceskel/lastfm"
	"github.com/lxn/win"
	"io/ioutil"
	"log"
	"syscall"
	"time"
	"unsafe"
)

type configuration struct {
	Channel               string
	Botname               string
	Aouth                 string
	LastfmKey             string
	LastfmSecret          string
	LastfmUser            string
	RepeatMsg             string
	TwitterConsumerKey    string
	TwitterConsumerSecret string
	TwitterAccessToken    string
	TwitterAccessSecret   string
}

const (
	vkA = 0x41 // win32 virtual key A code
	vkX = 0x42 // win32 virtual key B code
)

var (
	config      configuration
	tweet       *anaconda.TwitterApi
	timeoutList = make(map[string]bool)
	opList      = make(map[string]bool)
	hwnd        win.HWND
	delay       = time.Now()
	total       = 0
)

func main() {
	configFile := flag.String("c", "conf.json", "config file")
	flag.Parse()

	setConfig(configFile)
	setFoobar2k()
	setIrcClient()

}

func setIrcClient() {
	c := irc.SimpleClient(config.Botname, config.Botname, "simple bot")
	c.AddHandler(irc.CONNECTED, func(conn *irc.Conn, line *irc.Line) {
		conn.Join(config.Channel)
	})
	c.AddHandler("PRIVMSG", repeatMessenger)
	c.AddHandler("PRIVMSG", tweetHandler)
	c.AddHandler("PRIVMSG", songHandler)
	c.AddHandler("PRIVMSG", addTimeoutListHandler)
	c.AddHandler("PRIVMSG", timeoutHandler)
	c.AddHandler("PRIVMSG", foobar2kHandler)

	quit := make(chan bool)
	c.AddHandler(irc.DISCONNECTED, func(conn *irc.Conn, line *irc.Line) {
		quit <- true
	})
	if err := c.Connect("irc.twitch.tv", config.Aouth); err != nil {
		log.Fatal(err)
	}
	log.Printf("Joined %s", config.Channel)

	<-quit
}

func setConfig(configFile *string) {
	file, err := ioutil.ReadFile(*configFile)
	if err != nil {
		log.Fatal(err)
	}

	if err := json.Unmarshal(file, &config); err != nil {
		log.Fatal(err)
	}
	anaconda.SetConsumerKey(config.TwitterConsumerKey)
	anaconda.SetConsumerSecret(config.TwitterConsumerSecret)
	tweet = anaconda.NewTwitterApi(config.TwitterAccessToken, config.TwitterAccessSecret)

	opList[config.Channel[1:]] = true // op's for channel, gets op only commands
}

func setFoobar2k() {
	foobar2kwindowclass := syscall.StringToUTF16Ptr("{97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}")
	foobar2kwindowname := syscall.StringToUTF16Ptr("foobar2000 v1.2.9")
	hwnd = win.FindWindow(foobar2kwindowclass, foobar2kwindowname)
	if unsafe.Pointer(hwnd) == nil {
		log.Fatal("Foobar2k not open or not in default state (press the stop button)")
	}
}

func repeatMessenger(conn *irc.Conn, line *irc.Line) {
	ticker := time.NewTicker(5 * time.Minute)
	go func() {
		for {
			<-ticker.C
			conn.Privmsg(config.Channel, "► "+config.RepeatMsg)
		}
	}()
	time.Sleep(5001 * time.Millisecond)
}

func tweetHandler(conn *irc.Conn, line *irc.Line) {
	if !(time.Since(delay).Seconds() > 10) {
		return
	}
	if line.Args[1] != "!tweet" && line.Args[1] != "!twitter" {
		return
	}

	thetweet, err := tweet.GetUserTimeline(nil)
{'fraction_non_alphanumeric': 0.13428331936295054, 'fraction_numerical': 0.019111483654652137, 'mean_word_length': 3.77662129703763, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '3758165', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2208, 'n_words': 425}