add toggle command and admin-only command checks
This commit is contained in:
parent
e9ac4a1c43
commit
073540d1d5
3 changed files with 67 additions and 2 deletions
13
commands/join.js
Normal file
13
commands/join.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { exec } from "node:child_process";
|
||||
|
||||
function execute(client, event, args) {
|
||||
client.joinRoom(args);
|
||||
}
|
||||
|
||||
export default {
|
||||
command: "join",
|
||||
name: "join",
|
||||
owner: true,
|
||||
desc: "join a room",
|
||||
execute
|
||||
}
|
||||
46
commands/toggle.js
Normal file
46
commands/toggle.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
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.cache.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;
|
||||
}
|
||||
|
||||
if(config[module.name] !== undefined)
|
||||
config[module.name] = !config[module.name];
|
||||
else
|
||||
config[module.name] = false;
|
||||
|
||||
var state = (config[module.name] ? "En" : "Dis") + "abled";
|
||||
|
||||
var reply = state + " " + module.name + "\n";
|
||||
var replyHTML = `<b>${state}</b> <code>${encode(module.name)}</code><br>`;
|
||||
|
||||
client.cache.set(event.sender.roomId, config);
|
||||
client.reply(event, reply, replyHTML);
|
||||
return;
|
||||
}
|
||||
|
||||
var enabled = client.modules.map(m => "[" + (config[m.name] !== false ? "x" : " ") + "] " + m.name);
|
||||
var reply = `enabled modules:\n${enabled.join("\n")}`;
|
||||
var replyHTML = `enabled modules:<br><code>${enabled.join("</code><br><code>")}</code>`;
|
||||
|
||||
client.reply(event, reply, replyHTML);
|
||||
}
|
||||
|
||||
export default {
|
||||
command: "toggle",
|
||||
name: "toggle",
|
||||
admin: true,
|
||||
desc: "toggle a module on or off in current channel",
|
||||
execute
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue