2021-08-19 14:19:14 +00:00
|
|
|
import Command from "../../classes/command.js";
|
2022-10-25 17:37:55 +00:00
|
|
|
import database from "../../utils/database.js";
|
2022-09-21 05:05:03 +00:00
|
|
|
import { endBroadcast, startBroadcast } from "../../utils/misc.js";
|
2021-07-31 05:04:38 +00:00
|
|
|
|
|
|
|
class BroadcastCommand extends Command {
|
2022-09-21 05:05:03 +00:00
|
|
|
async run() {
|
|
|
|
const owners = process.env.OWNER.split(",");
|
|
|
|
if (!owners.includes(this.author.id)) {
|
|
|
|
this.success = false;
|
|
|
|
return "Only the bot owner can broadcast messages!";
|
|
|
|
}
|
|
|
|
const message = this.options.message ?? this.args.join(" ");
|
|
|
|
if (message?.trim()) {
|
2022-10-25 17:37:55 +00:00
|
|
|
await database.setBroadcast(message);
|
2022-09-21 05:05:03 +00:00
|
|
|
startBroadcast(this.client, message);
|
|
|
|
if (process.env.PM2_USAGE) {
|
|
|
|
process.send({
|
|
|
|
type: "process:msg",
|
|
|
|
data: {
|
|
|
|
type: "broadcastStart",
|
|
|
|
message
|
|
|
|
}
|
2021-07-31 05:04:38 +00:00
|
|
|
});
|
2022-09-21 05:05:03 +00:00
|
|
|
}
|
|
|
|
return "Started broadcast.";
|
|
|
|
} else {
|
2022-10-25 17:37:55 +00:00
|
|
|
await database.setBroadcast(null);
|
2022-09-21 05:05:03 +00:00
|
|
|
endBroadcast(this.client);
|
|
|
|
if (process.env.PM2_USAGE) {
|
|
|
|
process.send({
|
|
|
|
type: "process:msg",
|
|
|
|
data: {
|
|
|
|
type: "broadcastEnd"
|
|
|
|
}
|
2021-07-31 05:04:38 +00:00
|
|
|
});
|
|
|
|
}
|
2022-09-21 05:05:03 +00:00
|
|
|
return "Ended broadcast.";
|
|
|
|
}
|
2021-07-31 05:04:38 +00:00
|
|
|
}
|
|
|
|
|
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";
|
2022-09-01 15:40:55 +00:00
|
|
|
static adminOnly = true;
|
2022-12-12 17:15:10 +00:00
|
|
|
static dbRequired = true;
|
2021-07-31 05:04:38 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 14:19:14 +00:00
|
|
|
export default BroadcastCommand;
|