mrmBot-Matrix/commands/general/channel.js

50 lines
2.4 KiB
JavaScript
Raw Normal View History

import db from "../../utils/database.js";
import Command from "../../classes/command.js";
class ChannelCommand extends Command {
async run() {
if (!this.channel.guild) return "This command only works in servers!";
const owners = process.env.OWNER.split(",");
if (!this.member.permissions.has("administrator") && !owners.includes(this.member.id)) return "You need to be an administrator to enable/disable me!";
if (this.args.length === 0) return "You need to provide whether I should be enabled or disabled in this channel!";
if (this.args[0] !== "disable" && this.args[0] !== "enable") return "That's not a valid option!";
const guildDB = await db.getGuild(this.channel.guild.id);
if (this.args[0].toLowerCase() === "disable") {
let channel;
if (this.args[1]?.match(/^<?[@#]?[&!]?\d+>?$/) && this.args[1] >= 21154535154122752n) {
const id = this.args[1].replaceAll("@", "").replaceAll("#", "").replaceAll("!", "").replaceAll("&", "").replaceAll("<", "").replaceAll(">", "");
if (guildDB.disabled.includes(id)) return "I'm already disabled in this channel!";
channel = this.channel.guild.channels.get(id);
} else {
if (guildDB.disabled.includes(this.channel.id)) return "I'm already disabled in this channel!";
channel = this.channel;
}
await db.disableChannel(channel);
return `I have been disabled in this channel. To re-enable me, just run \`${guildDB.prefix}channel enable\`.`;
} else if (this.args[0].toLowerCase() === "enable") {
let channel;
if (this.args[1]?.match(/^<?[@#]?[&!]?\d+>?$/) && this.args[1] >= 21154535154122752n) {
const id = this.args[1].replaceAll("@", "").replaceAll("#", "").replaceAll("!", "").replaceAll("&", "").replaceAll("<", "").replaceAll(">", "");
if (!guildDB.disabled.includes(id)) return "I'm not disabled in that channel!";
channel = this.channel.guild.channels.get(id);
} else {
if (!guildDB.disabled.includes(this.channel.id)) return "I'm not disabled in this channel!";
channel = this.channel;
}
await db.enableChannel(channel);
return "I have been re-enabled in this channel.";
}
}
2022-03-22 20:43:26 +00:00
static description = "Enables/disables me in a channel (does not work with slash commands)";
static arguments = ["[enable/disable]", "{id}"];
2022-03-22 20:43:26 +00:00
static slashAllowed = false;
static directAllowed = false;
}
export default ChannelCommand;