aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moulberry-bush/neuConfigSearch.ts
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-10-18 00:44:04 +0200
committernea <romangraef@gmail.com>2022-10-18 00:44:04 +0200
commit76e9d147ac5b67aa5ad38e98fe0cce3334d44b8f (patch)
tree89c26fb297b881cf56d3c8ce2186821197241be2 /src/commands/moulberry-bush/neuConfigSearch.ts
parent46d087e17a549a3b1bb9797714d5c3df440b67f5 (diff)
downloadtanzanite-76e9d147ac5b67aa5ad38e98fe0cce3334d44b8f.tar.gz
tanzanite-76e9d147ac5b67aa5ad38e98fe0cce3334d44b8f.tar.bz2
tanzanite-76e9d147ac5b67aa5ad38e98fe0cce3334d44b8f.zip
[WIP] Please help, Mooniefeature/neaconfig
Diffstat (limited to 'src/commands/moulberry-bush/neuConfigSearch.ts')
-rw-r--r--src/commands/moulberry-bush/neuConfigSearch.ts71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/commands/moulberry-bush/neuConfigSearch.ts b/src/commands/moulberry-bush/neuConfigSearch.ts
new file mode 100644
index 0000000..5833dfd
--- /dev/null
+++ b/src/commands/moulberry-bush/neuConfigSearch.ts
@@ -0,0 +1,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: [
+ ],
+ }
+ ]
+ })
+ }
+} \ No newline at end of file