<commit_before>/* 	kylixor.go
_________________________________
Main code for Kylixor Discord Bot
<NAME>
kylixor.com
*/

package main

import (
	"encoding/json"
	"fmt"
	"math/rand"
	"os"
	"os/signal"
	"strings"
	"syscall"
	"time"

	"github.com/bwmarrin/discordgo"
	"github.com/jasonlvhit/gocron"
)

// ----- GLOBAL VARIABLES -----

//Config - structure to hold variables from the config file
type Config struct {
	Admin  string //Admin's Discord ID
	APIKey string //Discord bot api key
	Coins  string //Name of currency that bot uses (i.e. <gold> coins)
	Follow bool   //Whether or not the bot joins/follows into voice channels for anthems
	LogID  string //ID of channel for logging
	Prefix string //Prefix the bot will respond to
	Status string //Status of the bot (Playing <v1.0>)
}

var (
	config              *Config                    //Config structure from file
	currentVoiceChannel *discordgo.VoiceConnection //Current voice channel bot is in, nil if none
	self                *discordgo.User            //discord user type of self (for storing bots user account)
	err                 error
)

//InitConfFile - Initialize config file if one is not found
func InitConfFile() {
	//Default values
	config.Prefix = "k!"
	config.Status = "k!help"

	//Create and indent proper json output for the config
	configData, err := json.MarshalIndent(config, "", "    ")
	if err != nil {
		panic(err)
	}

	//Create folder for data
	_ = os.Mkdir("data", 0755)

	// Open file
	jsonFile, err := os.Create("data/conf.json")
	if err != nil {
		panic(err)
	}
	// Write to file
	_, err = jsonFile.Write(configData)
	if err != nil {
		panic(err)
	}
	// Cleanup
	jsonFile.Close()
}

//ReadConfig - Read in config file into Config structure
func (c *Config) ReadConfig() {
	file, _ := os.Open("data/conf.json")
	decoder := json.NewDecoder(file)
	err = decoder.Decode(&c)
	if err != nil {
		panic(err)
	}
	file.Close()
}

//WriteConfig - Write out the current Config structure to file, indented nicely
func (c *Config) WriteConfig() {
	//Indent so its readable
	configData, err := json.MarshalIndent(c, "", "    ")
	if err != nil {
		panic(err)
	}
	//Open file
	jsonFile, err := os.Create("data/conf.json")
	if err != nil {
		panic(err)
	}
	// Write to file
	_, err = jsonFile.Write(configData)
	if err != nil {
		panic(err)
	}
	// Cleanup
	jsonFile.Close()
}

//UpdateConfig - update configuration file by reading then writing
//Updates config file to correct syntax
func (c *Config) UpdateConfig() {
	config.ReadConfig()
	config.WriteConfig()
}

//ResetDailies - Function to call once a day to reset dailies
func ResetDailies() {
	// for j := range USArray.Users {
	// 	USArray.Users[j].Dailies = false
	// }
	// USArray.WriteUserFile()
}

