Skip to content

Commit

Permalink
update messageCreate, guildCreate and guildDelete to new handling method
Browse files Browse the repository at this point in the history
  • Loading branch information
jvnipers committed Jan 14, 2025
1 parent 3ca422e commit a45a451
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 120 deletions.
29 changes: 0 additions & 29 deletions src/anti-link.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/anti-spam.js

This file was deleted.

83 changes: 0 additions & 83 deletions src/bot-guilds.js

This file was deleted.

48 changes: 48 additions & 0 deletions src/events/guildCreate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { EmbedBuilder, Events } = require("discord.js");
const schema = require("../Schemas/base-system.js");

module.exports = {
name: Events.GuildCreate,
async execute(guild, client) {
const data = await schema.findOne({
Guild: guild.id,
ID: "audit-logs",
});

if (data) {
const channel = await client.channels.cache.get(data.Channel);
if (!data.Channel || !channel) return;
const owner = await client.users.cache.get(guild.ownerId);

const embed = new EmbedBuilder()
.setColor("Green")
.setTitle("FKZ Bot has joined a new server.")
.addFields([
{
name: "Server",
value: `> ${guild.name}`,
},
{
name: "Server Membercount",
value: `> ${guild.memberCount}`,
},
{
name: "Server Owner",
value: `> ${owner.username} / ${guild.ownerId}`,
},
{
name: "Server Age",
value: `> <t:${parseInt(guild.createdTimestamp / 1000)}:R>`,
},
])
.setTimestamp()
.setFooter({ text: `Guild Joined - ${guild.id}` });

try {
await channel.send({ embeds: [embed] });
} catch (error) {
console.error("Error in GuildCreate event:", error);
}
}
},
};
47 changes: 47 additions & 0 deletions src/events/guildDelete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { EmbedBuilder, Events } = require("discord.js");
const schema = require("../Schemas/base-system.js");

module.exports = {
name: Events.GuildDelete,
async execute(guild, client) {
const data = await schema.findOne({
Guild: guild.id,
ID: "audit-logs",
});

if (data) {
const channel = await client.channels.cache.get(data.Channel);
if (!data.Channel || !channel) return;
const owner = await client.users.cache.get(guild.ownerId);

const embed = new EmbedBuilder()
.setColor("Red")
.setTitle("FKZ Bot has left a server.")
.addFields([
{
name: "Server",
value: `> ${guild.name}`,
},
{
name: "Server Membercount",
value: `> ${guild.memberCount}`,
},
{
name: "Server Owner",
value: `> ${owner.username} / ${guild.ownerId}`,
},
{
name: "Server Age",
value: `> <t:${parseInt(guild.createdTimestamp / 1000)}:R>`,
},
])
.setTimestamp()
.setFooter({ text: `Guild Left - ${guild.id}` });
try {
await channel.send({ embeds: [embed] });
} catch (error) {
console.error("Error in GuildDelete event:", error);
}
}
},
};
49 changes: 49 additions & 0 deletions src/events/messageCreate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { Events } = require("discord.js");
//const schema = require("../Schemas/base-system.js");
//const settings = require("../Schemas/logger/settings.js");
const antiLink = require("../Schemas/moderation/anti-link.js");
//const schema = require("../Schemas/moderation/anti-spam.js");

module.exports = {
name: Events.MessageCreate,
async execute(message, client) {
if (
!message ||
!message.guild ||
!message.author ||
message.system ||
message.webhookId ||
!client
) {
return;
}

const antiLinkData = await antiLink.findOne({
Guild: message.guild.id,
});
if (antiLinkData) {
if (
message.content.includes("http") ||
message.content.includes("https") ||
message.content.includes("gg/")
) {
try {
const member = await message.guild.members.cache.get(
message.author.id
);
if (member && member.permissions.has(data.Perms)) {
return;
} else if (member) {
const msg = await message.channel.send(
`${message.author}, you can't send links here!`
);
setTimeout(() => msg.delete(), 3000);
await message.delete();
}
} catch (error) {
console.error(`Error in messageCreate event:\n${error}`);
}
}
}
},
};
3 changes: 0 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ client.on("disconnect", () => {
);
});

require("./anti-link.js");
require("./anti-spam.js");
require("./auto-roles.js");
require("./bot-guilds.js");
require("./guild-scraper.js");
require("./reaction-roles.js");
require("./whitelist-response.js");
Expand Down

0 comments on commit a45a451

Please sign in to comment.