<commit_before><template>
    <pre>
    /*
    {{ license }}
    */
    </pre>
</template>

<script lang="ts">
    import * as _ from 'lodash';
    import {Component, Prop, Vue, Watch} from 'vue-property-decorator';
    import {IPlugin} from '../lib/IPlugin';

    @Component({
        name: 'plugin-generator'
    })
    export default class PluginGenerator extends Vue {
        pluginBuilder: any;

        @Prop()
        pluginDefinition: IPlugin;

        get className() {
            if (this.pluginDefinition.name.trim().length === 0) {
                return 'SAMPLE_PLUGIN';
            }

            let literalNumbers = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'];
            let pluginClassName = this.pluginDefinition.name.replace(/[^A-Za-z0-9_]/g, '');

            let tryParse = parseInt(pluginClassName.charAt(0));

            if (!isNaN(tryParse)) {
                pluginClassName = literalNumbers[tryParse] + pluginClassName.substring(1);
            }

            return pluginClassName;
        }

        get license() {
            let currentYear = new Date().getFullYear().toString();

            if (this.pluginDefinition.license === null) {
                return `Copyright (C) ${currentYear} ${this.pluginDefinition.author}\nAll rights reserved.`;
            }

            return this.pluginDefinition.license.body
                .replace('{year}', currentYear)
                .replace('{author}', this.pluginDefinition.author)
                .replace('{name}', this.pluginDefinition.name)
            ;
        }

        get sortedEvents() {
            return _.sortBy(this.pluginDefinition.events, ['name']);
        }

        buildInitFunction() {
            let initBody = [];

            this.sortedEvents.forEach(function (event) {
                // @todo generate a Register();
                // initBody.push(event['name']);
            });

            if (this.pluginDefinition.slashCommands.length > 0) {
                if (this.sortedEvents.length > 0) {
                    // @todo generate a new line
                    // initBody.push()
                }

                this.pluginDefinition.slashCommands.forEach(function (command: any) {
                    // @todo create a function call to bz_registerCustomSlashCommand
                    // initBody.push(LanguageHelpers.createFunctionCall('bz_registerCustomSlashCommand', [
                    //     LanguageHelpers.createString(command),
                    //     'this'
                    // ]));
                });
            }

            // @todo convert this into a CppClass instance
            // this.pluginBuilder.implementFunction('void', 'Init', initBody);
        }

        @Watch('pluginDefinition.name')
        onPluginNameUpdateEvent() {
            this.buildInitFunction();
        }
<commit_msg>Begin support for event/slash command registration<commit_after><template>
    <pre>
    /*
    {{ license }}
    */

    {{ pluginBody }}
    </pre>
</template>

<script lang="ts">
    import * as _ from 'lodash';
    import {Component, Prop, Vue, Watch} from 'vue-property-decorator';
    import {IPlugin} from '../lib/IPlugin';
    import {CPPClass} from "../alyssa/CPPClass";
    import {CPPHelper} from '../alyssa/CPPHelper';
    import {CPPFunction} from "../alyssa/CPPFunction";
    import {CPPVariable} from '../alyssa/CPPVariable';
    import {CPPVisibility} from '../alyssa/CPPVisibility';
    import {CPPFormatter} from "../alyssa/CPPFormatter";
    import {CPPWritableObject} from "../alyssa/CPPWritableObject";

    @Component({
        name: 'plugin-generator'
    })
    export default class PluginGenerator extends Vue {
        pluginBuilder: CPPClass;

        @Prop()
        pluginDefinition: IPlugin;

        created() {
            this.pluginBuilder = new CPPClass(this.className);
        }

        get className() {
            if (this.pluginDefinition.name.trim().length === 0) {
                return 'SAMPLE_PLUGIN';
            }

            let literalNumbers = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'];
            let pluginClassName = this.pluginDefinition.name.replace(/[^A-Za-z0-9_]/g, '');

            let tryParse = parseInt(pluginClassName.charAt(0));

            if (!isNaN(tryParse)) {
                pluginClassName = literalNumbers[tryParse] + pluginClassName.substring(1);
            }

            return pluginClassName;
        }

        get pluginBody() {
            let formatter = new CPPFormatter({
                indentWithSpaces: true,
                indentSpaceCount: 4,
            });

            return this.pluginBuilder.write(formatter, 0);
        }

        get license() {
            let currentYear = new Date().getFullYear().toString();

            if (this.pluginDefinition.license === null) {
                return `Copyright (C) ${currentYear} ${this.pluginDefinition.author}\nAll rights reserved.`;
            }

            return this.pluginDefinition.license.body
                .replace('{year}', currentYear)
                .replace('{author}', this.pluginDefinition.author)
                .replace('{name}', this.pluginDefinition.name)
            ;
        }

        get sortedEvents() {
            return _.sortBy(this.pluginDefinition.events, ['name']);
        }

        buildInitFunction() {
            let initBody = [];

            // Register events
            this.sortedEvents.forEach(function (event) {
                initBody.push(CPPHelper.createFunctionCall('Register', [event.name]));
            });

            // Register slash commands
            if (this.pluginDefinition.slashCommands.length > 0) {
                if (this.sortedEvents.length > 0) {
                    initBody.push(CPPHelper.createEmptyLine());
                }

                this.pluginDefinition.slashCommands.forEach(function (command: any) {
                    initBody.push(CPPHelper.createFunctionCall('bz_registerCustomSlashCommand', [
                        `"${command}"`,
                        'this'
                    ]));
                });
            }

            // Build our Init() function
            let fxn = new CPPFunction('void', 'name', [
                CPPVariable.createConstChar('config')
            ]);
            fxn.implementFunction(initBody);
            fxn.setParentClass(this.pluginBuilder, CPPVisibility.Public);
        }

        @Watch('pluginDefinition.name')
        onPluginNameUpdateEvent() {
            this.buildInitFunction();
        }

{'fraction_non_alphanumeric': 0.12822836429542364, 'fraction_numerical': 0.0024165533907264765, 'mean_word_length': 1.7672377768491434, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '3811971', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1680, 'n_words': 334}