<commit_before>package miniporte

import (
	"log"
	"os"
	"strings"

	irc "github.com/fluffle/goirc/client"
	link "github.com/oz/miniporte/link"
)

type Bot struct {
	Chans  []string
	Config *irc.Config
	Client *irc.Conn
}

func New() *Bot {
	cfg := irc.NewConfig(getEnvOr("IRC_NICK", "miniporte"))
	cfg.SSL = true
	cfg.Me.Name = getEnvOr("IRC_NAME", "Mini-Porte")
	cfg.Me.Ident = getEnvOr("IRC_IDENT", "MiniPorteIRCBot")
	cfg.Server = getEnvOr("IRC_SERVER", "irc.freenode.net:7000")
	cfg.NewNick = func(n string) string { return n + "_" }

	return &Bot{
		Chans:  strings.Split(getEnvOr("IRC_CHANS", "#af83-bots"), ","),
		Config: cfg,
		Client: irc.Client(cfg),
	}
}

func (b *Bot) OnMessage(msg *irc.Line) {
	// Ignore non-public messages
	if !msg.Public() {
		return
	}

	if url := link.Find(msg.Text()); url != "" {
		tags := link.Tags(msg.Text())
		if len(tags) == 0 {
			tags = []string{"private"}
		}
		tags = append(tags, msg.Nick, msg.Target())
		go func() {
			if err := link.Save(url, tags); err != nil {
				b.Client.Privmsg(msg.Target(), "Oops! "+err.Error())
				return
			}
			b.Client.Privmsg(msg.Target(), "Saved!")
		}()
	}
}

func (b *Bot) JoinChannels() {
	log.Println("Joining channels", b.Chans)
	for _, c := range b.Chans {
		b.Client.Join(c)
	}
}

func (b *Bot) Run() {
	ctl := make(chan string)

	// Connected<commit_msg>Don't log success/error for private links<commit_after>package miniporte

import (
	"log"
	"os"
	"strings"

	irc "github.com/fluffle/goirc/client"
	link "github.com/oz/miniporte/link"
)

type Bot struct {
	Chans  []string
	Config *irc.Config
	Client *irc.Conn
}

func New() *Bot {
	cfg := irc.NewConfig(getEnvOr("IRC_NICK", "miniporte"))
	cfg.SSL = true
	cfg.Me.Name = getEnvOr("IRC_NAME", "Mini-Porte")
	cfg.Me.Ident = getEnvOr("IRC_IDENT", "MiniPorteIRCBot")
	cfg.Server = getEnvOr("IRC_SERVER", "irc.freenode.net:7000")
	cfg.NewNick = func(n string) string { return n + "_" }

	return &Bot{
		Chans:  strings.Split(getEnvOr("IRC_CHANS", "#af83-bots"), ","),
		Config: cfg,
		Client: irc.Client(cfg),
	}
}

func (b *Bot) OnMessage(msg *irc.Line) {
	// Ignore non-public messages
	if !msg.Public() {
		return
	}

	if url := link.Find(msg.Text()); url != "" {
		tags := link.Tags(msg.Text())
		if len(tags) == 0 {
			tags = []string{"private"}
		}
		tags = append(tags, msg.Nick, msg.Target())
		go func() {
			if err := link.Save(url, tags); err != nil {
				if !link.IncludesPrivate(tags) {
					b.Client.Privmsg(msg.Target(), "Oops! "+err.Error())
				}
				return
			}
			if !link.IncludesPrivate(tags) {
				b.Client.Privmsg(msg.Target(), "Saved!")
			}
		}()
	}
}

func (b *Bot) JoinChannels() {
	log.Println("Joining channels", b.Chans)
	for _, c := range b.Chans {
		b.Client.Join(c)
	}
}

func (b *Bot) Run() {
	ctl := make(chan string)

	// Connected
{'fraction_non_alphanumeric': 0.1917320028510335, 'fraction_numerical': 0.004989308624376337, 'mean_word_length': 3.5941080196399344, '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': '686966', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1152, 'n_words': 230}