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

@ -20,3 +20,18 @@ verification.enabled: Enables/Disables the verification feature (Default: "false
verification.channel: The channel to listen to for entry codes (Default: "entry") verification.channel: The channel to listen to for entry codes (Default: "entry")
verification.role: The server access role (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.channel", Value: "entry" });
this.values.push({ Key: "verification.role", Value: "Entry" }); this.values.push({ Key: "verification.role", Value: "Entry" });
this.values.push({ Key: "verification.code", Value: "" }); 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 { GuildMember } from "discord.js";
import EventEmbed from "../helpers/embeds/EventEmbed"; import EventEmbed from "../helpers/embeds/EventEmbed";
import GuildMemberUpdate from "./MemberEvents/GuildMemberUpdate"; import GuildMemberUpdate from "./MemberEvents/GuildMemberUpdate";
import IEventReturnContext from "../contracts/IEventReturnContext"; import SettingsHelper from "../helpers/SettingsHelper";
export default class MemberEvents extends Event { export default class MemberEvents extends Event {
constructor() { constructor() {
super(); 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"); const embed = new EventEmbed(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}` });
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 { embed.SendToChannel(channel);
embeds: [embed]
};
} }
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"); const embed = new EventEmbed(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}` });
await embed.SendToMemberLogsChannel(); const channel = await SettingsHelper.GetSetting("event.member.remove.channel", member.guild.id);
if (!channel || !member.guild.channels.cache.find(x => x.name == channel)) return;
return { embed.SendToChannel(channel);
embeds: [embed]
};
} }
public override async guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember): Promise<IEventReturnContext> { public override async guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
const handler = new GuildMemberUpdate(oldMember, newMember); const handler = new GuildMemberUpdate(oldMember, newMember);
if (oldMember.nickname != newMember.nickname) { // Nickname change if (oldMember.nickname != newMember.nickname) { // Nickname change
await handler.NicknameChanged(); await handler.NicknameChanged();
} }
return {
embeds: []
};
} }
} }

View file

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

View file

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