Added broadcast

This commit is contained in:
Essem 2021-07-31 00:04:38 -05:00
parent 5fa457958b
commit 7b07f82285
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
2 changed files with 55 additions and 6 deletions

View file

@ -0,0 +1,27 @@
const Command = require("../../classes/command.js");
class BroadcastCommand extends Command {
// yet another very hacky command
run() {
return new Promise((resolve) => {
if (this.message.author.id !== process.env.OWNER) return "Only the bot owner can broadcast messages!";
if (this.args.length !== 0) {
this.ipc.broadcast("playbroadcast", this.args.join(" "));
this.ipc.register("broadcastSuccess", () => {
this.ipc.unregister("broadcastSuccess");
resolve("Successfully broadcasted message.");
});
} else {
this.ipc.broadcast("broadcastend");
this.ipc.register("broadcastEnd", () => {
this.ipc.unregister("broadcastEnd");
resolve("Successfully ended broadcast.");
});
}
});
}
static description = "Broadcasts a playing message until the command is run again or the bot restarts";
}
module.exports = BroadcastCommand;

View file

@ -19,6 +19,8 @@ const misc = require("./utils/misc.js");
// generate help page
const helpGenerator =
process.env.OUTPUT !== "" ? require("./utils/help.js") : null;
// whether a broadcast is currently in effect
let broadcast = false;
class Shard extends BaseClusterWorker {
constructor(bot) {
@ -78,21 +80,41 @@ class Shard extends BaseClusterWorker {
return this.ipc.broadcast("soundReloadFail");
}
});
this.ipc.register("playbroadcast", async (message) => {
this.bot.editStatus("dnd", {
name: `${message.msg} | @${this.bot.user.username} help`,
});
broadcast = true;
return this.ipc.broadcast("broadcastSuccess");
});
this.ipc.register("broadcastend", async () => {
this.bot.editStatus("dnd", {
name: `${misc.random(messages)} | @${this.bot.user.username} help`,
});
broadcast = false;
return this.ipc.broadcast("broadcastEnd");
});
// connect to lavalink
if (!sound.status && !sound.connected) sound.connect(this.bot);
database.setup();
// set activity (a.k.a. the gamer code)
(async function activityChanger() {
this.activityChanger();
logger.log("info", `Started worker ${this.workerID}.`);
}
// set activity (a.k.a. the gamer code)
activityChanger() {
if (!broadcast) {
this.bot.editStatus("dnd", {
name: `${misc.random(messages)} | @${this.bot.user.username} help`,
});
setTimeout(activityChanger.bind(this), 900000);
}).bind(this)();
logger.log("info", `Started worker ${this.workerID}.`);
}
setTimeout(this.activityChanger, 900000);
}
async* getFiles(dir) {