mrmBot-Matrix/utils/handler.js

33 lines
1.2 KiB
JavaScript
Raw Normal View History

import { paths, commands, info, aliases as _aliases } from "./collections.js";
import { log } from "./logger.js";
let queryValue = 0;
2019-09-13 20:02:41 +00:00
// load command into memory
export async function load(command, soundStatus) {
const { default: props } = await import(`../${command}?v=${queryValue}`);
queryValue++;
if (props.requires.includes("mashape") && process.env.MASHAPE === "") return log("warn", `Mashape/RapidAPI info not provided in config, skipped loading command ${command}...`);
if (props.requires.includes("sound") && soundStatus) return log("warn", `Failed to connect to some Lavalink nodes, skipped loading command ${command}...`);
const commandArray = command.split("/");
const commandName = commandArray[commandArray.length - 1].split(".")[0];
paths.set(commandName, command);
commands.set(commandName, props);
info.set(commandName, {
category: commandArray[2],
description: props.description,
aliases: props.aliases,
params: props.arguments,
flags: props.flags
});
2019-09-13 20:02:41 +00:00
if (props.aliases) {
for (const alias of props.aliases) {
_aliases.set(alias, commandName);
paths.set(alias, command);
}
2019-09-13 20:02:41 +00:00
}
return false;
}