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
|
||||||
|
}
|
10
index.js
10
index.js
|
@ -56,6 +56,10 @@ for (const file of fs.readdirSync(resolve("commands"))) {
|
||||||
function doModule(client, event) {
|
function doModule(client, event) {
|
||||||
client.modules.forEach(m => {
|
client.modules.forEach(m => {
|
||||||
if(!m) return;
|
if(!m) return;
|
||||||
|
|
||||||
|
var config = client.cache.get(event.sender.roomId) ?? {};
|
||||||
|
if(config[m.name] === false) return;
|
||||||
|
|
||||||
m.hooks?.message(client, event);
|
m.hooks?.message(client, event);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -66,8 +70,9 @@ function doCommand(client, event, cmd, args) {
|
||||||
if(!command)
|
if(!command)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(command.owner && event.sender.userId != process.env.OWNER_ID) {
|
if((command.owner && event.sender.userId != process.env.OWNER_ID) || (command.admin && event.sender.powerLevel != 100 && event.sender.userId != process.env.OWNER_ID)) {
|
||||||
client.reply(event, "nuh uh", '<img src="mxc://possum.city/cu5mPRM1ITiJZQRgAyzJXDz22jN6TBo9" alt="nuh uh" />');
|
var addl = `Are you sure this command is for you?\nYour power level is ${event.sender.powerLevel}`;
|
||||||
|
client.reply(event, "nuh uh" + addl, '<img src="mxc://possum.city/b4Vo1BTcq49B7TbFWCqq76HQWQEdNIqq" alt="nuh uh" /><br>' + addl);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +99,7 @@ client.on(sdk.RoomEvent.Timeline, async function (event, room, toStartOfTimeline
|
||||||
if(event.event.content["m.relates_to"] != null)
|
if(event.event.content["m.relates_to"] != null)
|
||||||
event.event.content.body = event.event.content.body.substring(event.event.content.body.indexOf("\n\n") + 2);
|
event.event.content.body = event.event.content.body.substring(event.event.content.body.indexOf("\n\n") + 2);
|
||||||
|
|
||||||
|
event.sender = client.getRoom(event.sender.roomId).getMember(event.getSender());
|
||||||
var content = event.event.content.body;
|
var content = event.event.content.body;
|
||||||
var isCommand = false;
|
var isCommand = false;
|
||||||
for(const prefix of prefixes) {
|
for(const prefix of prefixes) {
|
||||||
|
|
Loading…
Reference in a new issue