import Plugin from "./Plugin";

export default class MasterPlugin extends Plugin {

    static get plugin() {
        return {
            name: "MasterPlugin",
            description: "",
            help: "This plugin has access to PluginManager and will perform all the 'meta'/'super' actions.",

            type: Plugin.Type.SPECIAL,
            visibility: Plugin.Visibility.HIDDEN,

            needs: {
                database: true,
                utils: true
            }
        };
    }

    constructor(listener, pluginManager) {
        super(listener);

        this.pluginManager = pluginManager;
    }

    onCommand({message, command, args}, reply) {
        if (command !== "help") return;
        const data = this.pluginManager.plugins
            .map(pl => pl.plugin)
            .filter(pl => pl.visibility !== Plugin.Visibility.HIDDEN);
        if (args.length === 0) {
            reply({
                type: "text",
                text: data
                    .map(pl => `${pl.name}: ${pl.description}`)
                    .join("\n"),
                options: {
                    parse_mode: "markdown",
                    disable_web_page_preview: true
                }
            });
        } else {
            const pluginName = args[0].toLowerCase();
            const plugin = data
                .filter(pl => pl.name.toLowerCase() === pluginName)[0];
            reply({
                type: "text",
                text: `*${plugin.name}* - ${plugin.description}\n\n${plugin.help}`,
                options: {
                    parse_mode: "markdown",
                    disable_web_page_preview: true
                }
            });
        }
    }
}
@@ -1001,16 +1001,17 @@
 (pl =%3E %60
+*
 $%7Bpl.nam
@@ -1012,16 +1012,17 @@
 pl.name%7D
+*
 : $%7Bpl.d

Make plugin name bold in /help