Add ability to disable events

This commit is contained in:
Ethan Lane 2022-04-24 15:32:29 +01:00
parent 10aa1568a4
commit 31866b1c3b
Signed by: Vylpes
GPG key ID: EED233CC06D12504
5 changed files with 80 additions and 62 deletions

View file

@ -19,4 +19,19 @@ channels.logs.mod: The channel mod events will be logged to (Default: "mod-logs"
verification.enabled: Enables/Disables the verification feature (Default: "false")
verification.channel: The channel to listen to for entry codes (Default: "entry")
verification.role: The server access role (Default: "Entry")
verification.code: The entry code for the channel (Default: "")
verification.code: The entry code for the channel (Default: "")
event.message.delete.enabled: Enables/Disables the message delete log event (Default: "false")
event.message.delete.channel: Sets the channel the bot will log message delete events to (Default: "message-logs")
event.message.update.enabled: Enables/Disables the message delete log event (Default: "false")
event.message.update.channel: Sets the channel the bot will log message delete events to (Default: "message-logs")
event.member.add.enabled: Enables/Disables the message delete log event (Default: "false")
event.member.add.channel: Sets the channel the bot will log message delete events to (Default: "member-logs")
event.member.remove.enabled: Enables/Disables the message delete log event (Default: "false")
event.member.remove.channel: Sets the channel the bot will log message delete events to (Default: "member-logs")
event.member.update.enabled: Enables/Disables the message delete log event (Default: "false")
event.member.update.channel: Sets the channel the bot will log message delete events to (Default: "member-logs")

View file

@ -46,6 +46,23 @@ export default class DefaultValues {
this.values.push({ Key: "verification.channel", Value: "entry" });
this.values.push({ Key: "verification.role", Value: "Entry" });
this.values.push({ Key: "verification.code", Value: "" });
// Event
this.values.push({ Key: "event.message.delete.enabled", Value: "false" });
this.values.push({ Key: "event.message.delete.channel", Value: "message-logs" });
this.values.push({ Key: "event.message.update.enabled", Value: "false" });
this.values.push({ Key: "event.message.update.channel", Value: "message-logs" });
this.values.push({ Key: "event.member.add.enabled", Value: "false" });
this.values.push({ Key: "event.member.add.channel", Value: "member-logs" });
this.values.push({ Key: "event.member.remove.enabled", Value: "false" });
this.values.push({ Key: "event.member.remove.channel", Value: "member-logs" });
this.values.push({ Key: "event.member.update.enabled", Value: "false" });
this.values.push({ Key: "event.member.remove.channel", Value: "member-logs" });
}
}
}

View file

@ -2,48 +2,52 @@ import { Event } from "../type/event";
import { GuildMember } from "discord.js";
import EventEmbed from "../helpers/embeds/EventEmbed";
import GuildMemberUpdate from "./MemberEvents/GuildMemberUpdate";
import IEventReturnContext from "../contracts/IEventReturnContext";
import SettingsHelper from "../helpers/SettingsHelper";
export default class MemberEvents extends Event {
constructor() {
super();
}
public override async guildMemberAdd(member: GuildMember): Promise<IEventReturnContext> {
public override async guildMemberAdd(member: GuildMember) {
if (!member.guild) return;
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");
embed.AddUser("User", member.user, true);
embed.addField("Created", member.user.createdAt.toISOString());
embed.setFooter({ text: `Id: ${member.user.id}` });
await embed.SendToMemberLogsChannel();
const channel = await SettingsHelper.GetSetting("event.member.add.channel", member.guild.id);
if (!channel || !member.guild.channels.cache.find(x => x.name == channel)) return;
return {
embeds: [embed]
};
embed.SendToChannel(channel);
}
public override async guildMemberRemove(member: GuildMember): Promise<IEventReturnContext> {
public override async guildMemberRemove(member: GuildMember) {
if (!member.guild) return;
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");
embed.AddUser("User", member.user, true);
embed.addField("Joined", member.joinedAt?.toISOString() || "n/a");
embed.setFooter({ text: `Id: ${member.user.id}` });
await embed.SendToMemberLogsChannel();
return {
embeds: [embed]
};
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);
}
public override async guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember): Promise<IEventReturnContext> {
public override async guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
const handler = new GuildMemberUpdate(oldMember, newMember);
if (oldMember.nickname != newMember.nickname) { // Nickname change
await handler.NicknameChanged();
}
return {
embeds: []
};
}
}

