aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moulberry-bush/neuConfigSearch.ts
blob: 5833dfd423acfc2eea3348dcb69e88c5b48b47c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {ArgType, BotCommand, colors, CommandMessage, OptArgType, SlashMessage} from "#lib";
import {ApplicationCommandOptionType} from "discord-api-types/v10";
import {ConfigOption, latestData as neuConfigData, NEUFileLocation} from '#src/services/neumeta.ts';


export default class NeuConfigSearch extends BotCommand {
    public constructor() {
        super('neuconfig', {
            aliases: ["neuconfig", "neucfg", "neuoption"],
            category: "Moulberry's Bush",
            description: 'Query config options of the NEU mod',
            usage: ['neuconfig [configName]', 'neuconfig [configSearch]'],
            examples: ['neuconfig doOamNotif'],
            args: [
                {
                    id: 'search',
                    optional: false,
                    description: "Search term to find.",
                    type: 'string',
                    slashType: ApplicationCommandOptionType.String,
                    // autocomplete: true
                },
            ],
            slash: true,
            clientPermissions: ['EmbedLinks'],
            clientCheckChannel: true,
            userPermissions: [],
        });
    }

    findOptionByFullPath(category: string, option: string): ConfigOption | null {
        category = category.toLowerCase();
        option = option.toLowerCase();
        return neuConfigData.categories
            .find(it => it.useReference.member.toLowerCase() === category)
            ?.options
            ?.find(it => it.reference.member.toLowerCase() === option) ?? null;
    }


    public override async exec(message: CommandMessage | SlashMessage, args: { search: ArgType<'string'> }) {
        const fullPath = args.search.match(/([^.]).([^.]+)/);
        if (fullPath) {
            let result = this.findOptionByFullPath(fullPath[1], fullPath[2]);
            if (result) {
                await this.showResult(message, result);
            }
        }
    }


    getUrl(location: NEUFileLocation): string {
        return `https://github.com/NotEnoughUpdates/NotEnoughUpdates/blob/master/${location.filename}`
            + (location.line ? `#L${location.line}` : '');
    }

    async showResult(message: CommandMessage | SlashMessage, result: ConfigOption) {
        await message.reply({
            embeds: [
                {
                    title: result.name,
                    color: colors.default,
                    description: result.description,
                    url: this.getUrl(result.location),
                    fields: [
                    ],
                }
            ]
        })
    }
}