Make bot check channel permissions before sending messages

This commit is contained in:
Ethan Lane 2022-06-04 16:04:05 +01:00
parent aa070bb7a7
commit db2ded40b7
28 changed files with 146 additions and 142 deletions

View file

@ -7,7 +7,7 @@
# any secret values. # any secret values.
BOT_TOKEN= BOT_TOKEN=
BOT_VER=3.0.2 BOT_VER=3.0.3
BOT_AUTHOR=Vylpes BOT_AUTHOR=Vylpes
BOT_DATE=16 May 2022 BOT_DATE=04 Jun 2022
BOT_OWNERID=147392775707426816 BOT_OWNERID=147392775707426816

View file

@ -1,24 +0,0 @@
{
"type": "mysql",
"host": "localhost",
"port": 3306,
"username": "dev",
"password": "dev",
"database": "vylbot",
"synchronize": true,
"logging": false,
"entities": [
"dist/entity/**/*.js"
],
"migrations": [
"dist/migration/**/*.js"
],
"subscribers": [
"dist/subscriber/**/*.js"
],
"cli": {
"entitiesDir": "dist/entity",
"migrationsDir": "dist/migration",
"subscribersDir": "dist/subscriber"
}
}

View file

@ -1,6 +1,6 @@
{ {
"name": "vylbot-app", "name": "vylbot-app",
"version": "3.0.1", "version": "3.0.3",
"description": "A discord bot made for Vylpes' Den", "description": "A discord bot made for Vylpes' Den",
"main": "./dist/vylbot", "main": "./dist/vylbot",
"typings": "./dist", "typings": "./dist",

View file

@ -20,6 +20,6 @@ export default class Entry extends Command {
const embedInfo = new PublicEmbed(context, "", `Welcome to the server! Please make sure to read the rules in the <#${rulesChannelId}> channel and type the code found there in here to proceed to the main part of the server.`); const embedInfo = new PublicEmbed(context, "", `Welcome to the server! Please make sure to read the rules in the <#${rulesChannelId}> channel and type the code found there in here to proceed to the main part of the server.`);
embedInfo.SendToCurrentChannel(); await embedInfo.SendToCurrentChannel();
} }
} }

View file

