<commit_before>package module

import (
	"fmt"
	"github.com/davidscholberg/irkbot/lib/configure"
	"github.com/davidscholberg/irkbot/lib/message"
	"github.com/thoj/go-ircevent"
	"strings"
)

type CommandModule struct {
	Configure func(*configure.Config)
	GetHelp   func() []string
	Run       func(*message.Privmsg)
}

type ParserModule struct {
	Configure func(*configure.Config)
	GetHelp   func() []string
	Run       func(*message.Privmsg) bool
}

func RegisterModules(conn *irc.Connection, cfg *configure.Config, sayChan chan message.SayMsg) error {
	// register modules
	parserModules := []*ParserModule{}
	cmdMap := make(map[string]*CommandModule)
	for moduleName, _ := range cfg.Modules {
		switch moduleName {
		case "echo_name":
			parserModules = append(parserModules, &ParserModule{ConfigEchoName, nil, EchoName})
		case "help":
			cmdMap["help"] = &CommandModule{ConfigHelp, nil, Help}
		case "slam":
			cmdMap["slam"] = &CommandModule{ConfigSlam, HelpSlam, Slam}
		case "compliment":
			cmdMap["compliment"] = &CommandModule{ConfigCompliment, HelpCompliment, Compliment}
		case "quit":
			cmdMap["quit"] = &CommandModule{ConfigQuit, HelpQuit, Quit}
		case "quote":
			parserModules = append(parserModules, &ParserModule{ConfigQuote, nil, UpdateQuoteBuffer})
			cmdMap["grab"] = &CommandModule{nil, HelpGrabQuote, GrabQuote}
			cmdMap["quote"] = &CommandModule{nil, HelpGetQuote, GetQuote}
		case "urban":
			cmdMap["urban"] = &CommandModule{nil, HelpUrban, Urban}
		case "urban_wotd":
			cmdMap["urban_wotd"] = &CommandModule{nil, HelpUrbanWotd, UrbanWotd}
		case "urban_trending":
			cmdMap["urban_trending"] = &CommandModule{nil, HelpUrbanTrending, UrbanTrending}
		case "url":
			parserModules = append(parserModules, &ParserModule{nil, nil, Url})
		default:
			return fmt.Errorf("invalid name '%s' in module config", moduleName)
		}
	}

	for _, m := range cmdMap {
		if m.GetHelp != nil {
			RegisterHelp(m.GetHelp())
		}
		if m.Configure != nil {
			m.Configure(cfg)
		}
	}

	for _, m := range parserModules {
		if m.GetHelp != nil {
			RegisterHelp(m.GetHelp())
		}
		if m.Configure != nil {
			m.Configure(cfg)
		}
	}

	conn.AddCallback("PRIVMSG", func(e *irc.Event) {
		p := message.Privmsg{}
		p.Msg = e.Message()
		p.MsgArgs = strings.Split(p.Msg, " ")
		p.Dest = e.Arguments[0]
		if !strings.HasPrefix(p.Dest, "#") {
			p.Dest = e.Nick
		}
		p.Event = e
		p.Conn = conn
		p.SayChan = sayChan

		// run parser modules
		for _, m := range parserModules {
			if m.Run(&p) {
				return
			}
		}

		// check commands
		cmdPrefix := cfg.Channel.CmdPrefix
		if cmdPrefix == "" {
			cmdPrefix = "."
		}
		if strings.HasPrefix(p.Msg, cmdPrefix) {
			if m, ok := cmdMap[strings.TrimPrefix(p.MsgArgs[0], cmdPrefix)]; ok {
				m.Run(&p)
			}
		}

	})

	return nil
}
<commit_msg>fixed message arg parsing to use strings.Fields<commit_after>package module

import (
	"fmt"
	"github.com/davidscholberg/irkbot/lib/configure"
	"github.com/davidscholberg/irkbot/lib/message"
	"github.com/thoj/go-ircevent"
	"strings"
)

type CommandModule struct {
	Configure func(*configure.Config)
	GetHelp   func() []string
	Run       func(*message.Privmsg)
}

type ParserModule struct {
	Configure func(*configure.Config)
	GetHelp   func() []string
	Run       func(*message.Privmsg) bool
}

func RegisterModules(conn *irc.Connection, cfg *configure.Config, sayChan chan message.SayMsg) error {
	// register modules
	parserModules := []*ParserModule{}
	cmdMap := make(map[string]*CommandModule)
	for moduleName, _ := range cfg.Modules {
		switch moduleName {
		case "echo_name":
			parserModules = append(parserModules, &ParserModule{ConfigEchoName, nil, EchoName})
		case "help":
			cmdMap["help"] = &CommandModule{ConfigHelp, nil, Help}
		case "slam":
			cmdMap["slam"] = &CommandModule{ConfigSlam, HelpSlam, Slam}
		case "compliment":
			cmdMap["compliment"] = &CommandModule{ConfigCompliment, HelpCompliment, Compliment}
		case "quit":
			cmdMap["quit"] = &CommandModule{ConfigQuit, HelpQuit, Quit}
		case "quote":
			parserModules = append(parserModules, &ParserModule{ConfigQuote, nil, UpdateQuoteBuffer})
			cmdMap["grab"] = &CommandModule{nil, HelpGrabQuote, GrabQuote}
			cmdMap["quote"] = &CommandModule{nil, HelpGetQuote, GetQuote}
		case "urban":
			cmdMap["urban"] = &CommandModule{nil, HelpUrban, Urban}
		case "urban_wotd":
			cmdMap["urban_wotd"] = &CommandModule{nil, HelpUrbanWotd, UrbanWotd}
		case "urban_trending":
			cmdMap["urban_trending"] = &CommandModule{nil, HelpUrbanTrending, UrbanTrending}
		case "url":
			parserModules = append(parserModules, &ParserModule{nil, nil, Url})
		default:
			return fmt.Errorf("invalid name '%s' in module config", moduleName)
		}
	}

	for _, m := range cmdMap {
		if m.GetHelp != nil {
			RegisterHelp(m.GetHelp())
		}
		if m.Configure != nil {
			m.Configure(cfg)
		}
	}

	for _, m := range parserModules {
		if m.GetHelp != nil {
			RegisterHelp(m.GetHelp())
		}
		if m.Configure != nil {
			m.Configure(cfg)
		}
	}

	conn.AddCallback("PRIVMSG", func(e *irc.Event) {
		p := message.Privmsg{}
		p.Msg = e.Message()
		p.MsgArgs = strings.Fields(p.Msg)
		p.Dest = e.Arguments[0]
		if !strings.HasPrefix(p.Dest, "#") {
			p.Dest = e.Nick
		}
		p.Event = e
		p.Conn = conn
		p.SayChan = sayChan

		// run parser modules
		for _, m := range parserModules {
			if m.Run(&p) {
				return
			}
		}

		// check commands
		cmdPrefix := cfg.Channel.CmdPrefix
		if cmdPrefix == "" {
			cmdPrefix = "."
		}
		if strings.HasPrefix(p.Msg, cmdPrefix) {
			if m, ok := cmdMap[strings.TrimPrefix(p.MsgArgs[0], cmdPrefix)]; ok {
				m.Run(&p)
			}
		}

	})

	return nil
}

{'fraction_non_alphanumeric': 0.14453961456102785, 'fraction_numerical': 0.0007137758743754461, 'mean_word_length': 4.0134168157423975, 'pattern_counts': {'":': 20, '<': 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': '2721526', 'n_tokens_mistral': 2258, 'n_tokens_neox': 2006, 'n_words': 414}