View file

@ -1,6 +1,6 @@
import { GuildMember } from "discord.js";
import IEventReturnContext from "../../contracts/IEventReturnContext";
import EventEmbed from "../../helpers/embeds/EventEmbed";
import SettingsHelper from "../../helpers/SettingsHelper";
export default class GuildMemberUpdate {
public oldMember: GuildMember;
@ -11,7 +11,10 @@ export default class GuildMemberUpdate {
this.newMember = newMember;
}
public async NicknameChanged(): Promise<IEventReturnContext> {
public async NicknameChanged() {
const enabled = await SettingsHelper.GetSetting("event.member.update.enabled", this.newMember.guild.id);
if (!enabled || enabled.toLowerCase() != "true") return;
const oldNickname = this.oldMember.nickname || "*none*";
const newNickname = this.newMember.nickname || "*none*";
@ -20,11 +23,10 @@ export default class GuildMemberUpdate {
embed.addField("Before", oldNickname, true);
embed.addField("After", newNickname, true);
embed.setFooter({ text: `Id: ${this.newMember.user.id}` });
const channel = await SettingsHelper.GetSetting("event.member.update.channel", this.newMember.guild.id);
if (!channel || channel.toLowerCase() != "true") return;
await embed.SendToMemberLogsChannel();
return {
embeds: [embed]
};
embed.SendToChannel(channel);
}
}

View file

@ -1,7 +1,6 @@
import { Event } from "../type/event";
import { Message } from "discord.js";
import EventEmbed from "../helpers/embeds/EventEmbed";
import IEventReturnContext from "../contracts/IEventReturnContext";
import SettingsHelper from "../helpers/SettingsHelper";
import OnMessage from "./MessageEvents/OnMessage";
@ -10,18 +9,12 @@ export default class MessageEvents extends Event {
super();
}
public override async messageDelete(message: Message): Promise<IEventReturnContext> {
if (!message.guild) {
return {
embeds: []
};
}
public override async messageDelete(message: Message) {
if (!message.guild) return;
if (message.author.bot) return;
if (message.author.bot) {
return {
embeds: []
};
}
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");
embed.AddUser("User", message.author, true);
@ -32,31 +25,19 @@ export default class MessageEvents extends Event {
embed.addField("Attachments", `\`\`\`${message.attachments.map(x => x.url).join("\n")}\`\`\``);
}
await embed.SendToMessageLogsChannel();
const channel = await SettingsHelper.GetSetting("event.message.delete.channel", message.guild.id);
if (!channel || !message.guild.channels.cache.find(x => x.name == channel)) return;
return {
embeds: [embed]
};
embed.SendToChannel(channel);
}
public override async messageUpdate(oldMessage: Message, newMessage: Message): Promise<IEventReturnContext> {
if (!newMessage.guild){
return {
embeds: []
};
}
public override async messageUpdate(oldMessage: Message, newMessage: Message) {
if (!newMessage.guild) return;
if (newMessage.author.bot) return;
if (oldMessage.content == newMessage.content) return;
if (newMessage.author.bot) {
return {
embeds: []
};
}
if (oldMessage.content == newMessage.content) {
return {
embeds: []
};
}
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");
embed.AddUser("User", newMessage.author, true);
@ -64,11 +45,10 @@ export default class MessageEvents extends Event {
embed.addField("Before", `\`\`\`${oldMessage.content || "*none*"}\`\`\``);
embed.addField("After", `\`\`\`${newMessage.content || "*none*"}\`\`\``);
await embed.SendToMessageLogsChannel();
const channel = await SettingsHelper.GetSetting("event.message.update.channel", newMessage.guild.id);
if (!channel || !newMessage.guild.channels.cache.find(x => x.name == channel)) return;
return {
embeds: [embed]
};
embed.SendToChannel(channel);
}
public override async messageCreate(message: Message) {