<commit_before>package victor

import (
	"fmt"
	"github.com/brettbuddin/victor/pkg/chat"
	_ "github.com/brettbuddin/victor/pkg/chat/campfire"
	_ "github.com/brettbuddin/victor/pkg/chat/shell"
	_ "github.com/brettbuddin/victor/pkg/chat/slack"
	"github.com/brettbuddin/victor/pkg/httpserver"
	"github.com/brettbuddin/victor/pkg/store"
	"github.com/gorilla/mux"
	"log"
	"os"
	"strings"
)

type Robot struct {
	*Dispatch
	name     string
	http     *httpserver.Server
	httpAddr string
	router   *mux.Router
	store    store.Store
	adapter  chat.Adapter
	incoming chan chat.Message
}

// New returns a Robot
func New(adapterName, robotName, httpAddr string) *Robot {
	initFunc, err := chat.Load(adapterName)

	if err != nil {
		log.Println(err)
		os.Exit(1)
	}

	bot := &Robot{
		name:     robotName,
		http:     httpserver.New(),
		store:    store.NewMemoryStore(),
		incoming: make(chan chat.Message),
		httpAddr: httpAddr,
	}

	bot.Dispatch = NewDispatch(bot)
	bot.adapter = initFunc(bot)
	bot.router = handlers(bot)

	defaults(bot)
	return bot
}

// Direct wraps a regexp pattern in the necessary pattern
// for a direct command to the bot.
func (r *Robot) Direct(exp string) string {
	return strings.Join([]string{
		"(?i)", // flags
		"\\A",  // begin
		"(?:(?:@)?" + r.name + "[:,]?\\s*|/)", // bot name
		"(?:" + exp + ")",                     // expression
		"\\z",                                 // end
	}, "")
}

func (r *Robot) Receive(m chat.Message) {
	r.incoming <- m
}

// Run starts the robot.
func (r *Robot) Run() error {
	go r.adapter.Run()
	go func() {
		for {
			select {
			case m := <-r.incoming:
				fmt.Println(strings.ToLower(m.UserName()), r.name)
				if strings.ToLower(m.UserName()) != r.name {
					go r.Process(m)
				}<commit_msg>Accidentally left in some debugging<commit_after>package victor

import (
	"github.com/brettbuddin/victor/pkg/chat"
	_ "github.com/brettbuddin/victor/pkg/chat/campfire"
	_ "github.com/brettbuddin/victor/pkg/chat/shell"
	_ "github.com/brettbuddin/victor/pkg/chat/slack"
	"github.com/brettbuddin/victor/pkg/httpserver"
	"github.com/brettbuddin/victor/pkg/store"
	"github.com/gorilla/mux"
	"log"
	"os"
	"strings"
)

type Robot struct {
	*Dispatch
	name     string
	http     *httpserver.Server
	httpAddr string
	router   *mux.Router
	store    store.Store
	adapter  chat.Adapter
	incoming chan chat.Message
}

// New returns a Robot
func New(adapterName, robotName, httpAddr string) *Robot {
	initFunc, err := chat.Load(adapterName)

	if err != nil {
		log.Println(err)
		os.Exit(1)
	}

	bot := &Robot{
		name:     robotName,
		http:     httpserver.New(),
		store:    store.NewMemoryStore(),
		incoming: make(chan chat.Message),
		httpAddr: httpAddr,
	}

	bot.Dispatch = NewDispatch(bot)
	bot.adapter = initFunc(bot)
	bot.router = handlers(bot)

	defaults(bot)
	return bot
}

// Direct wraps a regexp pattern in the necessary pattern
// for a direct command to the bot.
func (r *Robot) Direct(exp string) string {
	return strings.Join([]string{
		"(?i)", // flags
		"\\A",  // begin
		"(?:(?:@)?" + r.name + "[:,]?\\s*|/)", // bot name
		"(?:" + exp + ")",                     // expression
		"\\z",                                 // end
	}, "")
}

func (r *Robot) Receive(m chat.Message) {
	r.incoming <- m
}

// Run starts the robot.
func (r *Robot) Run() error {
	go r.adapter.Run()
	go func() {
		for {
			select {
			case m := <-r.incoming:
				if strings.ToLower(m.UserName()) != r.name {
					go r.Process(m)
				}
{'fraction_non_alphanumeric': 0.1591824985607369, 'fraction_numerical': 0.0005757052389176742, 'mean_word_length': 2.8568257491675917, 'pattern_counts': {'":': 0, '<': 7, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2785402', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1316, 'n_words': 283}