<commit_before>package fresh

import (
	"encoding/json"
	"fmt"

	lazlo "github.com/djosephsen/lazlo/lib"
	"github.com/sadbox/mediawiki"
)

var Wat = &lazlo.Module{
	Name:  `Wat`,
	Usage: `"wat is <term>": Returns wikipedia info`,
	Run:   watRun,
}

func watRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)^wat +is +(.*)$`, false)
	for {
		pm := <-cb.Chan
		search := pm.Match[1]
		client, err := mediawiki.New(`http://en.wikipedia.org/w/api.php`, "lazlo")
		if err != nil {
			pm.Event.Respond(err.Error())
		}
		response, err := readExtract(client, search)
		if err != nil {
			pm.Event.Respond(err.Error())
		}

		response.GenPageList()
		fmt.Printf("%v", response)
		pm.Event.Respond(
			fmt.Sprintf(
				"*%v*\n%v",
				response.Query.PageList[0].Title,
				response.Query.PageList[0].Extract,
			),
		)
	}
}

func readExtract(client *mediawiki.MWApi, search string) (*Response, error) {
	query := map[string]string{
		"action":      "query",
		"prop":        "extracts",
		"titles":      search,
		"redirects": "true",
		"exintro":     "true",
		"explaintext": "true",
		"exsentences": "3",
		"exsectionformat": "plain",
	}
	body, err := client.API(query)<commit_msg>Improve regex<commit_after>package fresh

import (
	"encoding/json"
	"fmt"

	lazlo "github.com/djosephsen/lazlo/lib"
	"github.com/sadbox/mediawiki"
)

var Wat = &lazlo.Module{
	Name:  `Wat`,
	Usage: `"wat is <term>": Returns wikipedia info`,
	Run:   watRun,
}

func watRun(b *lazlo.Broker) {
	cb := b.MessageCallback(`(?i)^wat +is +(.+?) *$`, false)
	for {
		pm := <-cb.Chan
		search := pm.Match[1]
		client, err := mediawiki.New(`http://en.wikipedia.org/w/api.php`, "lazlo")
		if err != nil {
			pm.Event.Respond(err.Error())
		}
		response, err := readExtract(client, search)
		if err != nil {
			pm.Event.Respond(err.Error())
		}

		response.GenPageList()
		fmt.Printf("%v", response)
		pm.Event.Respond(
			fmt.Sprintf(
				"*%v*\n%v",
				response.Query.PageList[0].Title,
				response.Query.PageList[0].Extract,
			),
		)
	}
}

func readExtract(client *mediawiki.MWApi, search string) (*Response, error) {
	query := map[string]string{
		"action":          "query",
		"prop":            "extracts",
		"titles":          search,
		"redirects":       "true",
		"exintro":         "true",
		"explaintext":     "true",
		"exsentences":     "3",
		"exsectionformat": "plain",
	}
	body, err := client.API(query)
{'fraction_non_alphanumeric': 0.19438625890238795, 'fraction_numerical': 0.0033514872224549644, 'mean_word_length': 3.3027027027027027, 'pattern_counts': {'":': 18, '<': 7, '<?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': '5722845', 'n_tokens_mistral': 1038, 'n_tokens_neox': 940, 'n_words': 172}