Make bot check channel permissions before sending messages
This commit is contained in:
parent
aa070bb7a7
commit
db2ded40b7
28 changed files with 146 additions and 142 deletions
|
@ -7,7 +7,7 @@
|
|||
# any secret values.
|
||||
|
||||
BOT_TOKEN=
|
||||
BOT_VER=3.0.2
|
||||
BOT_VER=3.0.3
|
||||
BOT_AUTHOR=Vylpes
|
||||
BOT_DATE=16 May 2022
|
||||
BOT_DATE=04 Jun 2022
|
||||
BOT_OWNERID=147392775707426816
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "vylbot-app",
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.3",
|
||||
"description": "A discord bot made for Vylpes' Den",
|
||||
"main": "./dist/vylbot",
|
||||
"typings": "./dist",
|
||||
|
|
|
@ -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.`);
|
||||
|
||||
embedInfo.SendToCurrentChannel();
|
||||
await embedInfo.SendToCurrentChannel();
|
||||
}
|
||||
}
|
|
@ -80,7 +80,7 @@ export default class Lobby extends Command {
|
|||
|
||||
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");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -94,15 +94,15 @@ export default class Lobby extends Command {
|
|||
break;
|
||||
case "help":
|
||||
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 embed = new PublicEmbed(context, "Configure Lobby Command", helpText);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
|
||||
private async AddLobbyConfig(context: ICommandContext) {
|
||||
|
@ -138,7 +138,7 @@ export default class Lobby extends Command {
|
|||
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`);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
|
||||
private async RemoveLobbyConfig(context: ICommandContext) {
|
||||
|
@ -146,7 +146,7 @@ export default class Lobby extends Command {
|
|||
|
||||
if (!entity) {
|
||||
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;
|
||||
}
|
||||
|
@ -154,6 +154,6 @@ export default class Lobby extends Command {
|
|||
await BaseEntity.Remove<eLobby>(eLobby, entity);
|
||||
|
||||
const embed = new PublicEmbed(context, "", `Removed <#${context.args[2]}> from the list of lobby channels`);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
import { ICommandContext } from "../contracts/ICommandContext";
|
||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
||||
import { Command } from "../type/command";
|
||||
|
||||
|
@ -9,17 +8,12 @@ export default class About extends Command {
|
|||
super.Category = "General";
|
||||
}
|
||||
|
||||
public override execute(context: ICommandContext): ICommandReturnContext {
|
||||
public override async execute(context: ICommandContext) {
|
||||
const embed = new PublicEmbed(context, "About", "")
|
||||
.addField("Version", process.env.BOT_VER!)
|
||||
.addField("Author", process.env.BOT_AUTHOR!)
|
||||
.addField("Date", process.env.BOT_DATE!);
|
||||
|
||||
embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed]
|
||||
};
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
}
|
|
@ -21,7 +21,8 @@ export default class Ban extends Command {
|
|||
|
||||
if (!targetUser) {
|
||||
const embed = new ErrorEmbed(context, "User does not exist");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed],
|
||||
|
@ -32,7 +33,8 @@ export default class Ban extends Command {
|
|||
|
||||
if (!targetMember) {
|
||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed],
|
||||
|
@ -53,7 +55,8 @@ export default class Ban extends Command {
|
|||
|
||||
if (!targetMember.bannable) {
|
||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
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 logEmbed.SendToModLogsChannel();
|
||||
publicEmbed.SendToCurrentChannel();
|
||||
await publicEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
|
|
@ -20,10 +20,10 @@ export default class Bunny extends Command {
|
|||
.setURL(`https://reddit.com${result.Result!.Permalink}`)
|
||||
.setFooter({ text: `r/Rabbits · ${result.Result!.Ups} upvotes` });
|
||||
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
} else {
|
||||
const errorEmbed = new ErrorEmbed(context, "There was an error using this command.");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ export default class Clear extends Command {
|
|||
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
|
||||
if (context.args.length == 0) {
|
||||
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -30,7 +30,7 @@ export default class Clear extends Command {
|
|||
|
||||
if (!totalToClear || totalToClear <= 0 || totalToClear > 100) {
|
||||
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [errorEmbed]
|
||||
|
@ -40,7 +40,7 @@ export default class Clear extends Command {
|
|||
await (context.message.channel as TextChannel).bulkDelete(totalToClear);
|
||||
|
||||
const embed = new PublicEmbed(context, "", `${totalToClear} message(s) were removed`);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
|
|
@ -58,7 +58,7 @@ export default class Code extends Command {
|
|||
].join("\n");
|
||||
|
||||
const embed = new PublicEmbed(context, "", description);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
const embed = new PublicEmbed(context, "Code", `Entry code has been set to \`${randomCode}\``);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
|
||||
private async SendEmbed(context: ICommandContext) {
|
||||
|
@ -89,6 +89,6 @@ export default class Code extends Command {
|
|||
}
|
||||
|
||||
const embed = new PublicEmbed(context, "Entry Code", code!);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
import { Guild } from "discord.js";
|
||||
import { readFileSync } from "fs";
|
||||
import { CommandResponse } from "../constants/CommandResponse";
|
||||
import DefaultValues from "../constants/DefaultValues";
|
||||
import { ICommandContext } from "../contracts/ICommandContext";
|
||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
||||
import Server from "../entity/Server";
|
||||
import Setting from "../entity/Setting";
|
||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
||||
|
@ -83,7 +81,7 @@ export default class Config extends Command {
|
|||
|
||||
const embed = new PublicEmbed(context, "Config", description);
|
||||
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
|
||||
private async GetValue(context: ICommandContext, server: Server, key: string) {
|
||||
|
@ -91,10 +89,10 @@ export default class Config extends Command {
|
|||
|
||||
if (setting) {
|
||||
const embed = new PublicEmbed(context, "", `${key}: ${setting.Value}`);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
} else {
|
||||
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) {
|
||||
const embed = new PublicEmbed(context, "", "Setting has been reset");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await Setting.Remove(Setting, setting);
|
||||
|
||||
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) {
|
||||
|
@ -131,6 +130,6 @@ export default class Config extends Command {
|
|||
}
|
||||
|
||||
const embed = new PublicEmbed(context, "", "Setting has been set");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ export default class Disable extends Command {
|
|||
].join("\n");
|
||||
|
||||
const embed = new PublicEmbed(context, "", description);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
|
||||
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(","));
|
||||
|
||||
const embed = new PublicEmbed(context, "", `Disabled command: ${commandName}`);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
|
||||
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(","));
|
||||
|
||||
const embed = new PublicEmbed(context, "", `Enabled command: ${commandName}`);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
}
|
|
@ -20,15 +20,15 @@ export default class Help extends Command {
|
|||
super.Category = "General";
|
||||
}
|
||||
|
||||
public override execute(context: ICommandContext) {
|
||||
public override async execute(context: ICommandContext) {
|
||||
if (context.args.length == 0) {
|
||||
this.SendAll(context);
|
||||
await this.SendAll(context);
|
||||
} else {
|
||||
this.SendSingle(context);
|
||||
await this.SendSingle(context);
|
||||
}
|
||||
}
|
||||
|
||||
public SendAll(context: ICommandContext) {
|
||||
public async SendAll(context: ICommandContext) {
|
||||
const allCommands = CoreClient.commandItems
|
||||
.filter(x => !x.ServerId || x.ServerId == context.message.guild?.id);
|
||||
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.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 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("Required Roles", StringTools.Capitalise(exclusiveCommand.Command.Roles.join(", ")) || "Everyone");
|
||||
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
} else if (command) {
|
||||
const embed = new PublicEmbed(context, StringTools.Capitalise(command.Name), "");
|
||||
embed.addField("Category", StringTools.Capitalise(command.Command.Category || "Uncategorised"));
|
||||
embed.addField("Required Roles", StringTools.Capitalise(command.Command.Roles.join(", ")) || "Everyone");
|
||||
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
} else {
|
||||
const errorEmbed = new ErrorEmbed(context, "Command does not exist");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return;
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ export default class Kick extends Command {
|
|||
|
||||
if (!targetUser) {
|
||||
const embed = new ErrorEmbed(context, "User does not exist");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -33,7 +33,7 @@ export default class Kick extends Command {
|
|||
|
||||
if (!targetMember) {
|
||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -55,7 +55,7 @@ export default class Kick extends Command {
|
|||
|
||||
if (!targetMember.kickable) {
|
||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -73,7 +73,7 @@ export default class Kick extends Command {
|
|||
await targetMember.kick(`Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
|
||||
|
||||
await logEmbed.SendToModLogsChannel();
|
||||
publicEmbed.SendToCurrentChannel();
|
||||
await publicEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
|
|
@ -21,7 +21,7 @@ export default class Mute extends Command {
|
|||
|
||||
if (!targetUser) {
|
||||
const embed = new ErrorEmbed(context, "User does not exist");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -33,7 +33,7 @@ export default class Mute extends Command {
|
|||
|
||||
if (!targetMember) {
|
||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -55,7 +55,7 @@ export default class Mute extends Command {
|
|||
|
||||
if (!targetMember.manageable) {
|
||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -75,7 +75,7 @@ export default class Mute extends Command {
|
|||
|
||||
if (!mutedRole) {
|
||||
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
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 logEmbed.SendToModLogsChannel();
|
||||
publicEmbed.SendToCurrentChannel();
|
||||
await publicEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
|
|
@ -17,7 +17,7 @@ export default class Poll extends Command {
|
|||
|
||||
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");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
|
|
@ -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 embed = new PublicEmbed(context, "Roles", description);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -77,7 +77,7 @@ export default class Role extends Command {
|
|||
|
||||
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");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -89,7 +89,7 @@ export default class Role extends Command {
|
|||
|
||||
if (!assignRole) {
|
||||
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 {
|
||||
commandContext: context,
|
||||
|
@ -115,7 +115,7 @@ export default class Role extends Command {
|
|||
await context.message.member?.roles.add(role, "Toggled with role command");
|
||||
|
||||
const embed = new PublicEmbed(context, "", `Gave role: \`${role.name}\``);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -127,7 +127,7 @@ export default class Role extends Command {
|
|||
await context.message.member?.roles.remove(role, "Toggled with role command");
|
||||
|
||||
const embed = new PublicEmbed(context, "", `Removed role: \`${role.name}\``);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -144,7 +144,7 @@ export default class Role extends Command {
|
|||
|
||||
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");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -157,15 +157,15 @@ export default class Role extends Command {
|
|||
await this.RemoveRoleConfig(context);
|
||||
break;
|
||||
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 embed = new PublicEmbed(context, "Configure Role Command", helpText);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
|
||||
private async AddRoleConfig(context: ICommandContext) {
|
||||
|
@ -180,7 +180,7 @@ export default class Role extends Command {
|
|||
|
||||
if (existingRole) {
|
||||
const errorEmbed = new ErrorEmbed(context, "This role has already been setup");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ export default class Role extends Command {
|
|||
|
||||
if (!server) {
|
||||
const errorEmbed = new ErrorEmbed(context, "Server not setup, please request the server owner runs the setup command.");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ export default class Role extends Command {
|
|||
await server.Save(Server, server);
|
||||
|
||||
const embed = new PublicEmbed(context, "", `Added \`${role.name}\` as a new assignable role`);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
|
||||
private async RemoveRoleConfig(context: ICommandContext) {
|
||||
|
@ -227,6 +227,6 @@ export default class Role extends Command {
|
|||
await eRole.Remove(eRole, existingRole);
|
||||
|
||||
const embed = new PublicEmbed(context, "", `Removed \`${role.name}\` from the list of assignable roles`);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { existsSync, readFileSync } from "fs";
|
||||
import { ICommandContext } from "../contracts/ICommandContext";
|
||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
||||
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`)) {
|
||||
const errorEmbed = new ErrorEmbed(context, "Rules file doesn't exist");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [errorEmbed]
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
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") || "");
|
||||
|
||||
embed.setImage(rule.image || "");
|
||||
embed.setFooter(rule.footer || "");
|
||||
embed.setFooter({ text: rule.footer || "" });
|
||||
|
||||
embeds.push(embed);
|
||||
});
|
||||
|
||||
embeds.forEach(x => x.SendToCurrentChannel());
|
||||
for (let i = 0; i < embeds.length; i++) {
|
||||
const embed = embeds[i];
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: embeds
|
||||
};
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,7 +22,8 @@ export default class Setup extends Command {
|
|||
|
||||
if (server) {
|
||||
const embed = new ErrorEmbed(context, "This server has already been setup, please configure using the config command");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -31,6 +32,6 @@ export default class Setup extends Command {
|
|||
await newServer.Save(Server, newServer);
|
||||
|
||||
const embed = new PublicEmbed(context, "Success", "Please configure using the config command");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ export default class Unmute extends Command {
|
|||
|
||||
if (!targetUser) {
|
||||
const embed = new ErrorEmbed(context, "User does not exist");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -33,7 +33,7 @@ export default class Unmute extends Command {
|
|||
|
||||
if (!targetMember) {
|
||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -55,7 +55,7 @@ export default class Unmute extends Command {
|
|||
|
||||
if (!targetMember.manageable) {
|
||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -75,7 +75,7 @@ export default class Unmute extends Command {
|
|||
|
||||
if (!mutedRole) {
|
||||
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
|
||||
embed.SendToCurrentChannel();
|
||||
await embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
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 logEmbed.SendToModLogsChannel();
|
||||
publicEmbed.SendToCurrentChannel();
|
||||
await publicEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
|
|
@ -20,7 +20,7 @@ export default class Warn extends Command {
|
|||
|
||||
if (!user) {
|
||||
const errorEmbed = new ErrorEmbed(context, "User does not exist");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -32,7 +32,7 @@ export default class Warn extends Command {
|
|||
|
||||
if (!member) {
|
||||
const errorEmbed = new ErrorEmbed(context, "User is not in this server");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
await errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
@ -61,7 +61,7 @@ export default class Warn extends Command {
|
|||
publicEmbed.AddReason(reason);
|
||||
|
||||
await logEmbed.SendToModLogsChannel();
|
||||
publicEmbed.SendToCurrentChannel();
|
||||
await publicEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
|
|
|
@ -15,7 +15,7 @@ export default class MemberEvents extends Event {
|
|||
const enabled = await SettingsHelper.GetSetting("event.member.add.enabled", member.guild.id);
|
||||
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.addField("Created", member.user.createdAt.toISOString());
|
||||
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);
|
||||
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) {
|
||||
|
@ -32,7 +32,7 @@ export default class MemberEvents extends Event {
|
|||
const enabled = await SettingsHelper.GetSetting("event.member.remove.enabled", member.guild.id);
|
||||
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.addField("Joined", member.joinedAt?.toISOString() || "n/a");
|
||||
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);
|
||||
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) {
|
||||
|
|
|
@ -18,7 +18,7 @@ export default class GuildMemberUpdate {
|
|||
const oldNickname = this.oldMember.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.addField("Before", oldNickname, 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);
|
||||
if (!channel || channel.toLowerCase() != "true") return;
|
||||
|
||||
embed.SendToChannel(channel);
|
||||
await embed.SendToChannel(channel);
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ export default class MessageEvents extends Event {
|
|||
const enabled = await SettingsHelper.GetSetting("event.message.delete.enabled", message.guild.id);
|
||||
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.addField("Channel", message.channel.toString(), true);
|
||||
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);
|
||||
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) {
|
||||
|
@ -39,7 +39,7 @@ export default class MessageEvents extends Event {
|
|||
const enabled = await SettingsHelper.GetSetting("event.message.update.enabled", newMessage.guild.id);
|
||||
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.addField("Channel", newMessage.channel.toString(), true);
|
||||
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);
|
||||
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) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { MessageEmbed } from "discord.js";
|
||||
import { MessageEmbed, Permissions, TextChannel } from "discord.js";
|
||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
||||
|
||||
export default class ErrorEmbed extends MessageEmbed {
|
||||
|
@ -13,7 +13,16 @@ export default class ErrorEmbed extends MessageEmbed {
|
|||
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 ]});
|
||||
}
|
||||
}
|
|
@ -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 SettingsHelper from "../SettingsHelper";
|
||||
|
||||
export default class EventEmbed extends MessageEmbed {
|
||||
public guild: Guild;
|
||||
|
||||
constructor(guild: Guild, title: string) {
|
||||
private client: Client;
|
||||
|
||||
constructor(client: Client, guild: Guild, title: string) {
|
||||
super();
|
||||
|
||||
super.setColor(0x3050ba);
|
||||
super.setTitle(title);
|
||||
|
||||
this.guild = guild;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
// Detail methods
|
||||
|
@ -28,7 +31,7 @@ export default class EventEmbed extends MessageEmbed {
|
|||
}
|
||||
|
||||
// Send methods
|
||||
public SendToChannel(name: string) {
|
||||
public async SendToChannel(name: string) {
|
||||
const channel = this.guild.channels.cache
|
||||
.find(channel => channel.name == name) as TextChannel;
|
||||
|
||||
|
@ -37,6 +40,14 @@ export default class EventEmbed extends MessageEmbed {
|
|||
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 ]});
|
||||
}
|
||||
|
||||
|
|
|
@ -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 { ICommandContext } from "../../contracts/ICommandContext";
|
||||
import SettingsHelper from "../SettingsHelper";
|
||||
|
@ -30,7 +30,16 @@ export default class LogEmbed extends MessageEmbed {
|
|||
}
|
||||
|
||||
// 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 ]});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { MessageEmbed } from "discord.js";
|
||||
import { MessageEmbed, Permissions, TextChannel } from "discord.js";
|
||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
||||
|
||||
export default class PublicEmbed extends MessageEmbed {
|
||||
|
@ -20,7 +20,16 @@ export default class PublicEmbed extends MessageEmbed {
|
|||
}
|
||||
|
||||
// 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 ]});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue