47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
import { encode } from "html-entities";
|
|
|
|
function execute(client, event, args) {
|
|
var name = args.toLowerCase();
|
|
|
|
var command = client.commands.filter(c=>(c.name.toLowerCase()==name || c.command.toLowerCase()==name))[0];
|
|
var module = client.modules.filter(m=>m.name.toLowerCase()==name)[0];
|
|
var specific = command ?? module ?? false;
|
|
|
|
var config = client.config.get(event.sender.roomId);
|
|
|
|
if(args != "") {
|
|
if(!module) {
|
|
client.reply(event, `Module "${args}" not found.\nRun "${process.env.PREFIX}help" for a list of commands and modules.`);
|
|
return;
|
|
}
|
|
|
|
config.set(module.name, !(config.get(module.name) ?? true));
|
|
var state = (config.get(module.name) ? "En" : "Dis") + "abled";
|
|
|
|
var reply = state + " " + module.name;
|
|
var replyHTML = `<b>${state}</b> <code>${encode(module.name)}</code>`;
|
|
|
|
client.reply(event, reply, replyHTML);
|
|
return;
|
|
}
|
|
|
|
var modules = client.modules.map(m=>m.name);
|
|
var enabled = modules.filter(m=>config.get(m)!==false);
|
|
|
|
var reply = `enabled modules:\n${enabled.join(", ")}`;
|
|
var replyHTML = `enabled modules:<br><code>${enabled.join("</code>, <code>")}</code>`;
|
|
|
|
reply += `\navailable modules:\n${modules.join(", ")}`;
|
|
replyHTML += `<br>available modules:<br><code>${modules.join("</code>, <code>")}</code>`;
|
|
|
|
client.reply(event, reply, replyHTML);
|
|
}
|
|
|
|
export default {
|
|
command: "toggle",
|
|
name: "toggle",
|
|
usage: "<module>",
|
|
minPwr: 50,
|
|
desc: "toggle a module on or off in current channel",
|
|
execute
|
|
}
|