mrmBot-Matrix/commands/general/broadcast.js

42 lines
1.3 KiB
JavaScript
Raw Normal View History

import Command from "../../classes/command.js";
2021-07-31 05:04:38 +00:00
class BroadcastCommand extends Command {
// yet another very hacky command
run() {
return new Promise((resolve) => {
const owners = process.env.OWNER.split(",");
if (!owners.includes(this.author.id)) {
this.success = false;
resolve("Only the bot owner can broadcast messages!");
return;
}
const message = this.options.message ?? this.args.join(" ");
if (message?.trim()) {
this.ipc.centralStore.set("broadcast", message);
2022-03-31 19:53:22 +00:00
this.ipc.broadcast("playbroadcast", message);
2021-07-31 05:04:38 +00:00
this.ipc.register("broadcastSuccess", () => {
this.ipc.unregister("broadcastSuccess");
resolve("Successfully broadcasted message.");
});
} else {
this.ipc.centralStore.delete("broadcast");
2021-07-31 05:04:38 +00:00
this.ipc.broadcast("broadcastend");
this.ipc.register("broadcastEnd", () => {
this.ipc.unregister("broadcastEnd");
resolve("Successfully ended broadcast.");
});
}
});
}
2022-03-31 19:53:22 +00:00
static flags = [{
name: "message",
type: 3,
description: "The message to broadcast"
}];
2021-07-31 05:04:38 +00:00
static description = "Broadcasts a playing message until the command is run again or the bot restarts";
static adminOnly = true;
2021-07-31 05:04:38 +00:00
}
export default BroadcastCommand;