<commit_before>package main

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

	_ "github.com/lib/pq"
	"github.com/spf13/viper"
	"github.com/willis7/slack"
)

func init() {
	viper.SetConfigName("app_config")
	viper.AddConfigPath(".")
	if err := viper.ReadInConfig(); err != nil {
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
}

func main() {

	mux := slack.NewEventMux()
	mux.Handle("message", slack.HandlerFunc(RTMMessage))

	token := viper.GetString("slack.token")
	client := slack.NewClient(token, mux)
	client.Connect()
	defer client.Close()
	go client.Dispatch()

	sigterm := make(chan os.Signal)
	signal.Notify(sigterm, os.Interrupt)
	for {
		select {
		case <-sigterm:
			log.Println("terminate signal recvd")
			err := client.Shutdown()
			if err != nil {
				log.Println("write close:", err)
				return
			}
			select {
			case <-time.After(time.Second):
			}
			client.Close()
			return
		}
	}
}

func RTMMessage(msg *slack.Message, c *slack.Client) {
	parts := strings.Fields(msg.Text)
	if len(parts) == 3 && parts[1] == "define" {
		// TODO: concurrently call to the DB and postMessage
		c.PostMessage(&slack.Message{Type: msg.Type, Channel: msg.Channel, Text: fmt.Sprintf("%s means - ", parts[2])})
		// NOTE: the Message object is copied, this is intentional
	} else {
		// huh?
		msg.Text = fmt.Sprintf("sorry, that does not compute\n")
		c.PostMessage(msg)
	}
}<commit_msg>Housekeeping :house_with_garden:<commit_after>package main

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

	_ "github.com/lib/pq"
	"github.com/spf13/viper"
	"github.com/willis7/slack"
)

func init() {
	viper.SetConfigName("app_config")
	viper.AddConfigPath(".")
	if err := viper.ReadInConfig(); err != nil {
		panic(fmt.Errorf("fatal error config file: %s", err))
	}
}

func main() {

	mux := slack.NewEventMux()
	mux.Handle("message", slack.HandlerFunc(RTMMessage))

	token := viper.GetString("slack.token")
	client := slack.NewClient(token, mux)
	client.Connect()
	defer client.Close()
	go client.Dispatch()

	sigterm := make(chan os.Signal)
	signal.Notify(sigterm, os.Interrupt)
	for {
		select {
		case <-sigterm:
			log.Println("terminate signal recvd")
			err := client.Shutdown()
			if err != nil {
				log.Println("write close:", err)
				return
			}
			select {
			case <-time.After(time.Second):
			}
			client.Close()
			return
		}
	}
}

// RTMMessage is a HandlerFunc implementation which handles the "message" event
func RTMMessage(msg *slack.Message, c *slack.Client) {
	parts := strings.Fields(msg.Text)
	if len(parts) == 3 && parts[1] == "define" {
		// TODO: concurrently call to the DB and postMessage
		c.PostMessage(&slack.Message{Type: msg.Type, Channel: msg.Channel, Text: fmt.Sprintf("%s means - ", parts[2])})
		// NOTE: the Message object is copied, this is intentional
	} else {
		// huh?
		msg.Text = fmt.Sprintf("sorry, that does not compute\n")
		c.PostMessage(msg)
	}
}
{'fraction_non_alphanumeric': 0.16336971350613916, 'fraction_numerical': 0.004092769440654843, 'mean_word_length': 3.738287560581583, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2151493', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1079, 'n_words': 242}