<commit_before>package bot

import (
	"fmt"

	"github.com/pajlada/pajbot2/redismanager"

	"github.com/pajlada/pajbot2/common"
)

/*
Config contains some data about
*/
type Config struct {
	Quit     chan string
	ReadChan chan common.Msg
	SendChan chan string
	Channel  string
	Redis    *redismanager.RedisManager
}

/*
A Bot runs in a single channel and reacts according to its
given commands.
*/
type Bot struct {
	Quit    chan string
	Read    chan common.Msg
	Send    chan string
	Channel string
	Redis   *redismanager.RedisManager
	Modules []Module
}

/*
NewBot instansiates a new Bot object with the given Config object
*/
func NewBot(cfg Config, modules []Module) *Bot {
	return &Bot{
		Quit:    cfg.Quit,
		Read:    cfg.ReadChan,
		Send:    cfg.SendChan,
		Channel: cfg.Channel,
		Modules: modules,
		Redis:   cfg.Redis,
	}
}

/*
Init starts the bots

Connects to irc, joins channel etc
starts channels?
idk
*/
func (bot *Bot) Init() {
	log.Infof("new bot in %s", bot.Channel)
	for {
		m := <-bot.Read
		// log.Infof("#%s %s :%s\n", m.Channel, m.User.Name, m.Text)
		if m.Type == common.MsgSub {
			log.Infof("%s subbed for %d months in a row\n", m.User.Name, m.Length)
		}
		if m.Type != common.MsgSub {
			bot.Redis.GetUser(bot.Channel, &m.User)
		}
		log.Debugf("%s is level %d\n", m.User.Name, m.User.Level)
		go bot.Handle(m)
	}
}

/*
Say sends a PRIVMSG to the bots given channel
*/
func (bot *Bot) Say(message string) {
	m := fmt.Sprintf("PRIVMSG #%s :%s ", bot.Channel, message)
	bot.Send <- m
}

/*
Sayf sends a formatted PRIVMSG to the bots given channel
*/
func (bot *Bot) Sayf(format string, a ...interface{}) {
	message := fmt.Sprintf(format, a...)
	m := fmt.Sprintf("PRIVMSG #%s :%s ", bot.Channel, message)
	bot.Send <- m
}

/*
Ban returns the ban/TO message and reason, perm ban if duration < 0
*/
func (bot *Bot) Ban(user string, duration int, reason string) string {
	if duration < 0 {
		return fmt.Sprintf(".ban %s %s - autoban by pajbot", user, reason)
	}
	return fmt.Sprintf(".timeout %s %d %s - autoban by pajbot", user, duration, reason)<commit_msg>simplified Bot.Sayf<commit_after>package bot

import (
	"fmt"

	"github.com/pajlada/pajbot2/common"
	"github.com/pajlada/pajbot2/redismanager"
)

/*
Config contains some data about
*/
type Config struct {
	Quit     chan string
	ReadChan chan common.Msg
	SendChan chan string
	Channel  string
	Redis    *redismanager.RedisManager
}

/*
A Bot runs in a single channel and reacts according to its
given commands.
*/
type Bot struct {
	Quit    chan string
	Read    chan common.Msg
	Send    chan string
	Channel string
	Redis   *redismanager.RedisManager
	Modules []Module
}

/*
NewBot instansiates a new Bot object with the given Config object
*/
func NewBot(cfg Config, modules []Module) *Bot {
	return &Bot{
		Quit:    cfg.Quit,
		Read:    cfg.ReadChan,
		Send:    cfg.SendChan,
		Channel: cfg.Channel,
		Modules: modules,
		Redis:   cfg.Redis,
	}
}

/*
Init starts the bots

Connects to irc, joins channel etc
starts channels?
idk
*/
func (bot *Bot) Init() {
	log.Infof("new bot in %s", bot.Channel)
	for {
		m := <-bot.Read
		// log.Infof("#%s %s :%s\n", m.Channel, m.User.Name, m.Text)
		if m.Type == common.MsgSub {
			log.Infof("%s subbed for %d months in a row\n", m.User.Name, m.Length)
		}
		if m.Type != common.MsgSub {
			bot.Redis.GetUser(bot.Channel, &m.User)
		}
		log.Debugf("%s is level %d\n", m.User.Name, m.User.Level)
		go bot.Handle(m)
	}
}

/*
Say sends a PRIVMSG to the bots given channel
*/
func (bot *Bot) Say(message string) {
	m := fmt.Sprintf("PRIVMSG #%s :%s ", bot.Channel, message)
	bot.Send <- m
}

/*
Sayf sends a formatted PRIVMSG to the bots given channel
*/
func (bot *Bot) Sayf(format string, a ...interface{}) {
	bot.Say(fmt.Sprintf(format, a...))
}

/*
Ban returns the ban/TO message and reason, perm ban if duration < 0
*/
func (bot *Bot) Ban(user string, duration int, reason string) string {
	if duration < 0 {
		return fmt.Sprintf(".ban %s %s - autoban by pajbot", user, reason)
	}
	return fmt.Sprintf(".timeout %s %d %s - autoban by pajbot", user, duration, reason)
{'fraction_non_alphanumeric': 0.1349828515433611, 'fraction_numerical': 0.0019598236158745713, 'mean_word_length': 3.2888655462184873, 'pattern_counts': {'":': 0, '<': 12, '<?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': '2294020', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1512, 'n_words': 475}