//------------------------------------------------------------------------------
//-----------------               M A I N ( )				--------------------
//------------------------------------------------------------------------------
func main() {
	//Get random seed for later random number generation
	rand.Seed(time.Now().Unix())

	// Read in config file if exists
	if _, err := os.Stat("data/conf.json"); os.IsNotExist(err) {
		fmt.Println("\nCannot find conf.json, creating new...")
		InitConfFile()
	}

	// Update config to account for any data structure changes
	config.UpdateConfig()

	// Read in user data file if exists
	// if _, err := os.Stat("data/users.json"); os.IsNotExist(err) {
		// fmt.Println("\nCannot find users.json, creating new...")
		// InitUserFile()
	// }

	// Reset all anthems
	// USArray.ReadUserFile()
	// for j := range USArray.Users {
	// 	USArray.Users[j].PlayAnthem = true
	// }
	// USArray.WriteUserFile

	//Check to see if bot token is provided
	if config.APIKey == "" {
		fmt.Println("No token provided. Please place your API key into the config.json file")
		return
	}

	// Create a new Discord session using the provided bot token.
	ky, err := discordgo.New("Bot " + config.APIKey)
	if err != nil {
		fmt.Println("Error creating Discord session: ", err)
		return
	}

	// Register ready for the ready event
	ky.AddHandlerOnce(ready)

	// Register messageCreate for the messageCreate events
	ky.AddHandler(messageCreate)<commit_msg>stpuid small fix<commit_after>/* 	kylixor.go
_________________________________
Main code for Kylixor Discord Bot
<NAME>
kylixor.com
*/

package main

import (
	"encoding/json"
	"fmt"
	"math/rand"
	"os"
	"os/signal"
	"strings"
	"syscall"
	"time"

	"github.com/bwmarrin/discordgo"
	"github.com/jasonlvhit/gocron"
)

// ----- GLOBAL VARIABLES -----

//Config - structure to hold variables from the config file
type Config struct {
	Admin  string //Admin's Discord ID
	APIKey string //Discord bot api key
	Coins  string //Name of currency that bot uses (i.e. <gold> coins)
	Follow bool   //Whether or not the bot joins/follows into voice channels for anthems
	LogID  string //ID of channel for logging
	Prefix string //Prefix the bot will respond to
	Status string //Status of the bot (Playing <v1.0>)
}

var (
	config              = Config{}                 //Config structure from file
	currentVoiceChannel *discordgo.VoiceConnection //Current voice channel bot is in, nil if none
	self                *discordgo.User            //discord user type of self (for storing bots user account)
	err                 error
)

//InitConfFile - Initialize config file if one is not found
func InitConfFile() {
	//Default values
	config.Prefix = "k!"
	config.Status = "k!help"

	//Create and indent proper json output for the config
	configData, err := json.MarshalIndent(config, "", "    ")
	if err != nil {
		panic(err)
	}

	//Create folder for data
	_ = os.Mkdir("data", 0755)

	// Open file
	jsonFile, err := os.Create("data/conf.json")
	if err != nil {
		panic(err)
	}
	// Write to file
	_, err = jsonFile.Write(configData)
	if err != nil {
		panic(err)
	}
	// Cleanup
	jsonFile.Close()
}

//ReadConfig - Read in config file into Config structure
func (c *Config) ReadConfig() {
	file, _ := os.Open("data/conf.json")
	decoder := json.NewDecoder(file)
	err = decoder.Decode(&c)
	if err != nil {
		panic(err)
	}
	file.Close()
}

//WriteConfig - Write out the current Config structure to file, indented nicely
func (c *Config) WriteConfig() {
	//Indent so its readable
	configData, err := json.MarshalIndent(c, "", "    ")
	if err != nil {
		panic(err)
	}
	//Open file
	jsonFile, err := os.Create("data/conf.json")
	if err != nil {
		panic(err)
	}
	// Write to file
	_, err = jsonFile.Write(configData)
	if err != nil {
		panic(err)
	}
	// Cleanup
	jsonFile.Close()
}

//UpdateConfig - update configuration file by reading then writing
//Updates config file to correct syntax
func (c *Config) UpdateConfig() {
	config.ReadConfig()
	config.WriteConfig()
}

//ResetDailies - Function to call once a day to reset dailies
func ResetDailies() {
	// for j := range USArray.Users {
	// 	USArray.Users[j].Dailies = false
	// }
	// USArray.WriteUserFile()
}

//------------------------------------------------------------------------------
//-----------------               M A I N ( )				--------------------
//------------------------------------------------------------------------------
func main() {
	//Get random seed for later random number generation
	rand.Seed(time.Now().Unix())

	// Read in config file if exists
	if _, err := os.Stat("data/conf.json"); os.IsNotExist(err) {
		fmt.Println("\nCannot find conf.json, creating new...")
		InitConfFile()
	}

	// Update config to account for any data structure changes
	config.UpdateConfig()

	// Read in user data file if exists
	// if _, err := os.Stat("data/users.json"); os.IsNotExist(err) {
	// fmt.Println("\nCannot find users.json, creating new...")
	// InitUserFile()
	// }

	// Reset all anthems
	// USArray.ReadUserFile()
	// for j := range USArray.Users {
	// 	USArray.Users[j].PlayAnthem = true
	// }
	// USArray.WriteUserFile

	//Check to see if bot token is provided
	if config.APIKey == "" {
		fmt.Println("No token provided. Please place your API key into the config.json file")
		return
	}

	// Create a new Discord session using the provided bot token.
	ky, err := discordgo.New("Bot " + config.APIKey)
	if err != nil {
		fmt.Println("Error creating Discord session: ", err)
		return
	}

	// Register ready for the ready event
	ky.AddHandlerOnce(ready)

	// Register messageCreate for the messageCreate events
	ky.AddHandler(messageCreate)
{'fraction_non_alphanumeric': 0.16811732443066651, 'fraction_numerical': 0.0014307857398354596, 'mean_word_length': 2.4906367041198503, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '163540', 'n_tokens_mistral': 2737, 'n_tokens_neox': 2642, 'n_words': 847}