<commit_before>package modules

import (
    "github.com/bwmarrin/discordgo"
    "git.lukas.moe/sn0w/Karen/ratelimits"
    "git.lukas.moe/sn0w/Karen/helpers"
    "git.lukas.moe/sn0w/Karen/cache"
    "git.lukas.moe/sn0w/Karen/metrics"
    "fmt"
    "git.lukas.moe/sn0w/Karen/logger"
    "strconv"
)

// Init warms the caches and initializes the plugins
func Init(session *discordgo.Session) {
    pluginCount := len(PluginList)
    triggerCount := len(TriggerPluginList)
    pluginCache = make(map[string]*Plugin)
    triggerCache = make(map[string]*TriggerPlugin)

    logTemplate := "[PLUG] %s reacts to [ %s]"
    listeners := ""

    for i := 0; i < pluginCount; i++ {
        ref := &PluginList[i]

        for _, cmd := range (*ref).Commands() {
            pluginCache[cmd] = ref
            listeners += cmd + " "
        }

        logger.INFO.L("modules", fmt.Sprintf(
            logTemplate,
            helpers.Typeof(*ref),
            listeners,
        ))
        listeners = ""

        (*ref).Init(session)
    }

    logTemplate = "[TRIG] %s gets triggered by [ %s]"
    for i := 0; i < triggerCount; i++ {
        ref := &TriggerPluginList[i]

        for _, trigger := range (*ref).Triggers() {
            triggerCache[trigger] = ref
            listeners += trigger + " "
        }

        logger.INFO.L("modules", fmt.Sprintf(
            logTemplate,
            helpers.Typeof(*ref),
            listeners,
        ))
        listeners = ""
    }

    logger.INFO.L(
        "modules",
        "Initializer finished. Loaded " + strconv.Itoa(len(PluginList)) + " plugins and " + strconv.Itoa(len(TriggerPluginList)) + " triggers",
    )
}

// command - The command that triggered this execution
// content - The content without command
// msg     - The message object
// session - The discord session
func CallBotPlugin(command string, content string, msg *discordgo.Message) {
    // Defer a recovery in case anything panics
    defer helpers.RecoverDiscord(msg)

    // Consume a key for this action
    ratelimits.Container.Drain(1, msg.Author.ID)

    // Track metrics
    metrics.CommandsExecuted.Add(1)

    // Call the module
    if ref, ok := pluginCache[command]; ok {
        (*ref).Action(command, content, msg, cache.GetSession())
    }
}

// msg     - The message that triggered the execution
// session - The discord session
func CallTriggerPlugin(trigger string, content string, msg *discordgo.Message) {
    // Defer a recovery in case anything panics
    defer helpers.RecoverDiscord(msg)

    // Consume a key for this action
    ratelimits.Container.Drain(1, msg.Author.ID)

    // Redirect trigger
    if ref, ok := triggerCache[trigger]; ok {
        (*ref).Response(trigger, content)
    }
}<commit_msg>Fix triggerplugin responses<commit_after>package modules

import (
    "github.com/bwmarrin/discordgo"
    "git.lukas.moe/sn0w/Karen/ratelimits"
    "git.lukas.moe/sn0w/Karen/helpers"
    "git.lukas.moe/sn0w/Karen/cache"
    "git.lukas.moe/sn0w/Karen/metrics"
    "fmt"
    "git.lukas.moe/sn0w/Karen/logger"
    "strconv"
)

// Init warms the caches and initializes the plugins
func Init(session *discordgo.Session) {
    pluginCount := len(PluginList)
    triggerCount := len(TriggerPluginList)
    pluginCache = make(map[string]*Plugin)
    triggerCache = make(map[string]*TriggerPlugin)

    logTemplate := "[PLUG] %s reacts to [ %s]"
    listeners := ""

    for i := 0; i < pluginCount; i++ {
        ref := &PluginList[i]

        for _, cmd := range (*ref).Commands() {
            pluginCache[cmd] = ref
            listeners += cmd + " "
        }

        logger.INFO.L("modules", fmt.Sprintf(
            logTemplate,
            helpers.Typeof(*ref),
            listeners,
        ))
        listeners = ""

        (*ref).Init(session)
    }

    logTemplate = "[TRIG] %s gets triggered by [ %s]"
    for i := 0; i < triggerCount; i++ {
        ref := &TriggerPluginList[i]

        for _, trigger := range (*ref).Triggers() {
            triggerCache[trigger] = ref
            listeners += trigger + " "
        }

        logger.INFO.L("modules", fmt.Sprintf(
            logTemplate,
            helpers.Typeof(*ref),
            listeners,
        ))
        listeners = ""
    }

    logger.INFO.L(
        "modules",
        "Initializer finished. Loaded " + strconv.Itoa(len(PluginList)) + " plugins and " + strconv.Itoa(len(TriggerPluginList)) + " triggers",
    )
}

// command - The command that triggered this execution
// content - The content without command
// msg     - The message object
// session - The discord session
func CallBotPlugin(command string, content string, msg *discordgo.Message) {
    // Defer a recovery in case anything panics
    defer helpers.RecoverDiscord(msg)

    // Consume a key for this action
    ratelimits.Container.Drain(1, msg.Author.ID)

    // Track metrics
    metrics.CommandsExecuted.Add(1)

    // Call the module
    if ref, ok := pluginCache[command]; ok {
        (*ref).Action(command, content, msg, cache.GetSession())
    }
}

// msg     - The message that triggered the execution
// session - The discord session
func CallTriggerPlugin(trigger string, content string, msg *discordgo.Message) {
    // Defer a recovery in case anything panics
    defer helpers.RecoverDiscord(msg)

    // Consume a key for this action
    ratelimits.Container.Drain(1, msg.Author.ID)

    // Redirect trigger
    if ref, ok := triggerCache[trigger]; ok {
        cache.GetSession().ChannelMessageSend(
            msg.ChannelID,
            (*ref).Response(trigger, content),
        )
    }
}
{'fraction_non_alphanumeric': 0.12582545065143674, 'fraction_numerical': 0.003569516330537212, 'mean_word_length': 2.3576992210904733, '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': '3464426', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1731, 'n_words': 408}