2022-04-24 14:46:37 +01:00
|
|
|
import { Event } from "../type/event";
|
|
|
|
import { GuildMember } from "discord.js";
|
|
|
|
import EventEmbed from "../helpers/embeds/EventEmbed";
|
|
|
|
import GuildMemberUpdate from "./MemberEvents/GuildMemberUpdate";
|
2022-04-24 15:32:29 +01:00
|
|
|
import SettingsHelper from "../helpers/SettingsHelper";
|
2022-04-24 14:46:37 +01:00
|
|
|
|
|
|
|
export default class MemberEvents extends Event {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
2022-04-24 15:32:29 +01:00
|
|
|
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;
|
|
|
|
|
2022-04-24 14:46:37 +01:00
|
|
|
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}` });
|
|
|
|
|
2022-04-24 15:32:29 +01:00
|
|
|
const channel = await SettingsHelper.GetSetting("event.member.add.channel", member.guild.id);
|
|
|
|
if (!channel || !member.guild.channels.cache.find(x => x.name == channel)) return;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-04-24 15:32:29 +01:00
|
|
|
embed.SendToChannel(channel);
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
|
2022-04-24 15:32:29 +01:00
|
|
|
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;
|
|
|
|
|
2022-04-24 14:46:37 +01:00
|
|
|
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}` });
|
|
|
|
|
2022-04-24 15:32:29 +01:00
|
|
|
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);
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
|
2022-04-24 15:32:29 +01:00
|
|
|
public override async guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
|
2022-04-24 14:46:37 +01:00
|
|
|
const handler = new GuildMemberUpdate(oldMember, newMember);
|
|
|
|
|
|
|
|
if (oldMember.nickname != newMember.nickname) { // Nickname change
|
|
|
|
await handler.NicknameChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|