<commit_before>package command

import (
	"encoding/xml"
	"log"
	"net/url"
	"strings"

	"github.com/davecgh/go-spew/spew"
	"github.com/igungor/tlbot"
)

func init() {
	register(cmdWiki)
}

const wikiURL = "https://en.wikipedia.org/w/api.php"

var cmdWiki = &Command{
	Name:      "bkz",
	ShortLine: "bakınız çok ilginçtir",
	Run:       runWiki,
}

func runWiki(b *tlbot.Bot, msg *tlbot.Message) {
	args := msg.Args()
	var txt string
	if len(args) == 0 {
		err := b.SendMessage(msg.Chat, "neye referans vereyim? mesela bana bakın: */bkz İlber Ortaylı*", tlbot.ModeMarkdown, false, nil)
		if err != nil {
			log.Printf("[wiki] Error while sending message '%v'. Err: %v\n", txt, err)
		}
		return
	}

	u, err := url.Parse(wikiURL)
	if err != nil {
		log.Printf("[wiki] Error while parsing URL '%v'. Err: %v\n", wikiURL, err)
		return
	}

	qs := strings.Join(args, " ")
	params := u.Query()
	params.Set("action", "opensearch")
	params.Set("format", "xml")
	params.Set("search", qs)
	u.RawQuery = params.Encode()

	resp, err := httpclient.Get(u.String())
	if err != nil {
		log.Printf("[wiki] Error while fetching article for query '%v'. Err: %v\n", qs, err)
		return
	}
	defer resp.Body.Close()

	var res result
	err = xml.NewDecoder(resp.Body).Decode(&res)
	if err != nil {
		log.Printf("[wiki] Error while decoding response '%v'. Err: %v\n", res, err)
		return
	}

	spew.Dump(res)
	return

	if len(res.Section.Items) == 0 {
		b.SendMessage(msg.Chat, "aradığın referansı bulamadım 🙈", tlbot.ModeMarkdown, true, nil)
		return
	}

	article := res.Section.Items[0]
	txt = article.URL
	err = b.SendMessage(msg.Chat, txt, tlbot.ModeNone, true, nil)
	if err != nil {
		log.Printf("[wiki] Error while sending message to Telegram servers. Err: '%v'\nMessage: %v", err, txt)
		return<commit_msg>Oops. Revert debug returns.<commit_after>package command

import (
	"encoding/xml"
	"log"
	"net/url"
	"strings"

	"github.com/igungor/tlbot"
)

func init() {
	register(cmdWiki)
}

const wikiURL = "https://en.wikipedia.org/w/api.php"

var cmdWiki = &Command{
	Name:      "bkz",
	ShortLine: "bakınız çok ilginçtir",
	Run:       runWiki,
}

func runWiki(b *tlbot.Bot, msg *tlbot.Message) {
	args := msg.Args()
	var txt string
	if len(args) == 0 {
		err := b.SendMessage(msg.Chat, "neye referans vereyim? mesela bana bakın: */bkz İlber Ortaylı*", tlbot.ModeMarkdown, false, nil)
		if err != nil {
			log.Printf("[wiki] Error while sending message '%v'. Err: %v\n", txt, err)
		}
		return
	}

	u, err := url.Parse(wikiURL)
	if err != nil {
		log.Printf("[wiki] Error while parsing URL '%v'. Err: %v\n", wikiURL, err)
		return
	}

	qs := strings.Join(args, " ")
	params := u.Query()
	params.Set("action", "opensearch")
	params.Set("format", "xml")
	params.Set("search", qs)
	u.RawQuery = params.Encode()

	resp, err := httpclient.Get(u.String())
	if err != nil {
		log.Printf("[wiki] Error while fetching article for query '%v'. Err: %v\n", qs, err)
		return
	}
	defer resp.Body.Close()

	var res result
	err = xml.NewDecoder(resp.Body).Decode(&res)
	if err != nil {
		log.Printf("[wiki] Error while decoding response '%v'. Err: %v\n", res, err)
		return
	}

	if len(res.Section.Items) == 0 {
		b.SendMessage(msg.Chat, "aradığın referansı bulamadım 🙈", tlbot.ModeMarkdown, true, nil)
		return
	}

	article := res.Section.Items[0]
	txt = article.URL
	err = b.SendMessage(msg.Chat, txt, tlbot.ModeNone, true, nil)
	if err != nil {
		log.Printf("[wiki] Error while sending message to Telegram servers. Err: '%v'\nMessage: %v", err, txt)
		return
{'fraction_non_alphanumeric': 0.17055144968732233, 'fraction_numerical': 0.0017055144968732233, 'mean_word_length': 3.710843373493976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '6764820', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1406, 'n_words': 353}