Update discord.js

This commit is contained in:
Ethan Lane 2022-09-12 18:32:49 +01:00
parent 0465697b87
commit 1dc7bb2f38
Signed by: Vylpes
GPG key ID: EED233CC06D12504
26 changed files with 444 additions and 400 deletions

View file

@ -1,5 +1,4 @@
import { MessageActionRow, MessageButton } from "discord.js";
import { MessageButtonStyles } from "discord.js/typings/enums";
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
import { ICommandContext } from "../contracts/ICommandContext";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
@ -14,29 +13,30 @@ export default class About extends Command {
const fundingLink = process.env.ABOUT_FUNDING;
const repoLink = process.env.ABOUT_REPO;
const embed = new PublicEmbed(context, "About", "")
.addField("Version", process.env.BOT_VER!, true)
.addField("Author", process.env.BOT_AUTHOR!, true)
.addField("Date", process.env.BOT_DATE!, true);
const embed = new PublicEmbed(context, "About", "Discord Bot made by Vylpes");
const row = new MessageActionRow();
embed.AddField("Version", process.env.BOT_VER!, true);
embed.AddField("Author", process.env.BOT_AUTHOR!, true);
embed.AddField("Date", process.env.BOT_DATE!, true);
const row = new ActionRowBuilder<ButtonBuilder>();
if (repoLink) {
row.addComponents(
new MessageButton()
new ButtonBuilder()
.setURL(repoLink)
.setLabel("Repo")
.setStyle(MessageButtonStyles.LINK));
.setStyle(ButtonStyle.Link));
}
if (fundingLink) {
row.addComponents(
new MessageButton()
new ButtonBuilder()
.setURL(fundingLink)
.setLabel("Funding")
.setStyle(MessageButtonStyles.LINK));
.setStyle(ButtonStyle.Link));
}
await embed.SendToCurrentChannel({ components: [row] });
await embed.SendToCurrentChannel({ components: [ row ] });
}
}

View file

@ -57,16 +57,16 @@ export default class Audits extends Command {
const audits = await Audit.FetchAuditsByUserId(userId, context.message.guild!.id);
if (!audits || audits.length == 0) {
const publicEmbed = new PublicEmbed(context, "", "There are no audits logged for this user.");
const publicEmbed = new PublicEmbed(context, "Audits", "There are no audits logged for this user.");
await publicEmbed.SendToCurrentChannel();
return;
}
const publicEmbed = new PublicEmbed(context, "Audit Log", "");
const publicEmbed = new PublicEmbed(context, "Audit Log", `Audits: ${audits.length}`);
for (let audit of audits) {
publicEmbed.addField(`${audit.AuditId} // ${AuditTools.TypeToFriendlyText(audit.AuditType)}`, audit.WhenCreated.toString());
publicEmbed.AddField(`${audit.AuditId} // ${AuditTools.TypeToFriendlyText(audit.AuditType)}`, audit.WhenCreated.toString());
}
await publicEmbed.SendToCurrentChannel();
@ -89,11 +89,11 @@ export default class Audits extends Command {
return;
}
const publicEmbed = new PublicEmbed(context, `Audit ${audit.AuditId.toUpperCase()}`, "");
const publicEmbed = new PublicEmbed(context, "Audit", audit.AuditId.toUpperCase());
publicEmbed.addField("Reason", audit.Reason || "*none*", true);
publicEmbed.addField("Type", AuditTools.TypeToFriendlyText(audit.AuditType), true);
publicEmbed.addField("Moderator", `<@${audit.ModeratorId}>`, true);
publicEmbed.AddField("Reason", audit.Reason || "*none*", true);
publicEmbed.AddField("Type", AuditTools.TypeToFriendlyText(audit.AuditType), true);
publicEmbed.AddField("Moderator", `<@${audit.ModeratorId}>`, true);
await publicEmbed.SendToCurrentChannel();
}
@ -117,7 +117,7 @@ export default class Audits extends Command {
await Audit.Remove(Audit, audit);
const publicEmbed = new PublicEmbed(context, "", "Audit cleared");
const publicEmbed = new PublicEmbed(context, "Audit", "Audit cleared");
await publicEmbed.SendToCurrentChannel();
}
@ -138,7 +138,7 @@ export default class Audits extends Command {
await audit.Save(Audit, audit);
const publicEmbed = new PublicEmbed(context, "", `Created new audit with ID \`${audit.AuditId}\``);
const publicEmbed = new PublicEmbed(context, "Audit", `Created new audit with ID \`${audit.AuditId}\``);
await publicEmbed.SendToCurrentChannel();
}
}

