<commit_before>package main

// Slack outgoing webhooks are handled here. Requests come in and are run through
// the markov chain to generate a response, which is sent back to Slack.
//
// Create an outgoing webhook in your Slack here:
// https://my.slack.com/services/new/outgoing-webhook

import (
	"encoding/json"
	"log"
	"math/rand"
	"net/http"
	"strconv"
	"strings"
	"time"
//	"fmt"
	"io/ioutil"
)



type whr struct {
	Token		 string `json:"token"`
	Team_ID	 string `json:"team_id"`
	ChannelID  string `json:"channel_id"`
	ChannelName string `json:"channel_name"`
	TS				string `json:"timestamp"`
	UserID		string `json:"user_id"`
	Username string `json:"user_name"`
	Text     string `json:"text"`
	Trigger  string `json:"trigger_word"`
}

func init() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
	//	incomingText := r.PostFormValue("text")
			

			err := r.ParseForm()
			if err != nil {
				panic(err)
			}
			//log.Println("r.Form", r.Form)
		
			txt := r.Form["text"]
			usr := r.Form["user_name"]
			incomingText := txt[0]
			rUsername := usr[0]
		if incomingText != "" && rUsername != "" && rUsername != "slackbot" {
			text := parseText(incomingText)
			log.Printf("Handling incoming request: %s from %s", text,rUsername )

			if text != "" {
				markovChain.Write(text)
			}


			go func() {
				markovChain.Save(stateFile)
			}()

			if rand.Intn(100) <= responseChance || strings.HasPrefix(text, botUsername) || strings.Contains(text,"Dingus") {
				var response whr
				response.Username = botUsername

				response.Text = markovChain.Generate(numWords)
				if strings.HasPrefix(text,"Dingus: compliment me"){
					url := "http://127.0.0.1:56735"
					comp, err := http.Get(url)
					if err != nil {
						log.Fatal(err)
					}
					defer comp.Body.Close()
					compData, err := ioutil.ReadAll(comp.Body)
					if err != nil {
						log.Fatal(err)
					}
					compString := string(compData)
					response.Text = rUsername + ": " + compString
				}
				if strings.HasPrefix(text,"Dingus: roast me"){
					url := "http://127.0.0.1:56736"
					comp, err := http.Get(url)
					if err != nil {
						log.Fatal(err)
					}
					defer comp.Body.Close()
					compData, err := ioutil.ReadAll(comp.Body)
					if err != nil {
						log.Fatal(err)
					}
					compString := string(compData)
					response.Text = rUsername + ": " + compString
				}
				if strings.HasPrefix(text, "Dingus: insult me"){
					url := "http://insult-me-dingus.herokuapp.com/"
					comp, err := http.Get(url)
					if err != nil {
						log.Fatal(err)
					}
					defer comp.Body.Close()
					compData, err := ioutil.ReadAll(comp.Body)
					if err != nil {
						log.Fatal(err)<commit_msg>quote feature<commit_after>package main

// Slack outgoing webhooks are handled here. Requests come in and are run through
// the markov chain to generate a response, which is sent back to Slack.
//
// Create an outgoing webhook in your Slack here:
// https://my.slack.com/services/new/outgoing-webhook

import (
	"encoding/json"
	"log"
	"math/rand"
	"net/http"
	"strconv"
	"strings"
	"time"
//	"fmt"
	"io/ioutil"
)



type whr struct {
	Token		 string `json:"token"`
	Team_ID	 string `json:"team_id"`
	ChannelID  string `json:"channel_id"`
	ChannelName string `json:"channel_name"`
	TS				string `json:"timestamp"`
	UserID		string `json:"user_id"`
	Username string `json:"user_name"`
	Text     string `json:"text"`
	Trigger  string `json:"trigger_word"`
}

func init() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
	//	incomingText := r.PostFormValue("text")
			

			err := r.ParseForm()
			if err != nil {
				panic(err)
			}
			//log.Println("r.Form", r.Form)
		
			txt := r.Form["text"]
			usr := r.Form["user_name"]
			incomingText := txt[0]
			rUsername := usr[0]
		if incomingText != "" && rUsername != "" && rUsername != "slackbot" {
			text := parseText(incomingText)
			log.Printf("Handling incoming request: %s from %s", text,rUsername )

			if text != "" {
				markovChain.Write(text)
			}


			go func() {
				markovChain.Save(stateFile)
			}()

			if rand.Intn(100) <= responseChance || strings.HasPrefix(text, botUsername) || strings.Contains(text,"Dingus") {
				var response whr
				response.Username = botUsername

				response.Text = markovChain.Generate(numWords)
				if strings.HasPrefix(text,"Dingus: compliment me"){
					url := "http://127.0.0.1:56735"
					comp, err := http.Get(url)
					if err != nil {
						log.Fatal(err)
					}
					defer comp.Body.Close()
					compData, err := ioutil.ReadAll(comp.Body)
					if err != nil {
						log.Fatal(err)
					}
					compString := string(compData)
					response.Text = rUsername + ": " + compString
				}
				if strings.HasPrefix(text,"Dingus: roast me"){
					url := "http://127.0.0.1:56736"
					comp, err := http.Get(url)
					if err != nil {
						log.Fatal(err)
					}
					defer comp.Body.Close()
					compData, err := ioutil.ReadAll(comp.Body)
					if err != nil {
						log.Fatal(err)
					}
					compString := string(compData)
					response.Text = rUsername + ": " + compString
				}
				if strings.HasPrefix(text,"Dingus: quote"){
					url := "http://127.0.0.1:56777"
					comp, err := http.Get(url)
					if err != nil {
						log.Fatal(err)
					}
					defer comp.Body.Close()
					compData, err := ioutil.ReadAll(comp.Body)
					if err != nil {
						log.Fatal(err)
					}
					compString := string(compData)
					response.Text = rUsername + ": " + compString
				}

				if strings.HasPrefix(text, "Dingus: insult me"){
					url := "http://insult-me-dingus.herokuapp.com/"
					comp, err := http.Get(url)
					if err != nil {
						log.Fatal(err)
					}
					defer comp.Body.Close()
					compData, err := ioutil.ReadAll(comp.Body)
					if err != nil {
						log.Fatal(err)
{'fraction_non_alphanumeric': 0.15512465373961218, 'fraction_numerical': 0.011253462603878116, 'mean_word_length': 2.773350751143044, 'pattern_counts': {'":': 5, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, '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': '2569017', 'n_tokens_mistral': 2569, 'n_tokens_neox': 2022, 'n_words': 450}