@ -80,7 +80,7 @@ export default class Lobby extends Command {
if (!context.message.member?.roles.cache.find(x => x.name == moderatorRole)) { if (!context.message.member?.roles.cache.find(x => x.name == moderatorRole)) {
const errorEmbed = new ErrorEmbed(context, "Sorry, you must be a moderator to be able to configure this command"); const errorEmbed = new ErrorEmbed(context, "Sorry, you must be a moderator to be able to configure this command");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return; return;
} }
@ -94,15 +94,15 @@ export default class Lobby extends Command {
break; break;
case "help": case "help":
default: default:
this.SendConfigHelp(context); await this.SendConfigHelp(context);
} }
} }
private SendConfigHelp(context: ICommandContext) { private async SendConfigHelp(context: ICommandContext) {
const helpText = readFileSync(`${process.cwd()}/data/usage/lobby.txt`).toString(); const helpText = readFileSync(`${process.cwd()}/data/usage/lobby.txt`).toString();
const embed = new PublicEmbed(context, "Configure Lobby Command", helpText); const embed = new PublicEmbed(context, "Configure Lobby Command", helpText);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
private async AddLobbyConfig(context: ICommandContext) { private async AddLobbyConfig(context: ICommandContext) {
@ -138,7 +138,7 @@ export default class Lobby extends Command {
await entity.Save(eLobby, entity); await entity.Save(eLobby, entity);
const embed = new PublicEmbed(context, "", `Added \`${channel.name}\` as a new lobby channel with a cooldown of \`${cooldown} minutes\` and will ping \`${role.name}\` on use`); const embed = new PublicEmbed(context, "", `Added \`${channel.name}\` as a new lobby channel with a cooldown of \`${cooldown} minutes\` and will ping \`${role.name}\` on use`);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
private async RemoveLobbyConfig(context: ICommandContext) { private async RemoveLobbyConfig(context: ICommandContext) {
@ -146,7 +146,7 @@ export default class Lobby extends Command {
if (!entity) { if (!entity) {
const errorEmbed = new ErrorEmbed(context, "The channel id you provided has not been setup as a lobby, unable to remove."); const errorEmbed = new ErrorEmbed(context, "The channel id you provided has not been setup as a lobby, unable to remove.");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return; return;
} }
@ -154,6 +154,6 @@ export default class Lobby extends Command {
await BaseEntity.Remove<eLobby>(eLobby, entity); await BaseEntity.Remove<eLobby>(eLobby, entity);
const embed = new PublicEmbed(context, "", `Removed <#${context.args[2]}> from the list of lobby channels`); const embed = new PublicEmbed(context, "", `Removed <#${context.args[2]}> from the list of lobby channels`);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
} }

View file

@ -1,5 +1,4 @@
import { ICommandContext } from "../contracts/ICommandContext"; import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import PublicEmbed from "../helpers/embeds/PublicEmbed"; import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command"; import { Command } from "../type/command";
@ -9,17 +8,12 @@ export default class About extends Command {
super.Category = "General"; super.Category = "General";
} }
public override execute(context: ICommandContext): ICommandReturnContext { public override async execute(context: ICommandContext) {
const embed = new PublicEmbed(context, "About", "") const embed = new PublicEmbed(context, "About", "")
.addField("Version", process.env.BOT_VER!) .addField("Version", process.env.BOT_VER!)
.addField("Author", process.env.BOT_AUTHOR!) .addField("Author", process.env.BOT_AUTHOR!)
.addField("Date", process.env.BOT_DATE!); .addField("Date", process.env.BOT_DATE!);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
} }
} }

View file

@ -21,7 +21,8 @@ export default class Ban extends Command {
if (!targetUser) { if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist"); const embed = new ErrorEmbed(context, "User does not exist");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
embeds: [embed], embeds: [embed],
@ -32,7 +33,8 @@ export default class Ban extends Command {
if (!targetMember) { if (!targetMember) {
const embed = new ErrorEmbed(context, "User is not in this server"); const embed = new ErrorEmbed(context, "User is not in this server");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
embeds: [embed], embeds: [embed],
@ -53,7 +55,8 @@ export default class Ban extends Command {
if (!targetMember.bannable) { if (!targetMember.bannable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions); const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
embeds: [embed], embeds: [embed],
@ -70,7 +73,7 @@ export default class Ban extends Command {
await targetMember.ban({ reason: `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}` }); await targetMember.ban({ reason: `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}` });
await logEmbed.SendToModLogsChannel(); await logEmbed.SendToModLogsChannel();
publicEmbed.SendToCurrentChannel(); await publicEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,

View file

@ -20,10 +20,10 @@ export default class Bunny extends Command {
.setURL(`https://reddit.com${result.Result!.Permalink}`) .setURL(`https://reddit.com${result.Result!.Permalink}`)
.setFooter({ text: `r/Rabbits · ${result.Result!.Ups} upvotes` }); .setFooter({ text: `r/Rabbits · ${result.Result!.Ups} upvotes` });
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} else { } else {
const errorEmbed = new ErrorEmbed(context, "There was an error using this command."); const errorEmbed = new ErrorEmbed(context, "There was an error using this command.");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
} }
} }
} }

View file

@ -18,7 +18,7 @@ export default class Clear extends Command {
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> { public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
if (context.args.length == 0) { if (context.args.length == 0) {
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100"); const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -30,7 +30,7 @@ export default class Clear extends Command {
if (!totalToClear || totalToClear <= 0 || totalToClear > 100) { if (!totalToClear || totalToClear <= 0 || totalToClear > 100) {
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100"); const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
embeds: [errorEmbed] embeds: [errorEmbed]
@ -40,7 +40,7 @@ export default class Clear extends Command {
await (context.message.channel as TextChannel).bulkDelete(totalToClear); await (context.message.channel as TextChannel).bulkDelete(totalToClear);
const embed = new PublicEmbed(context, "", `${totalToClear} message(s) were removed`); const embed = new PublicEmbed(context, "", `${totalToClear} message(s) were removed`);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,

View file

@ -58,7 +58,7 @@ export default class Code extends Command {
].join("\n"); ].join("\n");
const embed = new PublicEmbed(context, "", description); const embed = new PublicEmbed(context, "", description);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
private async Randomise(context: ICommandContext) { private async Randomise(context: ICommandContext) {
@ -71,7 +71,7 @@ export default class Code extends Command {
await SettingsHelper.SetSetting("verification.code", context.message.guild.id, randomCode); await SettingsHelper.SetSetting("verification.code", context.message.guild.id, randomCode);
const embed = new PublicEmbed(context, "Code", `Entry code has been set to \`${randomCode}\``); const embed = new PublicEmbed(context, "Code", `Entry code has been set to \`${randomCode}\``);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
private async SendEmbed(context: ICommandContext) { private async SendEmbed(context: ICommandContext) {
@ -89,6 +89,6 @@ export default class Code extends Command {
} }
const embed = new PublicEmbed(context, "Entry Code", code!); const embed = new PublicEmbed(context, "Entry Code", code!);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
} }

View file

@ -1,9 +1,7 @@
import { Guild } from "discord.js";
import { readFileSync } from "fs"; import { readFileSync } from "fs";
import { CommandResponse } from "../constants/CommandResponse"; import { CommandResponse } from "../constants/CommandResponse";
import DefaultValues from "../constants/DefaultValues"; import DefaultValues from "../constants/DefaultValues";
import { ICommandContext } from "../contracts/ICommandContext"; import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import Server from "../entity/Server"; import Server from "../entity/Server";
import Setting from "../entity/Setting"; import Setting from "../entity/Setting";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed"; import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
@ -83,7 +81,7 @@ export default class Config extends Command {
const embed = new PublicEmbed(context, "Config", description); const embed = new PublicEmbed(context, "Config", description);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
private async GetValue(context: ICommandContext, server: Server, key: string) { private async GetValue(context: ICommandContext, server: Server, key: string) {
@ -91,10 +89,10 @@ export default class Config extends Command {
if (setting) { if (setting) {
const embed = new PublicEmbed(context, "", `${key}: ${setting.Value}`); const embed = new PublicEmbed(context, "", `${key}: ${setting.Value}`);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} else { } else {
const embed = new PublicEmbed(context, "", `${key}: ${DefaultValues.GetValue(key)} <DEFAULT>`); const embed = new PublicEmbed(context, "", `${key}: ${DefaultValues.GetValue(key)} <DEFAULT>`);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
} }
@ -103,14 +101,15 @@ export default class Config extends Command {
if (!setting) { if (!setting) {
const embed = new PublicEmbed(context, "", "Setting has been reset"); const embed = new PublicEmbed(context, "", "Setting has been reset");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return; return;
} }
await Setting.Remove(Setting, setting); await Setting.Remove(Setting, setting);
const embed = new PublicEmbed(context, "", "Setting has been reset"); const embed = new PublicEmbed(context, "", "Setting has been reset");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
private async SetValue(context: ICommandContext, server: Server, key: string, value: string) { private async SetValue(context: ICommandContext, server: Server, key: string, value: string) {
@ -131,6 +130,6 @@ export default class Config extends Command {
} }
const embed = new PublicEmbed(context, "", "Setting has been set"); const embed = new PublicEmbed(context, "", "Setting has been set");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
} }

View file

@ -38,7 +38,7 @@ export default class Disable extends Command {
].join("\n"); ].join("\n");
const embed = new PublicEmbed(context, "", description); const embed = new PublicEmbed(context, "", description);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
private async Add(context: ICommandContext) { private async Add(context: ICommandContext) {
@ -61,7 +61,7 @@ export default class Disable extends Command {
await SettingsHelper.SetSetting("commands.disabled", context.message.guild.id, disabledCommands!.join(",")); await SettingsHelper.SetSetting("commands.disabled", context.message.guild.id, disabledCommands!.join(","));
const embed = new PublicEmbed(context, "", `Disabled command: ${commandName}`); const embed = new PublicEmbed(context, "", `Disabled command: ${commandName}`);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
private async Remove(context: ICommandContext) { private async Remove(context: ICommandContext) {
@ -88,6 +88,6 @@ export default class Disable extends Command {
await SettingsHelper.SetSetting("commands.disabled", context.message.guild.id, disabledCommands!.join(",")); await SettingsHelper.SetSetting("commands.disabled", context.message.guild.id, disabledCommands!.join(","));
const embed = new PublicEmbed(context, "", `Enabled command: ${commandName}`); const embed = new PublicEmbed(context, "", `Enabled command: ${commandName}`);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
} }

View file

@ -20,15 +20,15 @@ export default class Help extends Command {
super.Category = "General"; super.Category = "General";
} }
public override execute(context: ICommandContext) { public override async execute(context: ICommandContext) {
if (context.args.length == 0) { if (context.args.length == 0) {
this.SendAll(context); await this.SendAll(context);
} else { } else {
this.SendSingle(context); await this.SendSingle(context);
} }
} }
public SendAll(context: ICommandContext) { public async SendAll(context: ICommandContext) {
const allCommands = CoreClient.commandItems const allCommands = CoreClient.commandItems
.filter(x => !x.ServerId || x.ServerId == context.message.guild?.id); .filter(x => !x.ServerId || x.ServerId == context.message.guild?.id);
const cateogries = [...new Set(allCommands.map(x => x.Command.Category))]; const cateogries = [...new Set(allCommands.map(x => x.Command.Category))];
@ -41,10 +41,10 @@ export default class Help extends Command {
embed.addField(StringTools.Capitalise(category || "Uncategorised"), StringTools.CapitaliseArray(filtered.flatMap(x => x.Name)).join(", ")); embed.addField(StringTools.Capitalise(category || "Uncategorised"), StringTools.CapitaliseArray(filtered.flatMap(x => x.Name)).join(", "));
}); });
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
public SendSingle(context: ICommandContext) { public async SendSingle(context: ICommandContext) {
const command = CoreClient.commandItems.find(x => x.Name == context.args[0] && !x.ServerId); const command = CoreClient.commandItems.find(x => x.Name == context.args[0] && !x.ServerId);
const exclusiveCommand = CoreClient.commandItems.find(x => x.Name == context.args[0] && x.ServerId == context.message.guild?.id); const exclusiveCommand = CoreClient.commandItems.find(x => x.Name == context.args[0] && x.ServerId == context.message.guild?.id);
@ -53,18 +53,16 @@ export default class Help extends Command {
embed.addField("Category", StringTools.Capitalise(exclusiveCommand.Command.Category || "Uncategorised")); embed.addField("Category", StringTools.Capitalise(exclusiveCommand.Command.Category || "Uncategorised"));
embed.addField("Required Roles", StringTools.Capitalise(exclusiveCommand.Command.Roles.join(", ")) || "Everyone"); embed.addField("Required Roles", StringTools.Capitalise(exclusiveCommand.Command.Roles.join(", ")) || "Everyone");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} else if (command) { } else if (command) {
const embed = new PublicEmbed(context, StringTools.Capitalise(command.Name), ""); const embed = new PublicEmbed(context, StringTools.Capitalise(command.Name), "");
embed.addField("Category", StringTools.Capitalise(command.Command.Category || "Uncategorised")); embed.addField("Category", StringTools.Capitalise(command.Command.Category || "Uncategorised"));
embed.addField("Required Roles", StringTools.Capitalise(command.Command.Roles.join(", ")) || "Everyone"); embed.addField("Required Roles", StringTools.Capitalise(command.Command.Roles.join(", ")) || "Everyone");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} else { } else {
const errorEmbed = new ErrorEmbed(context, "Command does not exist"); const errorEmbed = new ErrorEmbed(context, "Command does not exist");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return;
} }
} }
} }

View file

@ -21,7 +21,7 @@ export default class Kick extends Command {
if (!targetUser) { if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist"); const embed = new ErrorEmbed(context, "User does not exist");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -33,7 +33,7 @@ export default class Kick extends Command {
if (!targetMember) { if (!targetMember) {
const embed = new ErrorEmbed(context, "User is not in this server"); const embed = new ErrorEmbed(context, "User is not in this server");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -55,7 +55,7 @@ export default class Kick extends Command {
if (!targetMember.kickable) { if (!targetMember.kickable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions); const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -73,7 +73,7 @@ export default class Kick extends Command {
await targetMember.kick(`Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`); await targetMember.kick(`Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
await logEmbed.SendToModLogsChannel(); await logEmbed.SendToModLogsChannel();
publicEmbed.SendToCurrentChannel(); await publicEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,

View file

@ -21,7 +21,7 @@ export default class Mute extends Command {
if (!targetUser) { if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist"); const embed = new ErrorEmbed(context, "User does not exist");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -33,7 +33,7 @@ export default class Mute extends Command {
if (!targetMember) { if (!targetMember) {
const embed = new ErrorEmbed(context, "User is not in this server"); const embed = new ErrorEmbed(context, "User is not in this server");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -55,7 +55,7 @@ export default class Mute extends Command {
if (!targetMember.manageable) { if (!targetMember.manageable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions); const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -75,7 +75,7 @@ export default class Mute extends Command {
if (!mutedRole) { if (!mutedRole) {
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound); const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -86,7 +86,7 @@ export default class Mute extends Command {
await targetMember.roles.add(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`); await targetMember.roles.add(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
await logEmbed.SendToModLogsChannel(); await logEmbed.SendToModLogsChannel();
publicEmbed.SendToCurrentChannel(); await publicEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,

View file

@ -17,7 +17,7 @@ export default class Poll extends Command {
if (argsSplit.length < 3 || argsSplit.length > 10) { if (argsSplit.length < 3 || argsSplit.length > 10) {
const errorEmbed = new ErrorEmbed(context, "Usage: <title>;<option 1>;<option 2>... (separate options with semicolons), maximum of 9 options"); const errorEmbed = new ErrorEmbed(context, "Usage: <title>;<option 1>;<option 2>... (separate options with semicolons), maximum of 9 options");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,

View file

@ -63,7 +63,7 @@ export default class Role extends Command {
const description = roles.length == 0 ? "*no roles*" : `Do ${botPrefix}role <role> to get the role!\n\n${roles.join('\n')}`; const description = roles.length == 0 ? "*no roles*" : `Do ${botPrefix}role <role> to get the role!\n\n${roles.join('\n')}`;
const embed = new PublicEmbed(context, "Roles", description); const embed = new PublicEmbed(context, "Roles", description);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -77,7 +77,7 @@ export default class Role extends Command {
if (!roles.includes(requestedRole)) { if (!roles.includes(requestedRole)) {
const errorEmbed = new ErrorEmbed(context, "This role isn't marked as assignable, to see a list of assignable roles, run this command without any parameters"); const errorEmbed = new ErrorEmbed(context, "This role isn't marked as assignable, to see a list of assignable roles, run this command without any parameters");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -89,7 +89,7 @@ export default class Role extends Command {
if (!assignRole) { if (!assignRole) {
const errorEmbed = new ErrorEmbed(context, "The current server doesn't have this role. Please contact the server's moderators"); const errorEmbed = new ErrorEmbed(context, "The current server doesn't have this role. Please contact the server's moderators");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -115,7 +115,7 @@ export default class Role extends Command {
await context.message.member?.roles.add(role, "Toggled with role command"); await context.message.member?.roles.add(role, "Toggled with role command");
const embed = new PublicEmbed(context, "", `Gave role: \`${role.name}\``); const embed = new PublicEmbed(context, "", `Gave role: \`${role.name}\``);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -127,7 +127,7 @@ export default class Role extends Command {
await context.message.member?.roles.remove(role, "Toggled with role command"); await context.message.member?.roles.remove(role, "Toggled with role command");
const embed = new PublicEmbed(context, "", `Removed role: \`${role.name}\``); const embed = new PublicEmbed(context, "", `Removed role: \`${role.name}\``);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -144,7 +144,7 @@ export default class Role extends Command {
if (!context.message.member?.roles.cache.find(x => x.name == moderatorRole)) { if (!context.message.member?.roles.cache.find(x => x.name == moderatorRole)) {
const errorEmbed = new ErrorEmbed(context, "Sorry, you must be a moderator to be able to configure this command"); const errorEmbed = new ErrorEmbed(context, "Sorry, you must be a moderator to be able to configure this command");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return; return;
} }
@ -157,15 +157,15 @@ export default class Role extends Command {
await this.RemoveRoleConfig(context); await this.RemoveRoleConfig(context);
break; break;
default: default:
this.SendConfigHelp(context); await this.SendConfigHelp(context);
} }
} }
private SendConfigHelp(context: ICommandContext) { private async SendConfigHelp(context: ICommandContext) {
const helpText = readFileSync(`${process.cwd()}/data/usage/role.txt`).toString(); const helpText = readFileSync(`${process.cwd()}/data/usage/role.txt`).toString();
const embed = new PublicEmbed(context, "Configure Role Command", helpText); const embed = new PublicEmbed(context, "Configure Role Command", helpText);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
private async AddRoleConfig(context: ICommandContext) { private async AddRoleConfig(context: ICommandContext) {
@ -180,7 +180,7 @@ export default class Role extends Command {
if (existingRole) { if (existingRole) {
const errorEmbed = new ErrorEmbed(context, "This role has already been setup"); const errorEmbed = new ErrorEmbed(context, "This role has already been setup");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return; return;
} }
@ -191,7 +191,7 @@ export default class Role extends Command {
if (!server) { if (!server) {
const errorEmbed = new ErrorEmbed(context, "Server not setup, please request the server owner runs the setup command."); const errorEmbed = new ErrorEmbed(context, "Server not setup, please request the server owner runs the setup command.");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return; return;
} }
@ -204,7 +204,7 @@ export default class Role extends Command {
await server.Save(Server, server); await server.Save(Server, server);
const embed = new PublicEmbed(context, "", `Added \`${role.name}\` as a new assignable role`); const embed = new PublicEmbed(context, "", `Added \`${role.name}\` as a new assignable role`);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
private async RemoveRoleConfig(context: ICommandContext) { private async RemoveRoleConfig(context: ICommandContext) {
@ -227,6 +227,6 @@ export default class Role extends Command {
await eRole.Remove(eRole, existingRole); await eRole.Remove(eRole, existingRole);
const embed = new PublicEmbed(context, "", `Removed \`${role.name}\` from the list of assignable roles`); const embed = new PublicEmbed(context, "", `Removed \`${role.name}\` from the list of assignable roles`);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
} }

View file

@ -1,6 +1,5 @@
import { existsSync, readFileSync } from "fs"; import { existsSync, readFileSync } from "fs";
import { ICommandContext } from "../contracts/ICommandContext"; import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed"; import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed"; import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command"; import { Command } from "../type/command";
@ -22,15 +21,12 @@ export default class Rules extends Command {
]; ];
} }
public override execute(context: ICommandContext): ICommandReturnContext { public override async execute(context: ICommandContext) {
if (!existsSync(`${process.cwd()}/data/rules/${context.message.guild?.id}.json`)) { if (!existsSync(`${process.cwd()}/data/rules/${context.message.guild?.id}.json`)) {
const errorEmbed = new ErrorEmbed(context, "Rules file doesn't exist"); const errorEmbed = new ErrorEmbed(context, "Rules file doesn't exist");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return { return;
commandContext: context,
embeds: [errorEmbed]
};
} }
const rulesFile = readFileSync(`${process.cwd()}/data/rules/${context.message.guild?.id}.json`).toString(); const rulesFile = readFileSync(`${process.cwd()}/data/rules/${context.message.guild?.id}.json`).toString();
@ -42,16 +38,15 @@ export default class Rules extends Command {
const embed = new PublicEmbed(context, rule.title || "", rule.description?.join("\n") || ""); const embed = new PublicEmbed(context, rule.title || "", rule.description?.join("\n") || "");
embed.setImage(rule.image || ""); embed.setImage(rule.image || "");
embed.setFooter(rule.footer || ""); embed.setFooter({ text: rule.footer || "" });
embeds.push(embed); embeds.push(embed);
}); });
embeds.forEach(x => x.SendToCurrentChannel()); for (let i = 0; i < embeds.length; i++) {
const embed = embeds[i];
return { await embed.SendToCurrentChannel();
commandContext: context, }
embeds: embeds
};
} }
} }

View file

@ -22,7 +22,8 @@ export default class Setup extends Command {
if (server) { if (server) {
const embed = new ErrorEmbed(context, "This server has already been setup, please configure using the config command"); const embed = new ErrorEmbed(context, "This server has already been setup, please configure using the config command");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return; return;
} }
@ -31,6 +32,6 @@ export default class Setup extends Command {
await newServer.Save(Server, newServer); await newServer.Save(Server, newServer);
const embed = new PublicEmbed(context, "Success", "Please configure using the config command"); const embed = new PublicEmbed(context, "Success", "Please configure using the config command");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
} }
} }

View file

@ -21,7 +21,7 @@ export default class Unmute extends Command {
if (!targetUser) { if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist"); const embed = new ErrorEmbed(context, "User does not exist");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -33,7 +33,7 @@ export default class Unmute extends Command {
if (!targetMember) { if (!targetMember) {
const embed = new ErrorEmbed(context, "User is not in this server"); const embed = new ErrorEmbed(context, "User is not in this server");
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -55,7 +55,7 @@ export default class Unmute extends Command {
if (!targetMember.manageable) { if (!targetMember.manageable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions); const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -75,7 +75,7 @@ export default class Unmute extends Command {
if (!mutedRole) { if (!mutedRole) {
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound); const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
embed.SendToCurrentChannel(); await embed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -86,7 +86,7 @@ export default class Unmute extends Command {
await targetMember.roles.remove(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`); await targetMember.roles.remove(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
await logEmbed.SendToModLogsChannel(); await logEmbed.SendToModLogsChannel();
publicEmbed.SendToCurrentChannel(); await publicEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,

View file

@ -20,7 +20,7 @@ export default class Warn extends Command {
if (!user) { if (!user) {
const errorEmbed = new ErrorEmbed(context, "User does not exist"); const errorEmbed = new ErrorEmbed(context, "User does not exist");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -32,7 +32,7 @@ export default class Warn extends Command {
if (!member) { if (!member) {
const errorEmbed = new ErrorEmbed(context, "User is not in this server"); const errorEmbed = new ErrorEmbed(context, "User is not in this server");
errorEmbed.SendToCurrentChannel(); await errorEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,
@ -61,7 +61,7 @@ export default class Warn extends Command {
publicEmbed.AddReason(reason); publicEmbed.AddReason(reason);
await logEmbed.SendToModLogsChannel(); await logEmbed.SendToModLogsChannel();
publicEmbed.SendToCurrentChannel(); await publicEmbed.SendToCurrentChannel();
return { return {
commandContext: context, commandContext: context,

View file

@ -15,7 +15,7 @@ export default class MemberEvents extends Event {
const enabled = await SettingsHelper.GetSetting("event.member.add.enabled", member.guild.id); const enabled = await SettingsHelper.GetSetting("event.member.add.enabled", member.guild.id);
if (!enabled || enabled.toLowerCase() != "true") return; if (!enabled || enabled.toLowerCase() != "true") return;
const embed = new EventEmbed(member.guild, "Member Joined"); const embed = new EventEmbed(member.client, member.guild, "Member Joined");
embed.AddUser("User", member.user, true); embed.AddUser("User", member.user, true);
embed.addField("Created", member.user.createdAt.toISOString()); embed.addField("Created", member.user.createdAt.toISOString());
embed.setFooter({ text: `Id: ${member.user.id}` }); embed.setFooter({ text: `Id: ${member.user.id}` });
@ -23,7 +23,7 @@ export default class MemberEvents extends Event {
const channel = await SettingsHelper.GetSetting("event.member.add.channel", member.guild.id); const channel = await SettingsHelper.GetSetting("event.member.add.channel", member.guild.id);
if (!channel || !member.guild.channels.cache.find(x => x.name == channel)) return; if (!channel || !member.guild.channels.cache.find(x => x.name == channel)) return;
embed.SendToChannel(channel); await embed.SendToChannel(channel);
} }
public override async guildMemberRemove(member: GuildMember) { public override async guildMemberRemove(member: GuildMember) {
@ -32,7 +32,7 @@ export default class MemberEvents extends Event {
const enabled = await SettingsHelper.GetSetting("event.member.remove.enabled", member.guild.id); const enabled = await SettingsHelper.GetSetting("event.member.remove.enabled", member.guild.id);
if (!enabled || enabled.toLowerCase() != "true") return; if (!enabled || enabled.toLowerCase() != "true") return;
const embed = new EventEmbed(member.guild, "Member Left"); const embed = new EventEmbed(member.client, member.guild, "Member Left");
embed.AddUser("User", member.user, true); embed.AddUser("User", member.user, true);
embed.addField("Joined", member.joinedAt?.toISOString() || "n/a"); embed.addField("Joined", member.joinedAt?.toISOString() || "n/a");
embed.setFooter({ text: `Id: ${member.user.id}` }); embed.setFooter({ text: `Id: ${member.user.id}` });
@ -40,7 +40,7 @@ export default class MemberEvents extends Event {
const channel = await SettingsHelper.GetSetting("event.member.remove.channel", member.guild.id); const channel = await SettingsHelper.GetSetting("event.member.remove.channel", member.guild.id);
if (!channel || !member.guild.channels.cache.find(x => x.name == channel)) return; if (!channel || !member.guild.channels.cache.find(x => x.name == channel)) return;
embed.SendToChannel(channel); await embed.SendToChannel(channel);
} }
public override async guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) { public override async guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {

View file

@ -18,7 +18,7 @@ export default class GuildMemberUpdate {
const oldNickname = this.oldMember.nickname || "*none*"; const oldNickname = this.oldMember.nickname || "*none*";
const newNickname = this.newMember.nickname || "*none*"; const newNickname = this.newMember.nickname || "*none*";
const embed = new EventEmbed(this.newMember.guild, "Nickname Changed"); const embed = new EventEmbed(this.oldMember.client, this.newMember.guild, "Nickname Changed");
embed.AddUser("User", this.newMember.user, true); embed.AddUser("User", this.newMember.user, true);
embed.addField("Before", oldNickname, true); embed.addField("Before", oldNickname, true);
embed.addField("After", newNickname, true); embed.addField("After", newNickname, true);
@ -27,6 +27,6 @@ export default class GuildMemberUpdate {
const channel = await SettingsHelper.GetSetting("event.member.update.channel", this.newMember.guild.id); const channel = await SettingsHelper.GetSetting("event.member.update.channel", this.newMember.guild.id);
if (!channel || channel.toLowerCase() != "true") return; if (!channel || channel.toLowerCase() != "true") return;
embed.SendToChannel(channel); await embed.SendToChannel(channel);
} }
} }

View file

@ -16,7 +16,7 @@ export default class MessageEvents extends Event {
const enabled = await SettingsHelper.GetSetting("event.message.delete.enabled", message.guild.id); const enabled = await SettingsHelper.GetSetting("event.message.delete.enabled", message.guild.id);
if (!enabled || enabled.toLowerCase() != "true") return; if (!enabled || enabled.toLowerCase() != "true") return;
const embed = new EventEmbed(message.guild, "Message Deleted"); const embed = new EventEmbed(message.client, message.guild, "Message Deleted");
embed.AddUser("User", message.author, true); embed.AddUser("User", message.author, true);
embed.addField("Channel", message.channel.toString(), true); embed.addField("Channel", message.channel.toString(), true);
embed.addField("Content", `\`\`\`${message.content || "*none*"}\`\`\``); embed.addField("Content", `\`\`\`${message.content || "*none*"}\`\`\``);
@ -28,7 +28,7 @@ export default class MessageEvents extends Event {
const channel = await SettingsHelper.GetSetting("event.message.delete.channel", message.guild.id); const channel = await SettingsHelper.GetSetting("event.message.delete.channel", message.guild.id);
if (!channel || !message.guild.channels.cache.find(x => x.name == channel)) return; if (!channel || !message.guild.channels.cache.find(x => x.name == channel)) return;
embed.SendToChannel(channel); await embed.SendToChannel(channel);
} }
public override async messageUpdate(oldMessage: Message, newMessage: Message) { public override async messageUpdate(oldMessage: Message, newMessage: Message) {
@ -39,7 +39,7 @@ export default class MessageEvents extends Event {
const enabled = await SettingsHelper.GetSetting("event.message.update.enabled", newMessage.guild.id); const enabled = await SettingsHelper.GetSetting("event.message.update.enabled", newMessage.guild.id);
if (!enabled || enabled.toLowerCase() != "true") return; if (!enabled || enabled.toLowerCase() != "true") return;
const embed = new EventEmbed(newMessage.guild, "Message Edited"); const embed = new EventEmbed(newMessage.client, newMessage.guild, "Message Edited");
embed.AddUser("User", newMessage.author, true); embed.AddUser("User", newMessage.author, true);
embed.addField("Channel", newMessage.channel.toString(), true); embed.addField("Channel", newMessage.channel.toString(), true);
embed.addField("Before", `\`\`\`${oldMessage.content || "*none*"}\`\`\``); embed.addField("Before", `\`\`\`${oldMessage.content || "*none*"}\`\`\``);
@ -48,7 +48,7 @@ export default class MessageEvents extends Event {
const channel = await SettingsHelper.GetSetting("event.message.update.channel", newMessage.guild.id); const channel = await SettingsHelper.GetSetting("event.message.update.channel", newMessage.guild.id);
if (!channel || !newMessage.guild.channels.cache.find(x => x.name == channel)) return; if (!channel || !newMessage.guild.channels.cache.find(x => x.name == channel)) return;
embed.SendToChannel(channel); await embed.SendToChannel(channel);
} }
public override async messageCreate(message: Message) { public override async messageCreate(message: Message) {

View file

@ -1,4 +1,4 @@
import { MessageEmbed } from "discord.js"; import { MessageEmbed, Permissions, TextChannel } from "discord.js";
import { ICommandContext } from "../../contracts/ICommandContext"; import { ICommandContext } from "../../contracts/ICommandContext";
export default class ErrorEmbed extends MessageEmbed { export default class ErrorEmbed extends MessageEmbed {
@ -13,7 +13,16 @@ export default class ErrorEmbed extends MessageEmbed {
this.context = context; this.context = context;
} }
public SendToCurrentChannel() { public async SendToCurrentChannel() {
const channel = this.context.message.channel as TextChannel;
const botMember = await this.context.message.guild?.members.fetch({ user: this.context.message.client.user! });
if (!botMember) return;
const permissions = channel.permissionsFor(botMember);
if (!permissions.has(Permissions.FLAGS.SEND_MESSAGES)) return;
this.context.message.channel.send({ embeds: [ this ]}); this.context.message.channel.send({ embeds: [ this ]});
} }
} }

View file

@ -1,17 +1,20 @@
import { MessageEmbed, TextChannel, User, Guild } from "discord.js"; import { MessageEmbed, TextChannel, User, Guild, Client, Permissions } from "discord.js";
import { ICommandContext } from "../../contracts/ICommandContext"; import { ICommandContext } from "../../contracts/ICommandContext";
import SettingsHelper from "../SettingsHelper"; import SettingsHelper from "../SettingsHelper";
export default class EventEmbed extends MessageEmbed { export default class EventEmbed extends MessageEmbed {
public guild: Guild; public guild: Guild;
constructor(guild: Guild, title: string) { private client: Client;
constructor(client: Client, guild: Guild, title: string) {
super(); super();
super.setColor(0x3050ba); super.setColor(0x3050ba);
super.setTitle(title); super.setTitle(title);
this.guild = guild; this.guild = guild;
this.client = client;
} }
// Detail methods // Detail methods
@ -28,7 +31,7 @@ export default class EventEmbed extends MessageEmbed {
} }
// Send methods // Send methods
public SendToChannel(name: string) { public async SendToChannel(name: string) {
const channel = this.guild.channels.cache const channel = this.guild.channels.cache
.find(channel => channel.name == name) as TextChannel; .find(channel => channel.name == name) as TextChannel;
@ -37,6 +40,14 @@ export default class EventEmbed extends MessageEmbed {
return; return;
} }
const botMember = await this.guild.members.fetch({ user: this.client.user! });
if (!botMember) return;
const permissions = channel.permissionsFor(botMember);
if (!permissions.has(Permissions.FLAGS.SEND_MESSAGES)) return;
channel.send({embeds: [ this ]}); channel.send({embeds: [ this ]});
} }

View file

@ -1,4 +1,4 @@
import { MessageEmbed, TextChannel, User } from "discord.js"; import { MessageEmbed, Permissions, TextChannel, User } from "discord.js";
import ErrorMessages from "../../constants/ErrorMessages"; import ErrorMessages from "../../constants/ErrorMessages";
import { ICommandContext } from "../../contracts/ICommandContext"; import { ICommandContext } from "../../contracts/ICommandContext";
import SettingsHelper from "../SettingsHelper"; import SettingsHelper from "../SettingsHelper";
@ -30,7 +30,16 @@ export default class LogEmbed extends MessageEmbed {
} }
// Send methods // Send methods
public SendToCurrentChannel() { public async SendToCurrentChannel() {
const channel = this.context.message.channel as TextChannel;
const botMember = await this.context.message.guild?.members.fetch({ user: this.context.message.client.user! });
if (!botMember) return;
const permissions = channel.permissionsFor(botMember);
if (!permissions.has(Permissions.FLAGS.SEND_MESSAGES)) return;
this.context.message.channel.send({ embeds: [ this ]}); this.context.message.channel.send({ embeds: [ this ]});
} }

View file

@ -1,4 +1,4 @@
import { MessageEmbed } from "discord.js"; import { MessageEmbed, Permissions, TextChannel } from "discord.js";
import { ICommandContext } from "../../contracts/ICommandContext"; import { ICommandContext } from "../../contracts/ICommandContext";
export default class PublicEmbed extends MessageEmbed { export default class PublicEmbed extends MessageEmbed {
@ -20,7 +20,16 @@ export default class PublicEmbed extends MessageEmbed {
} }
// Send methods // Send methods
public SendToCurrentChannel() { public async SendToCurrentChannel() {
const channel = this.context.message.channel as TextChannel;
const botMember = await this.context.message.guild?.members.fetch({ user: this.context.message.client.user! });
if (!botMember) return;
const permissions = channel.permissionsFor(botMember);
if (!permissions.has(Permissions.FLAGS.SEND_MESSAGES)) return;
this.context.message.channel.send({ embeds: [ this ]}); this.context.message.channel.send({ embeds: [ this ]});
} }
} }