View file

@ -4,7 +4,6 @@ import LogEmbed from "../helpers/embeds/LogEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import Audit from "../entity/Audit";
import { AuditType } from "../constants/AuditType";
@ -18,17 +17,14 @@ export default class Ban extends Command {
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
public override async execute(context: ICommandContext) {
const targetUser = context.message.mentions.users.first();
if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist");
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed],
};
return;
}
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
@ -37,10 +33,7 @@ export default class Ban extends Command {
const embed = new ErrorEmbed(context, "User is not in this server");
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed],
};
return;
}
const reasonArgs = context.args;
@ -48,21 +41,13 @@ export default class Ban extends Command {
const reason = reasonArgs.join(" ");
if (!context.message.guild?.available) {
return {
commandContext: context,
embeds: [],
};
}
if (!context.message.guild?.available) return;
if (!targetMember.bannable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed],
};
return;
}
const logEmbed = new LogEmbed(context, "Member Banned");
@ -82,10 +67,5 @@ export default class Ban extends Command {
await audit.Save(Audit, audit);
}
return {
commandContext: context,
embeds: [logEmbed, publicEmbed],
};
}
}

View file

@ -26,10 +26,11 @@ export default class Bunny extends Command {
const result = await randomBunny(selectedSubreddit, 'hot');
if (result.IsSuccess) {
const embed = new PublicEmbed(context, result.Result!.Title, "")
.setImage(result.Result!.Url)
.setURL(`https://reddit.com${result.Result!.Permalink}`)
.setFooter({ text: `r/${selectedSubreddit} · ${result.Result!.Ups} upvotes` });
const embed = new PublicEmbed(context, result.Result!.Title, "");
embed.SetImage(result.Result!.Url)
embed.SetURL(`https://reddit.com${result.Result!.Permalink}`)
embed.SetFooter(`r/${selectedSubreddit} · ${result.Result!.Ups} upvotes`);
await embed.SendToCurrentChannel();
} else {

View file

@ -3,7 +3,6 @@ import { TextChannel } from "discord.js";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
export default class Clear extends Command {
constructor() {
@ -15,15 +14,12 @@ export default class Clear extends Command {
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
public override async execute(context: ICommandContext) {
if (context.args.length == 0) {
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
await errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
return;
}
const totalToClear = Number.parseInt(context.args[0]);
@ -31,20 +27,13 @@ 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");
await errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
return;
}
await (context.message.channel as TextChannel).bulkDelete(totalToClear);
const embed = new PublicEmbed(context, "", `${totalToClear} message(s) were removed`);
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
}

View file

@ -1,4 +1,3 @@
import { existsSync, readdirSync } from "fs";
import { CoreClient } from "../client/client";
import { ICommandContext } from "../contracts/ICommandContext";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
@ -33,12 +32,12 @@ export default class Help extends Command {
.filter(x => !x.ServerId || x.ServerId == context.message.guild?.id);
const cateogries = [...new Set(allCommands.map(x => x.Command.Category))];
const embed = new PublicEmbed(context, "Commands", "");
const embed = new PublicEmbed(context, "Commands", `Commands: ${allCommands.length}`);
cateogries.forEach(category => {
let filtered = allCommands.filter(x => x.Command.Category == category);
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(", "));
});
await embed.SendToCurrentChannel();
@ -49,15 +48,15 @@ export default class Help extends Command {
const exclusiveCommand = CoreClient.commandItems.find(x => x.Name == context.args[0] && x.ServerId == context.message.guild?.id);
if (exclusiveCommand) {
const embed = new PublicEmbed(context, StringTools.Capitalise(exclusiveCommand.Name), "");
embed.addField("Category", StringTools.Capitalise(exclusiveCommand.Command.Category || "Uncategorised"));
embed.addField("Required Roles", StringTools.Capitalise(exclusiveCommand.Command.Roles.join(", ")) || "Everyone");
const embed = new PublicEmbed(context, StringTools.Capitalise(exclusiveCommand.Name), "Coming Soon");
embed.AddField("Category", StringTools.Capitalise(exclusiveCommand.Command.Category || "Uncategorised"));
embed.AddField("Required Roles", StringTools.Capitalise(exclusiveCommand.Command.Roles.join(", ")) || "Everyone");
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");
const embed = new PublicEmbed(context, StringTools.Capitalise(command.Name), "Coming Soon");
embed.AddField("Category", StringTools.Capitalise(command.Command.Category || "Uncategorised"));
embed.AddField("Required Roles", StringTools.Capitalise(command.Command.Roles.join(", ")) || "Everyone");
await embed.SendToCurrentChannel();
} else {

View file

@ -1,7 +1,6 @@
import { AuditType } from "../constants/AuditType";
import ErrorMessages from "../constants/ErrorMessages";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import Audit from "../entity/Audit";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import LogEmbed from "../helpers/embeds/LogEmbed";
@ -18,17 +17,14 @@ export default class Kick extends Command {
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
public override async execute(context: ICommandContext) {
const targetUser = context.message.mentions.users.first();
if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist");
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
return;
}
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
@ -37,10 +33,7 @@ export default class Kick extends Command {
const embed = new ErrorEmbed(context, "User is not in this server");
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
return;
}
const reasonArgs = context.args;
@ -48,21 +41,13 @@ export default class Kick extends Command {
const reason = reasonArgs.join(" ");
if (!context.message.guild?.available) {
return {
commandContext: context,
embeds: []
};
}
if (!context.message.guild?.available) return;
if (!targetMember.kickable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
return;
}
const logEmbed = new LogEmbed(context, "Member Kicked");
@ -82,10 +67,5 @@ export default class Kick extends Command {
await audit.Save(Audit, audit);
}
return {
commandContext: context,
embeds: [logEmbed, publicEmbed]
};
}
}

View file

@ -1,7 +1,6 @@
import { AuditType } from "../constants/AuditType";
import ErrorMessages from "../constants/ErrorMessages";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import Audit from "../entity/Audit";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import LogEmbed from "../helpers/embeds/LogEmbed";
@ -18,17 +17,14 @@ export default class Mute extends Command {
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
public override async execute(context: ICommandContext) {
const targetUser = context.message.mentions.users.first();
if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist");
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
return;
}
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
@ -37,10 +33,7 @@ export default class Mute extends Command {
const embed = new ErrorEmbed(context, "User is not in this server");
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
return;
}
const reasonArgs = context.args;
@ -48,21 +41,13 @@ export default class Mute extends Command {
const reason = reasonArgs.join(" ");
if (!context.message.guild?.available) {
return {
commandContext: context,
embeds: []
};
}
if (!context.message.guild?.available) return;
if (!targetMember.manageable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
return;
}
const logEmbed = new LogEmbed(context, "Member Muted");
@ -79,10 +64,7 @@ export default class Mute extends Command {
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
return;
}
await targetMember.roles.add(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
@ -95,10 +77,5 @@ export default class Mute extends Command {
await audit.Save(Audit, audit);
}
return {
commandContext: context,
embeds: [logEmbed, publicEmbed]
};
}
}

View file

@ -1,5 +1,4 @@
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";
@ -11,7 +10,7 @@ export default class Poll extends Command {
super.Category = "General";
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
public override async execute(context: ICommandContext) {
const argsJoined = context.args.join(" ");
const argsSplit = argsJoined.split(";");
@ -49,7 +48,9 @@ export default class Poll extends Command {
const embed = new PublicEmbed(context, title, description.join("\n"));
const message = await context.message.channel.send({ embeds: [ embed ]});
const message = await embed.SendToCurrentChannel();
if (!message) return;
description.forEach(async (value, index) => {
await message.react(reactionEmojis[index]);

View file

@ -3,7 +3,6 @@ import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Role as DiscordRole } from "discord.js";
import { Command } from "../type/command";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import SettingsHelper from "../helpers/SettingsHelper";
import { readFileSync } from "fs";
import { default as eRole } from "../entity/Role";
@ -56,7 +55,7 @@ export default class Role extends Command {
return stringArray;
}
public async SendRolesList(context: ICommandContext, serverId: string): Promise<ICommandReturnContext> {
public async SendRolesList(context: ICommandContext, serverId: string) {
const roles = await this.GetRolesList(context);
const botPrefix = await SettingsHelper.GetServerPrefix(serverId);
@ -64,14 +63,9 @@ export default class Role extends Command {
const embed = new PublicEmbed(context, "Roles", description);
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
public async ToggleRole(context: ICommandContext): Promise<ICommandReturnContext> {
public async ToggleRole(context: ICommandContext) {
const roles = await this.GetRolesList(context);
const requestedRole = context.args.join(" ");
@ -79,10 +73,7 @@ export default class Role extends Command {
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");
await errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
return;
}
const assignRole = context.message.guild?.roles.cache.find(x => x.name == requestedRole);
@ -91,10 +82,7 @@ export default class Role extends Command {
const errorEmbed = new ErrorEmbed(context, "The current server doesn't have this role. Please contact the server's moderators");
await errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
return;
}
const role = context.message.member?.roles.cache.find(x => x.name == requestedRole)
@ -104,35 +92,20 @@ export default class Role extends Command {
} else {
await this.RemoveRole(context, assignRole);
}
return {
commandContext: context,
embeds: []
};
}
public async AddRole(context: ICommandContext, role: DiscordRole): Promise<ICommandReturnContext> {
public async AddRole(context: ICommandContext, role: DiscordRole) {
await context.message.member?.roles.add(role, "Toggled with role command");
const embed = new PublicEmbed(context, "", `Gave role: \`${role.name}\``);
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
public async RemoveRole(context: ICommandContext, role: DiscordRole): Promise<ICommandReturnContext> {
public async RemoveRole(context: ICommandContext, role: DiscordRole) {
await context.message.member?.roles.remove(role, "Toggled with role command");
const embed = new PublicEmbed(context, "", `Removed role: \`${role.name}\``);
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
// ======

View file

@ -37,8 +37,8 @@ export default class Rules extends Command {
rules.forEach(rule => {
const embed = new PublicEmbed(context, rule.title || "", rule.description?.join("\n") || "");
embed.setImage(rule.image || "");
embed.setFooter({ text: rule.footer || "" });
embed.SetImage(rule.image || "");
embed.SetFooter(rule.footer || "");
embeds.push(embed);
});

View file

@ -1,6 +1,5 @@
import ErrorMessages from "../constants/ErrorMessages";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import LogEmbed from "../helpers/embeds/LogEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
@ -16,17 +15,14 @@ export default class Unmute extends Command {
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
public override async execute(context: ICommandContext) {
const targetUser = context.message.mentions.users.first();
if (!targetUser) {
const embed = new ErrorEmbed(context, "User does not exist");
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
return;
}
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
@ -35,10 +31,7 @@ export default class Unmute extends Command {
const embed = new ErrorEmbed(context, "User is not in this server");
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
return;
}
const reasonArgs = context.args;
@ -46,21 +39,13 @@ export default class Unmute extends Command {
const reason = reasonArgs.join(" ");
if (!context.message.guild?.available) {
return {
commandContext: context,
embeds: []
};
}
if (!context.message.guild?.available) return;
if (!targetMember.manageable) {
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
return;
}
const logEmbed = new LogEmbed(context, "Member Unmuted");
@ -77,20 +62,12 @@ export default class Unmute extends Command {
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
await embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
return;
}
await targetMember.roles.remove(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
await logEmbed.SendToModLogsChannel();
await publicEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [logEmbed, publicEmbed]
};
}
}

View file

@ -1,6 +1,5 @@
import { AuditType } from "../constants/AuditType";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import Audit from "../entity/Audit";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import LogEmbed from "../helpers/embeds/LogEmbed";
@ -17,17 +16,14 @@ export default class Warn extends Command {
];
}
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
public override async execute(context: ICommandContext) {
const user = context.message.mentions.users.first();
if (!user) {
const errorEmbed = new ErrorEmbed(context, "User does not exist");
await errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
return;
}
const member = context.message.guild?.members.cache.find(x => x.user.id == user.id);
@ -36,10 +32,7 @@ export default class Warn extends Command {
const errorEmbed = new ErrorEmbed(context, "User is not in this server");
await errorEmbed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [errorEmbed]
};
return;
}
const reasonArgs = context.args;
@ -47,12 +40,7 @@ export default class Warn extends Command {
const reason = reasonArgs.join(" ");
if (!context.message.guild?.available) {
return {
commandContext: context,
embeds: []
};
}
if (!context.message.guild?.available) return;
const logEmbed = new LogEmbed(context, "Member Warned");
logEmbed.AddUser("User", user, true);
@ -70,10 +58,5 @@ export default class Warn extends Command {
await audit.Save(Audit, audit);
}
return {
commandContext: context,
embeds: [logEmbed, publicEmbed]
};
}
}

View file

@ -1,7 +0,0 @@
import { MessageEmbed } from "discord.js";
import { ICommandContext } from "./ICommandContext";
export default interface ICommandReturnContext {
commandContext: ICommandContext,
embeds: MessageEmbed[]
}

View file

@ -1,6 +0,0 @@
import { MessageEmbed } from "discord.js";
import { ICommandContext } from "./ICommandContext";
export default interface ICommandReturnContext {
embeds: MessageEmbed[]
}

View file

@ -17,8 +17,8 @@ export default class MemberEvents extends Event {
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}` });
embed.AddField("Created", member.user.createdAt.toISOString());
embed.SetFooter(`Id: ${member.user.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;
@ -34,8 +34,8 @@ export default class MemberEvents extends Event {
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}` });
embed.AddField("Joined", member.joinedAt?.toISOString() || "n/a");
embed.SetFooter(`Id: ${member.user.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;

View file

@ -20,9 +20,9 @@ export default class GuildMemberUpdate {
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);
embed.setFooter({ text: `Id: ${this.newMember.user.id}` });
embed.AddField("Before", oldNickname, true);
embed.AddField("After", newNickname, true);
embed.SetFooter(`Id: ${this.newMember.user.id}`);
const channel = await SettingsHelper.GetSetting("event.member.update.channel", this.newMember.guild.id);
if (!channel || channel.toLowerCase() != "true") return;

View file

@ -22,11 +22,11 @@ export default class MessageEvents extends Event {
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*"}\`\`\``);
embed.AddField("Channel", message.channel.toString(), true);
embed.AddField("Content", `\`\`\`${message.content || "*none*"}\`\`\``);
if (message.attachments.size > 0) {
embed.addField("Attachments", `\`\`\`${message.attachments.map(x => x.url).join("\n")}\`\`\``);
embed.AddField("Attachments", `\`\`\`${message.attachments.map(x => x.url).join("\n")}\`\`\``);
}
const channel = await SettingsHelper.GetSetting("event.message.delete.channel", message.guild.id);
@ -48,9 +48,9 @@ export default class MessageEvents extends Event {
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*"}\`\`\``);
embed.addField("After", `\`\`\`${newMessage.content || "*none*"}\`\`\``);
embed.AddField("Channel", newMessage.channel.toString(), true);
embed.AddField("Before", `\`\`\`${oldMessage.content || "*none*"}\`\`\``);
embed.AddField("After", `\`\`\`${newMessage.content || "*none*"}\`\`\``);
const channel = await SettingsHelper.GetSetting("event.message.update.channel", newMessage.guild.id);
if (!channel || !newMessage.guild.channels.cache.find(x => x.name == channel)) return;

View file

@ -1,19 +1,46 @@
import { MessageEmbed, Permissions, TextChannel } from "discord.js";
import { EmbedBuilder, Message, PermissionsBitField, TextChannel } from "discord.js";
import { ICommandContext } from "../../contracts/ICommandContext";
export default class ErrorEmbed extends MessageEmbed {
export default class ErrorEmbed {
public context: ICommandContext;
private _embedBuilder: EmbedBuilder;
constructor(context: ICommandContext, message: string) {
super();
super.setColor(0xd52803);
super.setDescription(message);
this._embedBuilder = new EmbedBuilder()
.setColor(0xd52803)
.setDescription(message);
this.context = context;
}
public async SendToCurrentChannel() {
// Detail Methods
public AddField(name: string, value: string, inline: boolean = false) {
this._embedBuilder.addFields([
{
name,
value,
inline
}
])
}
public SetFooter(text: string) {
this._embedBuilder.setFooter({
text
});
}
public SetImage(imageUrl: string) {
this._embedBuilder.setImage(imageUrl);
}
public SetURL(url: string) {
this._embedBuilder.setURL(url);
}
// Send Methods
public async SendToCurrentChannel(): Promise<Message | undefined> {
const channel = this.context.message.channel as TextChannel;
const botMember = await this.context.message.guild?.members.fetch({ user: this.context.message.client.user! });
@ -21,8 +48,8 @@ export default class ErrorEmbed extends MessageEmbed {
const permissions = channel.permissionsFor(botMember);
if (!permissions.has(Permissions.FLAGS.SEND_MESSAGES)) return;
if (!permissions.has(PermissionsBitField.Flags.SendMessages)) return;
this.context.message.channel.send({ embeds: [ this ]});
return this.context.message.channel.send({ embeds: [ this._embedBuilder ]});
}
}

View file

@ -1,37 +1,71 @@
import { MessageEmbed, TextChannel, User, Guild, Client, Permissions } from "discord.js";
import { ICommandContext } from "../../contracts/ICommandContext";
import { EmbedBuilder, TextChannel, User, Guild, Client, PermissionsBitField, Message } from "discord.js";
import SettingsHelper from "../SettingsHelper";
export default class EventEmbed extends MessageEmbed {
export default class EventEmbed {
public guild: Guild;
private client: Client;
private _embedBuilder: EmbedBuilder;
constructor(client: Client, guild: Guild, title: string) {
super();
super.setColor(0x3050ba);
super.setTitle(title);
this._embedBuilder = new EmbedBuilder()
.setColor(0x3050ba)
.setTitle(title);
this.guild = guild;
this.client = client;
}
// Detail methods
public AddField(name: string, value: string, inline: boolean = false) {
this._embedBuilder.addFields([
{
name,
value,
inline
}
])
}
public SetFooter(text: string) {
this._embedBuilder.setFooter({
text
});
}
public SetImage(imageUrl: string) {
this._embedBuilder.setImage(imageUrl);
}
public AddUser(title: string, user: User, setThumbnail: boolean = false) {
this.addField(title, `${user} \`${user.tag}\``, true);
this._embedBuilder.addFields([
{
name: title,
value: `${user} \`${user.tag}\``,
inline: true,
}
])
if (setThumbnail) {
this.setThumbnail(user.displayAvatarURL());
this._embedBuilder.setThumbnail(user.displayAvatarURL());
}
}
public AddReason(message: string) {
this.addField("Reason", message || "*none*");
this._embedBuilder.addFields([
{
name: "Reason",
value: message || "*none*",
}
])
}
public SetURL(url: string) {
this._embedBuilder.setURL(url);
}
// Send methods
public async SendToChannel(name: string) {
public async SendToChannel(name: string): Promise<Message | undefined> {
const channel = this.guild.channels.cache
.find(channel => channel.name == name) as TextChannel;
@ -46,38 +80,38 @@ export default class EventEmbed extends MessageEmbed {
const permissions = channel.permissionsFor(botMember);
if (!permissions.has(Permissions.FLAGS.SEND_MESSAGES)) return;
if (!permissions.has(PermissionsBitField.Flags.SendMessages)) return;
channel.send({embeds: [ this ]});
return channel.send({embeds: [ this._embedBuilder ]});
}
public async SendToMessageLogsChannel() {
public async SendToMessageLogsChannel(): Promise<Message | undefined> {
const channelName = await SettingsHelper.GetSetting("channels.logs.message", this.guild.id);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
return this.SendToChannel(channelName);
}
public async SendToMemberLogsChannel() {
public async SendToMemberLogsChannel(): Promise<Message | undefined> {
const channelName = await SettingsHelper.GetSetting("channels.logs.member", this.guild.id);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
return this.SendToChannel(channelName);
}
public async SendToModLogsChannel() {
public async SendToModLogsChannel(): Promise<Message | undefined> {
const channelName = await SettingsHelper.GetSetting("channels.logs.mod", this.guild.id);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
return this.SendToChannel(channelName);
}
}

View file

@ -1,36 +1,72 @@
import { MessageEmbed, Permissions, TextChannel, User } from "discord.js";
import { TextChannel, User, EmbedBuilder, PermissionsBitField, Message } from "discord.js";
import ErrorMessages from "../../constants/ErrorMessages";
import { ICommandContext } from "../../contracts/ICommandContext";
import SettingsHelper from "../SettingsHelper";
import ErrorEmbed from "./ErrorEmbed";
export default class LogEmbed extends MessageEmbed {
export default class LogEmbed {
public context: ICommandContext;
private _embedBuilder: EmbedBuilder;
constructor(context: ICommandContext, title: string) {
super();
super.setColor(0x3050ba);
super.setTitle(title);
this._embedBuilder = new EmbedBuilder()
.setColor(0x3050ba)
.setTitle(title);
this.context = context;
}
// Detail methods
public AddField(name: string, value: string, inline: boolean = false) {
this._embedBuilder.addFields([
{
name,
value,
inline
}
])
}
public SetFooter(text: string) {
this._embedBuilder.setFooter({
text
});
}
public SetImage(imageUrl: string) {
this._embedBuilder.setImage(imageUrl);
}
public AddUser(title: string, user: User, setThumbnail: boolean = false) {
this.addField(title, `${user} \`${user.tag}\``, true);
this._embedBuilder.addFields([
{
name: title,
value: `${user} \`${user.tag}\``,
inline: true,
}
]);
if (setThumbnail) {
this.setThumbnail(user.displayAvatarURL());
this._embedBuilder.setThumbnail(user.displayAvatarURL());
}
}
public AddReason(message: string) {
this.addField("Reason", message || "*none*");
this._embedBuilder.addFields([
{
name: "Reason",
value: message || "*none*",
}
])
}
public SetURL(url: string) {
this._embedBuilder.setURL(url);
}
// Send methods
public async SendToCurrentChannel() {
public async SendToCurrentChannel(): Promise<Message | undefined> {
const channel = this.context.message.channel as TextChannel;
const botMember = await this.context.message.guild?.members.fetch({ user: this.context.message.client.user! });
@ -38,51 +74,52 @@ export default class LogEmbed extends MessageEmbed {
const permissions = channel.permissionsFor(botMember);
if (!permissions.has(Permissions.FLAGS.SEND_MESSAGES)) return;
if (!permissions.has(PermissionsBitField.Flags.SendMessages)) return;
this.context.message.channel.send({ embeds: [ this ]});
return this.context.message.channel.send({ embeds: [ this._embedBuilder ]});
}
public SendToChannel(name: string) {
public async SendToChannel(name: string): Promise<Message | undefined> {
const channel = this.context.message.guild?.channels.cache
.find(channel => channel.name == name) as TextChannel;
if (!channel) {
const errorEmbed = new ErrorEmbed(this.context, ErrorMessages.ChannelNotFound);
errorEmbed.SendToCurrentChannel();
return;
}
channel.send({ embeds: [ this ]});
return await channel.send({ embeds: [ this._embedBuilder ]});
}
public async SendToMessageLogsChannel() {
public async SendToMessageLogsChannel(): Promise<Message | undefined> {
const channelName = await SettingsHelper.GetSetting("channels.logs.message", this.context.message.guild?.id!);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
return this.SendToChannel(channelName);
}
public async SendToMemberLogsChannel() {
public async SendToMemberLogsChannel(): Promise<Message | undefined> {
const channelName = await SettingsHelper.GetSetting("channels.logs.member", this.context.message.guild?.id!);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
return this.SendToChannel(channelName);
}
public async SendToModLogsChannel() {
public async SendToModLogsChannel(): Promise<Message | undefined> {
const channelName = await SettingsHelper.GetSetting("channels.logs.mod", this.context.message.guild?.id!);
if (!channelName) {
return;
}
this.SendToChannel(channelName);
return this.SendToChannel(channelName);
}
}

View file

@ -1,26 +1,56 @@
import { MessageEmbed, MessageOptions, Permissions, TextChannel } from "discord.js";
import { EmbedBuilder, Message, MessageOptions, PermissionsBitField, TextChannel } from "discord.js";
import { ICommandContext } from "../../contracts/ICommandContext";
export default class PublicEmbed extends MessageEmbed {
export default class PublicEmbed {
public context: ICommandContext;
private _embedBuilder: EmbedBuilder;
constructor(context: ICommandContext, title: string, description: string) {
super();
super.setColor(0x3050ba);
super.setTitle(title);
super.setDescription(description);
this._embedBuilder = new EmbedBuilder()
.setColor(0x3050ba)
.setTitle(title)
.setDescription(description);
this.context = context;
}
// Detail methods
public AddField(name: string, value: string, inline: boolean = false) {
this._embedBuilder.addFields([
{
name,
value,
inline
}
])
}
public SetFooter(text: string) {
this._embedBuilder.setFooter({
text
});
}
public SetImage(imageUrl: string) {
this._embedBuilder.setImage(imageUrl);
}
public AddReason(message: string) {
this.addField("Reason", message || "*none*");
this._embedBuilder.addFields([
{
name: "Reason",
value: message || "*none*",
}
])
}
public SetURL(url: string) {
this._embedBuilder.setURL(url);
}
// Send methods
public async SendToCurrentChannel(options?: MessageOptions) {
public async SendToCurrentChannel(options?: MessageOptions): Promise<Message | undefined> {
const channel = this.context.message.channel as TextChannel;
const botMember = await this.context.message.guild?.members.fetch({ user: this.context.message.client.user! });
@ -28,8 +58,8 @@ export default class PublicEmbed extends MessageEmbed {
const permissions = channel.permissionsFor(botMember);
if (!permissions.has(Permissions.FLAGS.SEND_MESSAGES)) return;
if (!permissions.has(PermissionsBitField.Flags.SendMessages)) return;
this.context.message.channel.send({ embeds: [ this ], ...options});
return this.context.message.channel.send({ embeds: [ this._embedBuilder ], ...options});
}
}

View file

@ -1,7 +1,10 @@
import { CommandResponse } from "../constants/CommandResponse";
import { ICommandContext } from "../contracts/ICommandContext";
import { SlashCommandBuilder } from "discord.js";
export class Command {
public SlashCommandBuilder: SlashCommandBuilder;
public Roles: string[];
public Category?: string;

View file

@ -1,7 +1,7 @@
import { CoreClient } from "./client/client";
import * as dotenv from "dotenv";
import registry from "./registry";
import { Intents } from "discord.js";
import { IntentsBitField } from "discord.js";
dotenv.config();
@ -20,9 +20,10 @@ requiredConfigs.forEach(config => {
});
const client = new CoreClient([
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS,
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.MessageContent,
]);
registry.RegisterCommands();