<commit_before>package plugins

import (
    "github.com/bwmarrin/discordgo"
    "github.com/sn0w/Karen/helpers"
    "net/url"
    "regexp"
    "strings"
)

type Weather struct{}

func (w Weather) Commands() []string {
    return []string{
        "weather",
        "wttr",
    }
}

func (w Weather) Init(session *discordgo.Session) {

}

func (w Weather) Action(command string, content string, msg *discordgo.Message, session *discordgo.Session) {
    session.ChannelTyping(msg.ChannelID)

    if content == "" {
        session.ChannelMessageSend(msg.ChannelID, "You should pass a city :thinking:")
        return
    }

    text := string(helpers.NetGetUA("http://wttr.in/" + url.QueryEscape(content), "curl/7.51.0"))
    lines := strings.Split(text, "\n")

    session.ChannelMessageSend(
        msg.ChannelID,
        "```\n" +
            regexp.MustCompile("\\[.*?m").ReplaceAllString(strings.Join(lines[0:7], "\n"), "") +
            "\n```",
    )
}<commit_msg>Catch wttr.in errors | Fixes #4<commit_after>package plugins

import (
    "github.com/bwmarrin/discordgo"
    "github.com/sn0w/Karen/helpers"
    "net/url"
    "regexp"
    "strings"
)

type Weather struct{}

func (w Weather) Commands() []string {
    return []string{
        "weather",
        "wttr",
    }
}

func (w Weather) Init(session *discordgo.Session) {

}

func (w Weather) Action(command string, content string, msg *discordgo.Message, session *discordgo.Session) {
    session.ChannelTyping(msg.ChannelID)

    if content == "" {
        session.ChannelMessageSend(msg.ChannelID, "You should pass a city :thinking:")
        return
    }

    text := string(helpers.NetGetUA("http://wttr.in/" + url.QueryEscape(content), "curl/7.51.0"))
    if text == "ERROR" {
        session.ChannelMessageSend(msg.ChannelID, "Couldn't find that city :frowning:")
        return
    }

    lines := strings.Split(text, "\n")

    session.ChannelMessageSend(
        msg.ChannelID,
        "```\n" +
            regexp.MustCompile("\\[.*?m").ReplaceAllString(strings.Join(lines[0:7], "\n"), "") +
            "\n```",
    )
}
{'fraction_non_alphanumeric': 0.16452074391988555, 'fraction_numerical': 0.00715307582260372, 'mean_word_length': 2.793851717902351, 'pattern_counts': {'":': 0, '<': 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': '3053979', 'n_tokens_mistral': 735, 'n_tokens_neox': 701, 'n_words': 134}