<commit_before>package bot

import (
	"context"
	"fmt"
	"strings"
	"time"

	"github.com/FederationOfFathers/dashboard/db"
	"github.com/FederationOfFathers/dashboard/messaging"
	"github.com/bwmarrin/discordgo"
	"github.com/honeycombio/beeline-go"
	"go.uber.org/zap"
)

type DiscordAPI struct {
	Config                DiscordCfg
	discord               *discordgo.Session
	assignmentMsgs        map[string]map[string]string
	memberChannelAssignID string
}

type DiscordCfg struct {
	ClientId        string         `yaml:"appClientId"`
	Token           string         `yaml:"botToken"`
	StreamChannelId string         `yaml:"streamChannelId"`
	GuildId         string         `yaml:"guildId"`
	RoleCfg         DiscordRoleCfg `yaml:"roleConfig"`
}

type GuildChannels struct {
	Categories []ChannelCategory
}

type ChannelCategory struct {
	ID       string
	Name     string
	Channels []*Channel
}

type Channel struct {
	ID   string
	Name string
}

var discordApi *DiscordAPI

func NewDiscordAPI(cfg DiscordCfg) *DiscordAPI {
	return &DiscordAPI{
		Config: cfg,
	}
}

// StartDiscord starts Discord API bot
func StartDiscord(cfg DiscordCfg) *DiscordAPI {
	discordApi = NewDiscordAPI(cfg)
	discordApi.Connect()
	if cfg.RoleCfg.ChannelId != "" {
		discordApi.StartRoleHandlers()
	}

	discordApi.memberChannelAssignID = discordApi.channelIDByName(channelAssignName, memberCategoryID)

	//add handlers
	discordApi.discord.AddHandler(discordApi.roleAssignmentHandler)
	discordApi.discord.AddHandler(discordApi.teamCommandHandler)
	discordApi.discord.AddHandler(discordApi.verifiedEventsHandler)

	go discordApi.mindTempChannels()

	//go discordApi.setChannelAssignMessage()

	discordApi.discord.UpdateGameStatus(0, "ui.fofgaming.com | !team")

	// data cache
	data.load()
	populateLists()
	go mindLists()

	return discordApi

}

// verifiedEventsHandler checks if the user is verified before running the handler
func (d *DiscordAPI) verifiedEventsHandler(s *discordgo.Session, event *discordgo.MessageCreate) {
	if event.GuildID != d.Config.GuildId {
		return
	}<commit_msg>Add slash command registration and handlers<commit_after>package bot

import (
	"context"
	"fmt"
	"strings"
	"time"

	"github.com/FederationOfFathers/dashboard/db"
	"github.com/FederationOfFathers/dashboard/messaging"
	"github.com/bwmarrin/discordgo"
	"github.com/honeycombio/beeline-go"
	"go.uber.org/zap"
)

type DiscordAPI struct {
	Config                DiscordCfg
	discord               *discordgo.Session
	assignmentMsgs        map[string]map[string]string
	memberChannelAssignID string
}

type DiscordCfg struct {
	ClientId        string         `yaml:"appClientId"`
	Token           string         `yaml:"botToken"`
	StreamChannelId string         `yaml:"streamChannelId"`
	GuildId         string         `yaml:"guildId"`
	RoleCfg         DiscordRoleCfg `yaml:"roleConfig"`
}

type GuildChannels struct {
	Categories []ChannelCategory
}

type ChannelCategory struct {
	ID       string
	Name     string
	Channels []*Channel
}

type Channel struct {
	ID   string
	Name string
}

var discordApi *DiscordAPI

func NewDiscordAPI(cfg DiscordCfg) *DiscordAPI {
	return &DiscordAPI{
		Config: cfg,
	}
}

// StartDiscord starts Discord API bot
func StartDiscord(cfg DiscordCfg) *DiscordAPI {
	discordApi = NewDiscordAPI(cfg)
	discordApi.Connect()
	if cfg.RoleCfg.ChannelId != "" {
		discordApi.StartRoleHandlers()
	}

	discordApi.memberChannelAssignID = discordApi.channelIDByName(channelAssignName, memberCategoryID)

	// register slash command
	discordApi.registerSlashStream()

	//add handlers
	discordApi.discord.AddHandler(discordApi.slashCommandHandlers)
	discordApi.discord.AddHandler(discordApi.roleAssignmentHandler)
	discordApi.discord.AddHandler(discordApi.teamCommandHandler)
	discordApi.discord.AddHandler(discordApi.verifiedEventsHandler)

	go discordApi.mindTempChannels()

	//go discordApi.setChannelAssignMessage()

	discordApi.discord.UpdateGameStatus(0, "ui.fofgaming.com | !team")

	// data cache
	data.load()
	populateLists()
	go mindLists()

	return discordApi

}

// verifiedEventsHandler checks if the user is verified before running the handler
func (d *DiscordAPI) verifiedEventsHandler(s *discordgo.Session, event *discordgo.MessageCreate) {
	if event.GuildID != d.Config.GuildId {
		return
	}
{'fraction_non_alphanumeric': 0.09248014946286783, 'fraction_numerical': 0.00046707146193367583, 'mean_word_length': 4.185230024213075, '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': '6908562', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1392, 'n_words': 276}