<commit_before>package main

import (
	"fmt"
	"os"
	"os/signal"
	"strconv"
	"strings"
	"time"

	"github.com/bluele/slack"
)

var (
	msgOpts = &slack.ChatPostMessageOpt{AsUser: true}
)

//Slackcat client
type Slackcat struct {
	api         *slack.Slack
	queue       *StreamQ
	shutdown    chan os.Signal
	channelID   string
	channelName string
}

func newSlackcat(token, channelName string) *Slackcat {
	sc := &Slackcat{
		api:         slack.New(token),
		queue:       newStreamQ(),
		shutdown:    make(chan os.Signal, 1),
		channelName: channelName,
	}

	res, err := sc.api.AuthTest()
	failOnError(err, "Slack API Error")
	output(fmt.Sprintf("connected to %s as %s", res.Team, res.User))
	sc.channelID = sc.lookupSlackID()

	signal.Notify(sc.shutdown, os.Interrupt)
	return sc
}

type ChannelList struct {
	channels []string
	groups   []string
	ims      []string
	mpims    []string
}

// Return list of all channels by name
func (sc *Slackcat) listChannels() (names []string) {
	list, err := sc.api.ChannelsList()
	failOnError(err)
	for _, c := range list {
		names = append(names, c.Name)
	}
	return names
}

// Return list of all groups by name
func (sc *Slackcat) listGroups() (names []string) {
	list, err := sc.api.GroupsList()
	failOnError(err)
	for _, c := range list {
		names = append(names, c.Name)
	}
	return names
}

// Return list of all ims by name
func (sc *Slackcat) listIms() (names []string) {
	list, err := sc.api.ImList()
	failOnError(err)
	for _, c := range list {
		names = append(names, c.User)
	}
	return names
}

// Lookup Slack id for channel, group, or im by name
func (sc *Slackcat) lookupSlackID() string {
	api := sc.api
	if channel, err := api.FindChannelByName(sc.channelName); err == nil {
		return channel.Id
	}
	if group, err := api.FindGroupByName(sc.channelName); err == nil {
		return group.Id<commit_msg>add user id->name lookup for list opt<commit_after>package main

import (
	"fmt"
	"os"
	"os/signal"
	"strconv"
	"strings"
	"time"

	"github.com/bluele/slack"
)

var (
	msgOpts = &slack.ChatPostMessageOpt{AsUser: true}
)

//Slackcat client
type Slackcat struct {
	api         *slack.Slack
	queue       *StreamQ
	shutdown    chan os.Signal
	channelID   string
	channelName string
}

func newSlackcat(token, channelName string) *Slackcat {
	sc := &Slackcat{
		api:         slack.New(token),
		queue:       newStreamQ(),
		shutdown:    make(chan os.Signal, 1),
		channelName: channelName,
	}

	res, err := sc.api.AuthTest()
	failOnError(err, "Slack API Error")
	output(fmt.Sprintf("connected to %s as %s", res.Team, res.User))
	sc.channelID = sc.lookupSlackID()

	signal.Notify(sc.shutdown, os.Interrupt)
	return sc
}

type ChannelList struct {
	channels []string
	groups   []string
	ims      []string
	mpims    []string
}

// Return list of all channels by name
func (sc *Slackcat) listChannels() (names []string) {
	list, err := sc.api.ChannelsList()
	failOnError(err)
	for _, c := range list {
		names = append(names, c.Name)
	}
	return names
}

// Return list of all groups by name
func (sc *Slackcat) listGroups() (names []string) {
	list, err := sc.api.GroupsList()
	failOnError(err)
	for _, c := range list {
		names = append(names, c.Name)
	}
	return names
}

// Return list of all ims by name
func (sc *Slackcat) listIms() (names []string) {
	users, err := sc.api.UsersList()
	failOnError(err)

	list, err := sc.api.ImList()
	failOnError(err)
	for _, c := range list {
		for _, u := range users {
			if u.Id == c.User {
				names = append(names, u.Name)
				continue
			}
		}
	}
	return names
}

// Lookup Slack id for channel, group, or im by name
func (sc *Slackcat) lookupSlackID() string {
	api := sc.api
	if channel, err := api.FindChannelByName(sc.channelName); err == nil {
		return channel.Id
	}
	if group, err := api.FindGroupByName(sc.channelName); err == nil {
		return group.Id
{'fraction_non_alphanumeric': 0.13451511991657977, 'fraction_numerical': 0.0005213764337851929, 'mean_word_length': 3.456445993031359, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1716033', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1414, 'n_words': 395}