<commit_before>package modules

import (
	"fmt"
	"log"
	"math"
	"strings"

	"github.com/pajlada/pajbot2/bot"

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

// Pyramid module from pajbot 1
type Pyramid struct {
	data      [][]string
	goingDown bool
}

// Ensure the module implements the interface properly
var _ Module = (*Pyramid)(nil)

// Check KKona
func (module *Pyramid) Check(b *bot.Bot, msg *common.Msg, action *bot.Action) error {
	if msg.User.Name == "twitchnotify" {
		return nil
	}
	msgParts := strings.Split(msg.Message, " ")
	if len(module.data) > 0 {
		curLen := len(msgParts)
		lastLen := len(module.data[len(module.data)-1])
		pyramidThing := module.data[0][0]
		lenDiff := curLen - lastLen

		if math.Abs(float64(lenDiff)) == 1 {
			good := true

			for _, w := range msgParts {
				if w != pyramidThing {
					good = false
					break
				}
			}
			if good {
				module.data = append(module.data, msgParts)
				if lenDiff > 0 {
					if module.goingDown {
						module.data = make([][]string, 0)
						module.goingDown = false
					}
				} else if lenDiff < 0 {
					module.goingDown = true
					if curLen == 1 {
						// a pyramid has been finished<commit_msg>fixed bug<commit_after>package modules

import (
	"fmt"
	"log"
	"math"
	"strings"

	"github.com/pajlada/pajbot2/bot"

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

// Pyramid module from pajbot 1
type Pyramid struct {
	data      [][]string
	goingDown bool
}

// Ensure the module implements the interface properly
var _ Module = (*Pyramid)(nil)

// Check KKona
func (module *Pyramid) Check(b *bot.Bot, msg *common.Msg, action *bot.Action) error {
	if msg.Type != "privmsg" {
		return nil
	}
	msgParts := strings.Split(msg.Message, " ")
	if len(module.data) > 0 {
		curLen := len(msgParts)
		lastLen := len(module.data[len(module.data)-1])
		pyramidThing := module.data[0][0]
		lenDiff := curLen - lastLen

		if math.Abs(float64(lenDiff)) == 1 {
			good := true

			for _, w := range msgParts {
				if w != pyramidThing {
					good = false
					break
				}
			}
			if good {
				module.data = append(module.data, msgParts)
				if lenDiff > 0 {
					if module.goingDown {
						module.data = make([][]string, 0)
						module.goingDown = false
					}
				} else if lenDiff < 0 {
					module.goingDown = true
					if curLen == 1 {
						// a pyramid has been finished
{'fraction_non_alphanumeric': 0.13445017182130584, 'fraction_numerical': 0.012027491408934709, 'mean_word_length': 2.7869918699186993, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1830401', 'n_tokens_mistral': 1005, 'n_tokens_neox': 836, 'n_words': 212}