-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move gMemberAdd and Remove to new structure, make invite collection g…
…lobal
- Loading branch information
Showing
4 changed files
with
241 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
const { EmbedBuilder, Events } = require("discord.js"); | ||
require("dotenv").config(); | ||
const autoroles = require("../Schemas/autorole.js"); | ||
const mutes = require("../Schemas/moderation/mute.js"); | ||
const muteRoles = require("../Schemas/moderation/mute-role.js"); | ||
const schema = require("../Schemas/base-system.js"); | ||
const logs = require("../Schemas/logger/members.js"); | ||
const settings = require("../Schemas/logger/settings.js"); | ||
|
||
module.exports = { | ||
name: Events.GuildMemberAdd, | ||
async execute(member, client) { | ||
if (!member || !client) { | ||
return; | ||
} | ||
|
||
const autoroleData = await autoroles.findOne({ Guild: member.guild.id }); | ||
if (autoroleData) { | ||
if (!autoroleData.Roles.length) return; | ||
try { | ||
for (const roleId of autoroleData.Roles) { | ||
const role = member.guild.roles.cache.get(roleId); | ||
if (role) { | ||
await member.roles.add(role); | ||
} | ||
} | ||
} catch (e) { | ||
return console.log(e); | ||
} | ||
} | ||
|
||
const muteData = await mutes.findOne({ | ||
Guild: member.guild.id, | ||
User: member.user.id, | ||
}); | ||
const muteRole = await muteRoles.findOne({ | ||
Guild: member.guild.id, | ||
}); | ||
if (muteData) { | ||
if (!muteRole) return; | ||
try { | ||
const role = member.guild.roles.cache.get(muteRole.Role); | ||
if (role) { | ||
await member.roles.add(role); | ||
} | ||
} catch (e) { | ||
return console.log(e); | ||
} | ||
} | ||
|
||
const settingsData = await settings.findOne({ | ||
Guild: member.guild.id, | ||
}); | ||
if (settingsData.Members === false) return; | ||
if (settingsData.Store === false && settingsData.Post === false) return; | ||
|
||
const data = await schema.findOne({ | ||
Guild: member.guild.id, | ||
ID: "audit-logs", | ||
}); | ||
if (!data || !data.Channel) return; | ||
const channel = client.channels.cache.get(data.Channel); | ||
if (!channel) return; | ||
|
||
const logData = await logs.findOne({ | ||
Guild: member.guild.id, | ||
User: member.user.id, | ||
}); | ||
|
||
const newInvites = await member.guild.invites.fetch(); | ||
const oldInvites = client.invites.get(member.guild.id) || new Map(); | ||
|
||
const invite = newInvites.find((i) => i.uses > oldInvites.get(i.code)); | ||
|
||
const date = new Date(); | ||
|
||
const embed = new EmbedBuilder() | ||
.setColor("#ff00b3") | ||
.setTimestamp() | ||
.setTitle(`${member.user.username} Has Joined the Server!`) | ||
.setFooter({ text: `FKZ • ID: ${member.user.id}` }) | ||
.addFields({ | ||
name: "User", | ||
value: `<@${member.user.id}> - \`${member.user.username}\``, | ||
inline: true, | ||
}); | ||
|
||
if (logData && logData.Avatar) { | ||
embed.setAuthor({ | ||
name: `Member Joined`, | ||
iconURL: member.user.avatarURL({ size: 256 }) | ||
? logData.Avatar | ||
: "https://files.femboy.kz/web/images/avatars/unknown.png", | ||
}); | ||
} else { | ||
embed.setAuthor({ | ||
name: `Member Joined`, | ||
iconURL: | ||
member.user.avatarURL({ size: 256 }) || | ||
"https://files.femboy.kz/web/images/avatars/unknown.png", | ||
}); | ||
} | ||
|
||
try { | ||
if (!logData && settingsData.Store === true) { | ||
await logs.create({ | ||
Guild: member.guild.id, | ||
User: member.user.id, | ||
Name: member.user.username, | ||
Nickname: member.nickname || member.user.username, | ||
Displayname: member.displayName, | ||
Avatar: member.user.displayAvatarURL({ size: 128 }), | ||
Banner: member.user.bannerURL({ size: 128 }) || null, | ||
Roles: member.roles.cache.map((role) => role.id) || [], | ||
Joined: member.joinedAt || date, | ||
Created: member.user.createdAt, | ||
}); | ||
} | ||
|
||
if (settingsData.Post === true) { | ||
if (!invite) { | ||
embed.addFields( | ||
{ | ||
name: "Inviter", | ||
value: "None", | ||
inline: false, | ||
}, | ||
{ | ||
name: "Invite", | ||
value: "Unknown / Vanity", | ||
inline: false, | ||
} | ||
); | ||
await channel.send({ embeds: [embed] }); | ||
} else { | ||
const inviter = await client.users.fetch(invite.inviter.id); | ||
embed.addFields( | ||
{ | ||
name: "Inviter", | ||
value: `${inviter}`, | ||
inline: false, | ||
}, | ||
{ | ||
name: "Invite", | ||
value: `<https://discord.gg/${invite.code}>`, | ||
inline: false, | ||
} | ||
); | ||
await channel.send({ embeds: [embed] }); | ||
} | ||
} | ||
} catch (error) { | ||
console.error("Error in guildMemberAdd event:", error); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const { EmbedBuilder, Events } = require("discord.js"); | ||
const schema = require("../Schemas/base-system.js"); | ||
const logs = require("../Schemas/logger/members.js"); | ||
const settings = require("../Schemas/logger/settings.js"); | ||
|
||
module.exports = { | ||
name: Events.GuildMemberRemove, | ||
async execute(member, client) { | ||
if (!member || !client) { | ||
return; | ||
} | ||
|
||
const settingsData = await settings.findOne({ | ||
Guild: member.guild.id, | ||
}); | ||
if (settingsData.Members === false) return; | ||
if (settingsData.Store === false && settingsData.Post === false) return; | ||
|
||
const data = await schema.findOne({ | ||
Guild: member.guild.id, | ||
ID: "audit-logs", | ||
}); | ||
if (!data || !data.Channel) return; | ||
const channel = client.channels.cache.get(data.Channel); | ||
if (!channel) return; | ||
|
||
const logData = await logs.findOne({ | ||
Guild: member.guild.id, | ||
User: member.user.id, | ||
}); | ||
|
||
const embed = new EmbedBuilder() | ||
.setColor("#ff00b3") | ||
.setTimestamp() | ||
.setFooter({ text: `FKZ • ID: ${member.user.id}` }) | ||
.setTitle(`${member.user.username} has left the server`) | ||
.setDescription(`<@${member.user.id}> has left the Server`); | ||
|
||
if (logData && logData.Avatar) { | ||
embed.setAuthor({ | ||
name: `Member Left`, | ||
iconURL: member.user.avatarURL({ size: 256 }) | ||
? logData.Avatar | ||
: "https://files.femboy.kz/web/images/avatars/unknown.png", | ||
}); | ||
} else { | ||
embed.setAuthor({ | ||
name: `Member Left`, | ||
iconURL: | ||
member.user.avatarURL({ size: 256 }) || | ||
"https://files.femboy.kz/web/images/avatars/unknown.png", | ||
}); | ||
} | ||
|
||
try { | ||
if (logData && settingsData.Store === true) { | ||
await logs.deleteMany({ | ||
Guild: member.guild.id, | ||
User: member.user.id, | ||
}); | ||
} | ||
if (settingsData.Post === true) { | ||
await channel.send({ embeds: [embed] }); | ||
} | ||
} catch (error) { | ||
console.error(`Error in guildMemberRemove event:`, error); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.