diff --git a/source/events/channel/channelCreate.js b/source/events/channel/channelCreate.js deleted file mode 100644 index f28a5001..00000000 --- a/source/events/channel/channelCreate.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, channel) => { - if (client.mode === "start") { - settingsData(client, channel.guild, module.exports, channel); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), channel.guild.id); - const channelRef = child(guildRef, "notification/channelCreate"); - const channelSnapshot = client.api.guilds[channel.guild.id].notification.channelCreate; - - if (typeof channelSnapshot === "boolean") { - const notification = channel.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const channelCreateEmbed = new EmbedBuilder() - .setTitle(client.translate.events.channelCreate.channel_notification) - .setDescription(client.translate.events.channelCreate.member_create_channel.replace("%s", channel.id)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [channelCreateEmbed] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, channel)); - } -}; \ No newline at end of file diff --git a/source/events/channel/channelDelete.js b/source/events/channel/channelDelete.js deleted file mode 100644 index 33785617..00000000 --- a/source/events/channel/channelDelete.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, channel) => { - if (client.mode === "start") { - settingsData(client, channel.guild, module.exports, channel); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), channel.guild.id); - const channelRef = child(guildRef, "notification/channelDelete"); - const channelSnapshot = client.api.guilds[channel.guild.id].notification.channelDelete; - - if (typeof channelSnapshot === "boolean") { - const notification = channel.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const channelDeleteEmbed = new EmbedBuilder() - .setTitle(client.translate.events.channelDelete.channel_notification) - .setDescription(client.translate.events.channelDelete.member_delete_channel.replace("%s", channel.name)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [channelDeleteEmbed] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, channel)); - } -}; \ No newline at end of file diff --git a/source/events/channel/channelPinsUpdate.js b/source/events/channel/channelPinsUpdate.js deleted file mode 100644 index 898abd6d..00000000 --- a/source/events/channel/channelPinsUpdate.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, channel, time) => { - if (client.mode === "start") { - settingsData(client, channel.guild, module.exports, (channel, time)); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), channel.guild.id); - const channelRef = child(guildRef, "notification/channelPinsUpdate"); - const channelSnapshot = client.api.guilds[channel.guild.id].notification.channelPinsUpdate; - - if (typeof channelSnapshot === "boolean") { - const notification = channel.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const channelPiusUpdateEmbed = new EmbedBuilder() - .setTitle(client.translate.events.channelPinsUpdate.channel_notification) - .setDescription(client.translate.events.channelPinsUpdate.member_pins_in_channel.replace("%s1", channel.id).replace("%s2", time)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [channelPiusUpdateEmbed] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, channel, time)); - } -}; \ No newline at end of file diff --git a/source/events/channel/channelUpdate.js b/source/events/channel/channelUpdate.js deleted file mode 100644 index 966dd76d..00000000 --- a/source/events/channel/channelUpdate.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, oldChannel, newChannel) => { - if (client.mode === "start") { - settingsData(client, newChannel.guild, module.exports, (oldChannel, newChannel)); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newChannel.guild.id); - const channelRef = child(guildRef, "notification/channelUpdate"); - const channelSnapshot = client.api.guilds[newChannel.guild.id].notification.channelUpdate; - - if (typeof channelSnapshot === "boolean") { - const notification = newChannel.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const channelUpdate = new EmbedBuilder() - .setTitle(client.translate.events.channelUpdate.channel_notification) - .setDescription(client.translate.events.channelUpdate.member_update_channel.replace("%s1", oldChannel.name).replace("%s2", newChannel.id)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [channelUpdate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, oldChannel, newChannel)); - } -}; \ No newline at end of file diff --git a/source/events/channelCreate.js b/source/events/channelCreate.js new file mode 100644 index 00000000..1691e023 --- /dev/null +++ b/source/events/channelCreate.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.ChannelCreate, + "once": false, + execute(channel) { + if (channel.client.mode === "start") { + settingsData(channel.client, channel.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), channel.guild.id); + const channelRef = child(guildRef, "notification/channelCreate"); + const channelSnapshot = channel.client.api.guilds[channel.guild.id].notification.channelCreate; + + if (typeof channelSnapshot === "boolean") { + const notification = channel.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const channelCreateEmbed = new EmbedBuilder() + .setTitle(channel.client.translate.events.channelCreate.channel_notification) + .setDescription(channel.client.translate.events.channelCreate.member_create_channel.replace("%s", channel.id)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [channelCreateEmbed] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(channel)); + } + } +}; \ No newline at end of file diff --git a/source/events/channelDelete.js b/source/events/channelDelete.js new file mode 100644 index 00000000..1229329d --- /dev/null +++ b/source/events/channelDelete.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.ChannelDelete, + "once": false, + execute(channel) { + if (channel.client.mode === "start") { + settingsData(channel.client, channel.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), channel.guild.id); + const channelRef = child(guildRef, "notification/channelDelete"); + const channelSnapshot = channel.client.api.guilds[channel.guild.id].notification.channelDelete; + + if (typeof channelSnapshot === "boolean") { + const notification = channel.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const channelDeleteEmbed = new EmbedBuilder() + .setTitle(channel.client.translate.events.channelDelete.channel_notification) + .setDescription(channel.client.translate.events.channelDelete.member_delete_channel.replace("%s", channel.name)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [channelDeleteEmbed] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(channel)); + } + } +}; \ No newline at end of file diff --git a/source/events/channelPinsUpdate.js b/source/events/channelPinsUpdate.js new file mode 100644 index 00000000..9fd0467a --- /dev/null +++ b/source/events/channelPinsUpdate.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.ChannelPinsUpdate, + "once": false, + execute(channel, time) { + if (channel.client.mode === "start") { + settingsData(channel.client, channel.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), channel.guild.id); + const channelRef = child(guildRef, "notification/channelPinsUpdate"); + const channelSnapshot = channel.client.api.guilds[channel.guild.id].notification.channelPinsUpdate; + + if (typeof channelSnapshot === "boolean") { + const notification = channel.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const channelPiusUpdateEmbed = new EmbedBuilder() + .setTitle(channel.client.translate.events.channelPinsUpdate.channel_notification) + .setDescription(channel.client.translate.events.channelPinsUpdate.member_pins_in_channel.replace("%s1", channel.id).replace("%s2", time)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [channelPiusUpdateEmbed] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(channel, time)); + } + } +}; \ No newline at end of file diff --git a/source/events/channelUpdate.js b/source/events/channelUpdate.js new file mode 100644 index 00000000..ee65bbcd --- /dev/null +++ b/source/events/channelUpdate.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.ChannelUpdate, + "once": false, + execute(oldChannel, newChannel) { + if (newChannel.client.mode === "start") { + settingsData(newChannel.client, newChannel.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newChannel.guild.id); + const channelRef = child(guildRef, "notification/channelUpdate"); + const channelSnapshot = newChannel.client.api.guilds[newChannel.guild.id].notification.channelUpdate; + + if (typeof channelSnapshot === "boolean") { + const notification = newChannel.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const channelUpdate = new EmbedBuilder() + .setTitle(newChannel.client.translate.events.channelUpdate.channel_notification) + .setDescription(newChannel.client.translate.events.channelUpdate.member_update_channel.replace("%s1", oldChannel.name).replace("%s2", newChannel.id)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [channelUpdate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(oldChannel, newChannel)); + } + } +}; \ No newline at end of file diff --git a/source/events/client/debug.js b/source/events/client/debug.js deleted file mode 100644 index 5af41c88..00000000 --- a/source/events/client/debug.js +++ /dev/null @@ -1,5 +0,0 @@ -const { logGenerator } = require("../../utils/consoleUtils"); - -module.exports = (client, info) => { - logGenerator("debug", info); -}; \ No newline at end of file diff --git a/source/events/client/error.js b/source/events/client/error.js deleted file mode 100644 index 6df9bab3..00000000 --- a/source/events/client/error.js +++ /dev/null @@ -1,5 +0,0 @@ -const { logGenerator } = require("../../utils/consoleUtils"); - -module.exports = (client, error) => { - logGenerator("error", error); -}; \ No newline at end of file diff --git a/source/events/client/ready.js b/source/events/client/ready.js deleted file mode 100644 index b9da0e4b..00000000 --- a/source/events/client/ready.js +++ /dev/null @@ -1,191 +0,0 @@ -const { ActivityType } = require("discord.js"); -const { readdirSync } = require("node:fs"); -const { getApps } = require("firebase/app"); -const { getFirestore, doc, setDoc } = require("firebase/firestore"); -const { getDatabase, get, onValue, ref, update } = require("firebase/database"); -const { checkForUpdates, updateApplicationCommands } = require("../../utils/clientUtils"); - -module.exports = async (client) => { - // Notify when the bot is online. - const date = client.readyAt; - const year = date.getFullYear(); - const month = date.getMonth(); - const day = date.getDate(); - const hour = date.getHours(); - const minute = date.getMinutes(); - const at = year + "-" + month + "-" + day + "." + hour + ":" + minute; - - client.console.add("online-loading", { - "text": "Bot is working and is now online at " + at + ".", - "status": "non-spinnable" - }); - - // Check server is set up. - if (!getApps.length) { - client.console.add("server-check-loading", { - "text": "Connected to the server successfully.", - "status": "non-spinnable" - }); - } else { - client.console.add("server-check-loading", { - "text": "Unable to connect to the provider server.", - "status": "non-spinnable" - }); - } - - // Organize data from a database. - const data = await get(ref(getDatabase(), "projects/shioru")); - const statistics = await get(ref(getDatabase(), "statistics/shioru")); - - if (data.exists()) client.api = data.val(); - if (statistics.exists()) client.api.statistics = statistics.val(); - - onValue(ref(getDatabase(), "projects/shioru"), (snapshot) => { - if (snapshot.exists()) client.api = snapshot.val(); - }); - onValue(ref(getDatabase(), "statistics/shioru"), (snapshot) => { - if (snapshot.exists()) client.api.statistics = snapshot.val(); - }); - - // Send bot statistics. - setInterval(() => { - const commandSize = client.commands.size; - const guildSize = client.guilds.cache.size; - const userSize = client.users.cache.size; - - const prevGuildSize = client.api.statistics ? client.api.statistics.size.guilds : guildSize; - const prevUserSize = client.api.statistics ? client.api.statistics.size.users : userSize; - - if (client.mode === "start") { - if (guildSize !== prevGuildSize || userSize !== prevUserSize) { - update(ref(getDatabase(), "statistics/shioru/size"), { - "commands": commandSize, - "guilds": guildSize, - "users": userSize - }); - } - } - }, 5000); - - // Send commands information - try { - const categories = readdirSync("./source/commands/"); - - categories.forEach((category) => { - const directory = client.commands.filter(dirs => dirs.category.toLowerCase() === category.toLowerCase()); - const categorize = category.slice(0, 1).toUpperCase() + category.slice(1); - - if (!directory.size) return; - - directory.map(pull => { - setDoc(doc(getFirestore(), "Information", "shioru"), { - "commands": { - [categorize]: { - [pull.name]: { - "name": pull.name || "", - "description": { - "en-US": pull.function.command.data.description_localizations ? pull.function.command.data.description_localizations["en-US"] : "", - "th": pull.function.command.data.description_localizations ? pull.function.command.data.description_localizations["th"] : "" - }, - "category": pull.category || "", - "permissions": { - "client": pull.permissions.client ? pull.permissions.client.map(String) : [], - "user": pull.permissions.user ? pull.permissions.user.map(String) : [] - }, - "usage": pull.usage || "", - "function": { - "command": pull.function.command ? true : false, - "context": pull.function.context ? true : false - } - } - } - } - }, { - "merge": true - }); - }) - }); - } catch (error) { - console.log(error) - } - - // Setup bot activity. - const commandSize = client.commands.size; - const guildSize = client.guilds.cache.size; - const userSize = client.users.cache.size; - const activities = { - "production": [ - { - "name": guildSize + " Server" + (guildSize === 1 ? "" : "s"), - "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", - "type": ActivityType.Streaming - }, - { - "name": "/help", - "type": ActivityType.Watching - }, - { - "name": userSize + " Member" + (userSize === 1 ? "" : "s"), - "type": ActivityType.Watching - }, - { - "name": commandSize + " Command" + (commandSize === 1 ? "" : "s"), - "type": ActivityType.Listening - } - ], - "development": [ - { - "name": "🧶", - "type": ActivityType.Playing - }, - { - "name": "/", - "type": ActivityType.Listening - }, - { - "name": "📦", - "type": ActivityType.Playing - } - ] - }; - const activityType = client.mode === "start" ? activities.production : activities.development; - - client.user.setPresence({ - "status": "available", - "afk": false, - "activities": activityType - }); - - setInterval(() => { - const guildSize = client.guilds.cache.size; - const userSize = client.users.cache.size; - const randomIndex = Math.floor(Math.random() * activityType.length); - const newActivity = activityType[randomIndex]; - - activities.production[0].name = guildSize + " Server" + (guildSize === 1 ? "" : "s"); - activities.production[2].name = userSize + " Member" + (userSize === 1 ? "" : "s"); - client.user.setActivity(newActivity); - }, 10000); - - // Check for update - await checkForUpdates(client); - - // Refreshing application (/) commands. - await updateApplicationCommands(client); - - // Client username - client.console.add("username-check-loading", { - "text": "Sign in with the username " + client.user.username + ".", - "status": "non-spinnable" - }); - - // If everything is ready to go - const endTime = new Date().getTime(); - - client.startup.end = endTime; - client.console.add("startup-loading", { - "color": "blueBright", - "text": "Bot is ready to work on the servers!: " + ((client.startup.end - client.startup.start) / 1000) + "s", - "status": "non-spinnable" - }); -}; diff --git a/source/events/client/warn.js b/source/events/client/warn.js deleted file mode 100644 index dc4a0741..00000000 --- a/source/events/client/warn.js +++ /dev/null @@ -1,5 +0,0 @@ -const { logGenerator } = require("../../utils/consoleUtils"); - -module.exports = (client, info) => { - logGenerator("warn", info); -}; \ No newline at end of file diff --git a/source/events/debug.js b/source/events/debug.js new file mode 100644 index 00000000..1738a502 --- /dev/null +++ b/source/events/debug.js @@ -0,0 +1,10 @@ +const { Events } = require("discord.js"); +const { logGenerator } = require("../utils/consoleUtils"); + +module.exports = { + "name": Events.Debug, + "once": false, + execute(info) { + logGenerator("debug", info); + } +}; \ No newline at end of file diff --git a/source/events/emoji/emojiCreate.js b/source/events/emoji/emojiCreate.js deleted file mode 100644 index f06d4548..00000000 --- a/source/events/emoji/emojiCreate.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, emoji) => { - if (client.mode === "start") { - settingsData(client, emoji.guild, module.exports, emoji); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), emoji.guild.id); - const channelRef = child(guildRef, "notification/emojiCreate"); - const channelSnapshot = client.api.guilds[emoji.guild.id].notification.emojiCreate; - - if (typeof channelSnapshot === "boolean") { - const notification = emoji.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const emojiCreateEmbed = new EmbedBuilder() - .setTitle(client.translate.events.emojiCreate.emoji_notification) - .setDescription(client.translate.events.emojiCreate.member_create_emoji.replace("%s", emoji.name)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [emojiCreateEmbed] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, emoji)); - } -}; \ No newline at end of file diff --git a/source/events/emoji/emojiDelete.js b/source/events/emoji/emojiDelete.js deleted file mode 100644 index d0600b9c..00000000 --- a/source/events/emoji/emojiDelete.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, emoji) => { - if (client.mode === "start") { - settingsData(client, emoji.guild, module.exports, emoji); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), emoji.guild.id); - const channelRef = child(guildRef, "notification/emojiDelete"); - const channelSnapshot = client.api.guilds[emoji.guild.id].notification.emojiDelete; - - if (typeof channelSnapshot === "boolean") { - const notification = emoji.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const emojiDeleteEmbed = new EmbedBuilder() - .setTitle(client.translate.events.emojiDelete.emoji_notification) - .setDescription(client.translate.events.emojiDelete.member_delete_emoji.replace("%s", emoji.name)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [emojiDeleteEmbed] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, emoji)); - } -}; \ No newline at end of file diff --git a/source/events/emoji/emojiUpdate.js b/source/events/emoji/emojiUpdate.js deleted file mode 100644 index c33ac841..00000000 --- a/source/events/emoji/emojiUpdate.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, oldEmoji, newEmoji) => { - if (client.mode === "start") { - settingsData(client, newEmoji.guild, module.exports, (oldEmoji, newEmoji)); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newEmoji.guild.id); - const channelRef = child(guildRef, "notification/emojiUpdate"); - const channelSnapshot = client.api.guilds[newEmoji.guild.id].notification.emojiUpdate; - - if (typeof channelSnapshot === "boolean") { - const notification = newEmoji.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const emojiUpdateEmbed = new EmbedBuilder() - .setTitle(client.translate.events.emojiUpdate.emoji_notification) - .setDescription(client.translate.events.emojiUpdate.member_update_emoji.replace("%s1", oldEmoji.name).replace("%s2", newEmoji.name)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [emojiUpdateEmbed] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, oldEmoji, newEmoji)); - } -}; \ No newline at end of file diff --git a/source/events/emojiCreate.js b/source/events/emojiCreate.js new file mode 100644 index 00000000..99d249b9 --- /dev/null +++ b/source/events/emojiCreate.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildEmojiCreate, + "once": false, + execute(emoji) { + if (emoji.client.mode === "start") { + settingsData(emoji.client, emoji.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), emoji.guild.id); + const channelRef = child(guildRef, "notification/emojiCreate"); + const channelSnapshot = emoji.client.api.guilds[emoji.guild.id].notification.emojiCreate; + + if (typeof channelSnapshot === "boolean") { + const notification = emoji.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const emojiCreateEmbed = new EmbedBuilder() + .setTitle(emoji.client.translate.events.emojiCreate.emoji_notification) + .setDescription(emoji.client.translate.events.emojiCreate.member_create_emoji.replace("%s", emoji.name)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [emojiCreateEmbed] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(emoji)); + } + } +}; \ No newline at end of file diff --git a/source/events/emojiDelete.js b/source/events/emojiDelete.js new file mode 100644 index 00000000..8530d8e9 --- /dev/null +++ b/source/events/emojiDelete.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildEmojiDelete, + "once": false, + execute(emoji) { + if (emoji.client.mode === "start") { + settingsData(emoji.client, emoji.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), emoji.guild.id); + const channelRef = child(guildRef, "notification/emojiDelete"); + const channelSnapshot = emoji.client.api.guilds[emoji.guild.id].notification.emojiDelete; + + if (typeof channelSnapshot === "boolean") { + const notification = emoji.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const emojiDeleteEmbed = new EmbedBuilder() + .setTitle(emoji.client.translate.events.emojiDelete.emoji_notification) + .setDescription(emoji.client.translate.events.emojiDelete.member_delete_emoji.replace("%s", emoji.name)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [emojiDeleteEmbed] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(emoji)); + } + } +}; \ No newline at end of file diff --git a/source/events/emojiUpdate.js b/source/events/emojiUpdate.js new file mode 100644 index 00000000..96719c52 --- /dev/null +++ b/source/events/emojiUpdate.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildEmojiUpdate, + "once": false, + execute(oldEmoji, newEmoji) { + if (newEmoji.client.mode === "start") { + settingsData(newEmoji.client, newEmoji.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newEmoji.guild.id); + const channelRef = child(guildRef, "notification/emojiUpdate"); + const channelSnapshot = newEmoji.client.api.guilds[newEmoji.guild.id].notification.emojiUpdate; + + if (typeof channelSnapshot === "boolean") { + const notification = newEmoji.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const emojiUpdateEmbed = new EmbedBuilder() + .setTitle(newEmoji.client.translate.events.emojiUpdate.emoji_notification) + .setDescription(newEmoji.client.translate.events.emojiUpdate.member_update_emoji.replace("%s1", oldEmoji.name).replace("%s2", newEmoji.name)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [emojiUpdateEmbed] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(oldEmoji, newEmoji)); + } + } +}; \ No newline at end of file diff --git a/source/events/error.js b/source/events/error.js new file mode 100644 index 00000000..de81a4c1 --- /dev/null +++ b/source/events/error.js @@ -0,0 +1,11 @@ +const { Events } = require("discord.js"); +const { logGenerator } = require("../utils/consoleUtils"); + +module.exports = { + "name": Events.Error, + "once": false, + execute(error) { + logGenerator("error", error); + console.log(error); + } +}; \ No newline at end of file diff --git a/source/events/guild/guildBanAdd.js b/source/events/guild/guildBanAdd.js deleted file mode 100644 index c0a4931d..00000000 --- a/source/events/guild/guildBanAdd.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, ban) => { - if (client.mode === "start") { - settingsData(client, ban.guild, module.exports, ban); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), ban.guild.id); - const channelRef = child(guildRef, "notification/guildBanAdd"); - const channelSnapshot = client.api.guilds[ban.guild.id].notification.guildBanAdd; - - if (typeof channelSnapshot === "boolean") { - const notification = ban.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const guildBanAddEmbed = new EmbedBuilder() - .setTitle(client.translate.events.guildBanAdd.guild_notification) - .setDescription(client.translate.events.guildBanAdd.member_ban_add.replace("%s1", ban.user.id).replace("%s2", ban.reason)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [guildBanAddEmbed] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, ban)); - } -}; \ No newline at end of file diff --git a/source/events/guild/guildBanRemove.js b/source/events/guild/guildBanRemove.js deleted file mode 100644 index e9c7b17e..00000000 --- a/source/events/guild/guildBanRemove.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, ban) => { - if (client.mode === "start") { - settingsData(client, ban.guild, module.exports, ban); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), ban.guild.id); - const channelRef = child(guildRef, "notification/guildBanRemove"); - const channelSnapshot = client.api.guilds[ban.guild.id].notification.guildBanRemove; - - if (typeof channelSnapshot === "boolean") { - const notification = ban.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const guildBanRemoveEmbed = new EmbedBuilder() - .setTitle(client.translate.events.guildBanRemove.guild_notification) - .setDescription(client.translate.events.guildBanRemove.member_ban_remove.replace("%s1", ban.user.id).replace("%s2", ban.reason)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [guildBanRemoveEmbed] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, ban)); - } -}; \ No newline at end of file diff --git a/source/events/guild/guildCreate.js b/source/events/guild/guildCreate.js deleted file mode 100644 index 25ce1cc4..00000000 --- a/source/events/guild/guildCreate.js +++ /dev/null @@ -1,67 +0,0 @@ -const { EmbedBuilder, AttachmentBuilder, ChannelType } = require("discord.js"); -const { getDatabase, ref, update } = require("firebase/database"); -const { updateApplicationCommands } = require("../../utils/clientUtils") -const { settingsData } = require("../../utils/databaseUtils"); -const { catchError } = require("../../utils/consoleUtils"); - -module.exports = async (client, guild) => { - if (client.mode === "start") { - const guildSize = client.guilds.cache.size; - const userSize = client.users.cache.size; - - update(ref(getDatabase(), "statistics/shioru/size"), { - "guilds": guildSize, - "users": userSize - }); - - settingsData(client, guild, module.exports, guild); - - if (client.temp.set !== 1) return; - } - - await updateApplicationCommands(client, true) - - const channels = guild.channels.cache.find(channel => channel.type === ChannelType.GuildText && channel.permissionsFor(guild.members.me).has("SEND_MESSAGES")); - const guildChannel = guild.channels.cache.get(channels ? channels.id : guild.systemChannelId); - - if (guildChannel) { - const guildName = guild.name; - const clientFetch = await client.user.fetch(); - const clientColor = clientFetch.accentColor; - const clientAvatar = client.user.displayAvatarURL(); - const clientUsername = client.user.username; - const languageCode = client.config.language.code; - const attachment = new AttachmentBuilder("./source/assets/images/shioru-discord-cover-" + languageCode + ".png", { "name": "shioru-discord-cover.png" }); - const guildCreateEmbed = new EmbedBuilder() - .setTitle(client.translate.events.guildCreate.get_started) - .setDescription(client.translate.events.guildCreate.description.replace("%s", guildName)) - .setColor(clientColor) - .setTimestamp() - .setFooter({ "text": client.translate.events.guildCreate.join_on, "iconURL": "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/microsoft/209/spiral-calendar-pad_1f5d3.png" }) - .setImage("attachment://shioru-discord-cover.png") - .setAuthor({ "iconURL": clientAvatar, "name": clientUsername, "url": "https://shiorus.web.app/" }) - .addFields( - [ - { - "name": client.translate.events.guildCreate.advice, - "value": client.translate.events.guildCreate.advice_detail - }, - { - "name": client.translate.events.guildCreate.support_multiple_languages, - "value": client.translate.events.guildCreate.support_multiple_languages_detail - }, - { - "name": client.translate.events.guildCreate.help_information_and_documentation, - "value": client.translate.events.guildCreate.help_information_and_documentation_detail - } - ] - ); - - guildChannel.send({ - "embeds": [guildCreateEmbed], - "files": [attachment] - }).catch((error) => { - catchError(client, guild.systemChannel, "guildCreate", error); - }); - } -}; \ No newline at end of file diff --git a/source/events/guild/guildDelete.js b/source/events/guild/guildDelete.js deleted file mode 100644 index ee83e92c..00000000 --- a/source/events/guild/guildDelete.js +++ /dev/null @@ -1,13 +0,0 @@ -const { getDatabase, ref, update } = require("firebase/database"); - -module.exports = (client, guild) => { - if (client.mode === "start") { - const guildSize = client.guilds.cache.size; - const userSize = client.users.cache.size; - - update(ref(getDatabase(), "statistics/shioru/size"), { - "guilds": guildSize, - "users": userSize - }); - } -}; \ No newline at end of file diff --git a/source/events/guild/guildIntegrationsUpdate.js b/source/events/guild/guildIntegrationsUpdate.js deleted file mode 100644 index 4b5a44ab..00000000 --- a/source/events/guild/guildIntegrationsUpdate.js +++ /dev/null @@ -1,30 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, guild) => { - if (client.mode === "start") { - settingsData(client, guild, module.exports, guild); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), guild.id); - const channelRef = child(guildRef, "notification/guildIntegrationsUpdate"); - const channelSnapshot = client.api.guilds[guild.id].notification.guildIntegrationsUpdate; - - if (typeof channelSnapshot === "boolean") { - const notification = guild.channels.cache.find(channels => channels.id === channelSnapshot); - const guildIntegrationsUpdate = new EmbedBuilder() - .setTitle(client.translate.events.guildIntegrationsUpdate.guild_notification) - .setDescription(client.translate.events.guildIntegrationsUpdate.guild_integrations_update.replace("%s", guild.name)) - .setImage(guild.bannerURL()) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [guildIntegrationsUpdate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, guild)); - } -}; \ No newline at end of file diff --git a/source/events/guild/guildMemberAdd.js b/source/events/guild/guildMemberAdd.js deleted file mode 100644 index 0c33113e..00000000 --- a/source/events/guild/guildMemberAdd.js +++ /dev/null @@ -1,36 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = async (client, member) => { - if (member.user.bot) return; - if (client.mode === "start") { - settingsData(client, member.guild, module.exports, member); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), member.guild.id); - const channelRef = child(guildRef, "notification/guildMemberAdd"); - const channelSnapshot = client.api.guilds[member.guild.id].notification.guildMemberAdd; - - if (typeof channelSnapshot === "boolean") { - const notification = member.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const memberFetch = await member.user.fetch(); - const memberColor = memberFetch.accentColor; - const memberTag = member.user.tag; - const memberAvatar = member.user.displayAvatarURL(); - const guildMemberAddEmbed = new EmbedBuilder() - .setTitle(memberTag) - .setDescription(client.translate.events.guildMemberAdd.greet) - .setTimestamp() - .setColor(memberColor) - .setThumbnail(memberAvatar) - .setAuthor({ "icon_url": "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/microsoft/209/video-game_1f3ae.png", "name": client.translate.events.guildMemberAdd.welcome }); - - if (!notification) return; - - notification.send({ "embeds": [guildMemberAddEmbed] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, member)); - } -}; \ No newline at end of file diff --git a/source/events/guild/guildMemberRemove.js b/source/events/guild/guildMemberRemove.js deleted file mode 100644 index 9abcfd3b..00000000 --- a/source/events/guild/guildMemberRemove.js +++ /dev/null @@ -1,35 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = async (client, member) => { - if (member.user.bot) return; - if (client.mode === "start") { - settingsData(client, member.guild, module.exports, member); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), member.guild.id); - const channelRef = child(guildRef, "notification/guildMemberRemove"); - const channelSnapshot = client.api.guilds[member.guild.id].notification.guildMemberRemove; - - if (typeof channelSnapshot === "boolean") { - const notification = member.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const memberFetch = await member.user.fetch(); - const memberColor = memberFetch.accentColor; - const memberTag = member.user.tag; - const memberAvatar = member.user.displayAvatarURL(); - const guildMemberRemoveEmbed = new EmbedBuilder() - .setTitle(memberTag) - .setDescription(client.translate.events.guildMemberRemove.user_has_exited) - .setTimestamp() - .setColor(memberColor) - .setThumbnail(memberAvatar); - - if (!notification) return; - - notification.send({ "embeds": [guildMemberRemoveEmbed] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, member)); - } -}; \ No newline at end of file diff --git a/source/events/guild/guildMembersChunk.js b/source/events/guild/guildMembersChunk.js deleted file mode 100644 index 864fcfb2..00000000 --- a/source/events/guild/guildMembersChunk.js +++ /dev/null @@ -1,30 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, members, guild, chunk) => { - if (client.mode === "start") { - settingsData(client, guild, module.exports, (members, guild, chunk)); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), guild.id); - const channelRef = child(guildRef, "notification/guildMembersChunk"); - const channelSnapshot = client.api.guilds[guild.id].notification.guildMembersChunk; - - if (typeof channelSnapshot === "boolean") { - const notification = guild.channels.cache.find(channels => channels.id === channelSnapshot); - const guildMembersChunk = new EmbedBuilder() - .setTitle(client.translate.events.guildMembersChunk.guild_notification) - .setDescription(client.translate.events.guildMembersChunk.guild_members_chunk.replace("%s", guild.name)) - .setImage(guild.bannerURL()) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [guildMembersChunk] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, members, guild, chunk)); - } -}; \ No newline at end of file diff --git a/source/events/guild/guildUnavailable.js b/source/events/guild/guildUnavailable.js deleted file mode 100644 index 5fd34456..00000000 --- a/source/events/guild/guildUnavailable.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, guild) => { - if (client.mode === "start") { - settingsData(client, guild, module.exports, guild); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), guild.id); - const channelRef = child(guildRef, "notification/guildUnavailable"); - const channelSnapshot = client.api.guilds[guild.id].notification.guildUnavailable; - - if (typeof channelSnapshot === "boolean") { - const notification = guild.channels.cache.find(channels => channels.id === channelSnapshot); - const guildUnavailable = new EmbedBuilder() - .setTitle(client.translate.events.guildUnavailable.guild_notification) - .setDescription(client.translate.events.guildMembersChunk.guild_unavailable) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [guildUnavailable] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, guild)); - } -}; \ No newline at end of file diff --git a/source/events/guildBanAdd.js b/source/events/guildBanAdd.js new file mode 100644 index 00000000..f8b4a3b6 --- /dev/null +++ b/source/events/guildBanAdd.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildBanAdd, + "once": false, + execute(ban) { + if (ban.client.mode === "start") { + settingsData(ban.client, ban.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), ban.guild.id); + const channelRef = child(guildRef, "notification/guildBanAdd"); + const channelSnapshot = ban.client.api.guilds[ban.guild.id].notification.guildBanAdd; + + if (typeof channelSnapshot === "boolean") { + const notification = ban.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const guildBanAddEmbed = new EmbedBuilder() + .setTitle(ban.client.translate.events.guildBanAdd.guild_notification) + .setDescription(ban.client.translate.events.guildBanAdd.member_ban_add.replace("%s1", ban.user.id).replace("%s2", ban.reason)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [guildBanAddEmbed] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(ban)); + } + } +}; \ No newline at end of file diff --git a/source/events/guildBanRemove.js b/source/events/guildBanRemove.js new file mode 100644 index 00000000..c98a319c --- /dev/null +++ b/source/events/guildBanRemove.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildBanRemove, + "once": false, + execute(ban) { + if (ban.client.mode === "start") { + settingsData(ban.client, ban.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), ban.guild.id); + const channelRef = child(guildRef, "notification/guildBanRemove"); + const channelSnapshot = ban.client.api.guilds[ban.guild.id].notification.guildBanRemove; + + if (typeof channelSnapshot === "boolean") { + const notification = ban.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const guildBanRemoveEmbed = new EmbedBuilder() + .setTitle(ban.client.translate.events.guildBanRemove.guild_notification) + .setDescription(ban.client.translate.events.guildBanRemove.member_ban_remove.replace("%s1", ban.user.id).replace("%s2", ban.reason)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [guildBanRemoveEmbed] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(ban)); + } + } +}; \ No newline at end of file diff --git a/source/events/guildCreate.js b/source/events/guildCreate.js new file mode 100644 index 00000000..b3a71f18 --- /dev/null +++ b/source/events/guildCreate.js @@ -0,0 +1,69 @@ +const { Events, PermissionsBitField, EmbedBuilder, AttachmentBuilder, ChannelType } = require("discord.js"); +const { getDatabase, ref, update } = require("firebase/database"); +const { updateApplicationCommands } = require("../utils/clientUtils") +const { settingsData } = require("../utils/databaseUtils"); +const { catchError } = require("../utils/consoleUtils"); + +module.exports = { + "name": Events.GuildCreate, + "once": false, + async execute(guild) { + if (guild.client.mode === "start") { + const guildSize = guild.client.guilds.cache.size; + const userSize = guild.client.users.cache.size; + + update(ref(getDatabase(), "statistics/shioru/size"), { + "guilds": guildSize, + "users": userSize + }); + + settingsData(guild.client, guild); + } + + await updateApplicationCommands(guild.client, true) + + const channels = guild.channels.cache.find(channel => channel.type === ChannelType.GuildText && channel.permissionsFor(guild.members.me).has(PermissionsBitField.Flags.SendMessages)); + const guildChannel = guild.channels.cache.get(channels ? channels.id : guild.systemChannelId); + + if (guildChannel) { + const guildName = guild.name; + const clientFetch = await guild.client.user.fetch(); + const clientColor = clientFetch.accentColor; + const clientAvatar = guild.client.user.displayAvatarURL(); + const clientUsername = guild.client.user.username; + const languageCode = guild.client.config.language.code; + const attachment = new AttachmentBuilder("./source/assets/images/shioru-discord-cover-" + languageCode + ".png", { "name": "shioru-discord-cover.png" }); + const guildCreateEmbed = new EmbedBuilder() + .setTitle(guild.client.translate.events.guildCreate.get_started) + .setDescription(guild.client.translate.events.guildCreate.description.replace("%s", guildName)) + .setColor(clientColor) + .setTimestamp() + .setFooter({ "text": guild.client.translate.events.guildCreate.join_on, "iconURL": "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/microsoft/209/spiral-calendar-pad_1f5d3.png" }) + .setImage("attachment://shioru-discord-cover.png") + .setAuthor({ "iconURL": clientAvatar, "name": clientUsername, "url": "https://shiorus.web.app/" }) + .addFields( + [ + { + "name": guild.client.translate.events.guildCreate.advice, + "value": guild.client.translate.events.guildCreate.advice_detail + }, + { + "name": guild.client.translate.events.guildCreate.support_multiple_languages, + "value": guild.client.translate.events.guildCreate.support_multiple_languages_detail + }, + { + "name": guild.client.translate.events.guildCreate.help_information_and_documentation, + "value": guild.client.translate.events.guildCreate.help_information_and_documentation_detail + } + ] + ); + + guildChannel.send({ + "embeds": [guildCreateEmbed], + "files": [attachment] + }).catch((error) => { + catchError(guild.client, guild.systemChannel, "guildCreate", error); + }); + } + } +}; \ No newline at end of file diff --git a/source/events/guildDelete.js b/source/events/guildDelete.js new file mode 100644 index 00000000..937709eb --- /dev/null +++ b/source/events/guildDelete.js @@ -0,0 +1,18 @@ +const { Events } = require("discord.js"); +const { getDatabase, ref, update } = require("firebase/database"); + +module.exports = { + "name": Events.GuildDelete, + "once": false, + execute(guild) { + if (guild.client.mode === "start") { + const guildSize = guild.client.guilds.cache.size; + const userSize = guild.client.users.cache.size; + + update(ref(getDatabase(), "statistics/shioru/size"), { + "guilds": guildSize, + "users": userSize + }); + } + } +}; \ No newline at end of file diff --git a/source/events/guildIntegrationsUpdate.js b/source/events/guildIntegrationsUpdate.js new file mode 100644 index 00000000..616a6589 --- /dev/null +++ b/source/events/guildIntegrationsUpdate.js @@ -0,0 +1,33 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildIntegrationsUpdate, + "once": false, + execute(guild) { + if (guild.client.mode === "start") { + settingsData(guild.client, guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), guild.id); + const channelRef = child(guildRef, "notification/guildIntegrationsUpdate"); + const channelSnapshot = guild.client.api.guilds[guild.id].notification.guildIntegrationsUpdate; + + if (typeof channelSnapshot === "boolean") { + const notification = guild.channels.cache.find(channels => channels.id === channelSnapshot); + const guildIntegrationsUpdate = new EmbedBuilder() + .setTitle(guild.client.translate.events.guildIntegrationsUpdate.guild_notification) + .setDescription(guild.client.translate.events.guildIntegrationsUpdate.guild_integrations_update.replace("%s", guild.name)) + .setImage(guild.bannerURL()) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [guildIntegrationsUpdate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(guild)); + } + } +}; \ No newline at end of file diff --git a/source/events/guildMemberAdd.js b/source/events/guildMemberAdd.js new file mode 100644 index 00000000..bf723d8d --- /dev/null +++ b/source/events/guildMemberAdd.js @@ -0,0 +1,125 @@ +const { + Events, + EmbedBuilder, + AttachmentBuilder, + ActionRowBuilder, + ButtonBuilder, + ButtonStyle, + ModalBuilder, + TextInputBuilder, + TextInputStyle +} = require("discord.js"); +const { CaptchaGenerator } = require("captcha-canvas") +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); +const { catchError } = require("../utils/consoleUtils"); + +module.exports = { + "name": Events.GuildMemberAdd, + "once": false, + async execute(member) { + if (member.user.bot) return; + if (member.client.mode === "start") { + settingsData(member.client, member.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), member.guild.id); + const channelRef = child(guildRef, "notification/guildMemberAdd"); + const channelSnapshot = member.client.api.guilds[member.guild.id].notification.guildMemberAdd; + const captchaSnapshot = member.client.api.guilds[member.guild.id].captcha; + + if (typeof channelSnapshot === "boolean") { + const notification = member.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const memberFetch = await member.user.fetch(); + const memberColor = memberFetch.accentColor; + const memberTag = member.user.tag; + const memberAvatar = member.user.displayAvatarURL(); + const guildMemberAddEmbed = new EmbedBuilder() + .setTitle(memberTag) + .setDescription(member.client.translate.events.guildMemberAdd.greet) + .setTimestamp() + .setColor(memberColor) + .setThumbnail(memberAvatar) + .setAuthor({ "icon_url": "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/microsoft/209/video-game_1f3ae.png", "name": member.client.translate.events.guildMemberAdd.welcome }); + + if (notification) notification.send({ "embeds": [guildMemberAddEmbed] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(member)); + } + if (captchaSnapshot && captchaSnapshot.enable) { + const textSnapshot = captchaSnapshot.text; + + const captcha = new CaptchaGenerator() + .setDimension(150, 450) + .setCaptcha({ "text": textSnapshot, "size": 60, "color": "green" }) + .setDecoy({ "opacity": 0.5 }) + .setTrace({ "color": "green" }); + const buffer = captcha.generateSync(); + + const captchaAttachment = new AttachmentBuilder(buffer, { "name": "captcha.png" }); + + const captchaEmbed = new EmbedBuilder() + .setColor("Blue") + .setImage("attachment://captcha.png") + .setTitle(member.client.translate.events.guildMemberAdd.solve_the_captcha.replace("%s", member.guild.name)) + .setDescription(member.client.translate.events.guildMemberAdd.use_button_below); + const captchaButton = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId("captcha-button") + .setLabel("Answer") + .setStyle(ButtonStyle.Primary) + ); + const captchaModal = new ModalBuilder() + .setTitle(member.client.translate.events.guildMemberAdd.submit_answer_captcha) + .setCustomId("captcha-modal"); + const captchaTextInput = new TextInputBuilder() + .setCustomId("captcha-text-input") + .setRequired(true) + .setLabel(member.client.translate.events.guildMemberAdd.your_answer) + .setPlaceholder(member.client.translate.events.guildMemberAdd.submit_you_answer_guide) + .setStyle(TextInputStyle.Short); + + const captchaFirst = new ActionRowBuilder().addComponents(captchaTextInput); + + captchaModal.addComponents(captchaFirst); + + try { + const guild = member.guild; + const message = await member.send({ "embeds": [captchaEmbed], "files": [captchaAttachment], "components": [captchaButton] }); + const collector = message.createMessageComponentCollector(); + + collector.on("collect", async (component) => { + if (component.customId === "captcha-button") component.showModal(captchaModal); + }); + + member.client.on(Events.InteractionCreate, async (interaction) => { + if (!interaction.isModalSubmit()) return; + if (!interaction.customId === "captcha-modal") return; + + const captchaSnapshot = member.client.api.guilds[guild.id].captcha; + const captchaAnswer = interaction.fields.getTextInputValue("captcha-text-input"); + + if (captchaAnswer !== captchaSnapshot.text) { + return await interaction.reply({ "content": member.client.translate.events.guildMemberAdd.wrong_answer, "ephemeral": true }); + } else { + try { + const captchaRole = captchaSnapshot.role; + const captchaGuild = await member.client.guilds.fetch(guild.id); + const captchaUser = await captchaGuild.members.fetch(interaction.user.id); + const role = await captchaGuild.roles.cache.get(captchaRole); + + await captchaUser.roles.add(role); + await interaction.reply({ "content": member.client.translate.events.guildMemberAdd.captcha_success.replace("%s", captchaGuild.name), "ephemeral": true }) + } catch (error) { + catchError(interaction.client, interaction, "guildMemberAdd", error, true) + await interaction.reply({ "content": member.client.translate.events.guildMemberAdd.captcha_error, "ephemeral": true }); + } + } + }); + } catch (error) { + catchError(member.client, member, "guildMemberAdd", error, true) + } + } + } +}; \ No newline at end of file diff --git a/source/events/guildMemberRemove.js b/source/events/guildMemberRemove.js new file mode 100644 index 00000000..e6b15e37 --- /dev/null +++ b/source/events/guildMemberRemove.js @@ -0,0 +1,38 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildMemberRemove, + "once": false, + async execute(member) { + if (member.user.bot) return; + if (member.client.mode === "start") { + settingsData(member.client, member.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), member.guild.id); + const channelRef = child(guildRef, "notification/guildMemberRemove"); + const channelSnapshot = member.client.api.guilds[member.guild.id].notification.guildMemberRemove; + + if (typeof channelSnapshot === "boolean") { + const notification = member.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const memberFetch = await member.user.fetch(); + const memberColor = memberFetch.accentColor; + const memberTag = member.user.tag; + const memberAvatar = member.user.displayAvatarURL(); + const guildMemberRemoveEmbed = new EmbedBuilder() + .setTitle(memberTag) + .setDescription(member.client.translate.events.guildMemberRemove.user_has_exited) + .setTimestamp() + .setColor(memberColor) + .setThumbnail(memberAvatar); + + if (!notification) return; + + notification.send({ "embeds": [guildMemberRemoveEmbed] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(member)); + } + } +}; \ No newline at end of file diff --git a/source/events/guildMembersChunk.js b/source/events/guildMembersChunk.js new file mode 100644 index 00000000..dd58c459 --- /dev/null +++ b/source/events/guildMembersChunk.js @@ -0,0 +1,33 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildMembersChunk, + "once": false, + execute(members, guild, chunk) { + if (guild.client.mode === "start") { + settingsData(guild.client, guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), guild.id); + const channelRef = child(guildRef, "notification/guildMembersChunk"); + const channelSnapshot = guild.client.api.guilds[guild.id].notification.guildMembersChunk; + + if (typeof channelSnapshot === "boolean") { + const notification = guild.channels.cache.find(channels => channels.id === channelSnapshot); + const guildMembersChunk = new EmbedBuilder() + .setTitle(guild.client.translate.events.guildMembersChunk.guild_notification) + .setDescription(guild.client.translate.events.guildMembersChunk.guild_members_chunk.replace("%s", guild.name)) + .setImage(guild.bannerURL()) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [guildMembersChunk] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(members, guild, chunk)); + } + } +}; \ No newline at end of file diff --git a/source/events/guildUnavailable.js b/source/events/guildUnavailable.js new file mode 100644 index 00000000..769cd621 --- /dev/null +++ b/source/events/guildUnavailable.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildUnavailable, + "once": false, + execute(guild) { + if (guild.client.mode === "start") { + settingsData(guild.client, guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), guild.id); + const channelRef = child(guildRef, "notification/guildUnavailable"); + const channelSnapshot = guild.client.api.guilds[guild.id].notification.guildUnavailable; + + if (typeof channelSnapshot === "boolean") { + const notification = guild.channels.cache.find(channels => channels.id === channelSnapshot); + const guildUnavailable = new EmbedBuilder() + .setTitle(guild.client.translate.events.guildUnavailable.guild_notification) + .setDescription(guild.client.translate.events.guildMembersChunk.guild_unavailable) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [guildUnavailable] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(guild)); + } + } +}; \ No newline at end of file diff --git a/source/events/interaction/interactionCreate.js b/source/events/interaction/interactionCreate.js deleted file mode 100644 index 0baa34c4..00000000 --- a/source/events/interaction/interactionCreate.js +++ /dev/null @@ -1,109 +0,0 @@ -const { ChannelType, PermissionsBitField } = require("discord.js"); -const { getDatabase, ref, child, set, increment } = require("firebase/database"); -const { BitwisePermissionFlags } = require("../../utils/clientUtils"); -const { catchError, ansiColor } = require("../../utils/consoleUtils"); -const { levelSystem, settingsData } = require("../../utils/databaseUtils"); - -module.exports = async (client, interaction) => { - const guildSnapshot = client.api.guilds[interaction.guild.id]; - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), interaction.guild.id); - const command = client.commands.get(interaction.commandName); - - const clearStyle = ansiColor(0, "sgr"); - const underlineStyle = ansiColor(4, "sgr"); - const blueBrightColor = ansiColor(33, "foreground"); - - if (interaction.user.bot) return; - if (interaction.channel.type === ChannelType.DM) return; - if (client.mode === "start") { - settingsData(client, interaction.guild, module.exports, interaction); - if (client.temp.set !== 1) return; - - levelSystem(client, interaction, "POST", 123); - } - - if (!command) return console.log(underlineStyle + interaction.user.username + clearStyle + " Type an unknown command: " + blueBrightColor + commandName + clearStyle); - - // Check that members have the permissions to use the application or not. - if (!interaction.member.permissions.has(PermissionsBitField.Flags.UseApplicationCommands)) { - return await interaction.reply(client.translate.events.interactionCreate.no_permission); - } - - if (command.permissions) { - // Check the permissions of the command for the user. - if (command.permissions.user) { - if (!interaction.member.permissions.has(command.permissions.user)) { - try { - return await interaction.reply(client.translate.events.interactionCreate.user_is_not_allowed).replace("%s", command.permissions.user.map(permission => BitwisePermissionFlags[permission]).join(", ")); - } catch { - return; - } - } - } - - // Check the permissions of the command for the bot. - if (command.permissions.client) { - if (!interaction.guild.members.me.permissions.has(command.permissions.client)) { - try { - return await interaction.member.send(client.translate.events.interactionCreate.client_is_not_allowed).replace("%s", command.permissions.client.map(permission => BitwisePermissionFlags[permission]).join(", ")); - } catch { - return; - } - } - } - } - if (!guildSnapshot.commands || !Object.keys(guildSnapshot.commands).includes(command.name)) { - await set(child(child(guildRef, "commands"), command.name), true); - - return module.exports(client, interaction); - } - if (!guildSnapshot.commands[command.name]) { - command.enable = false; - } - if (!command.enable) { - return await interaction.reply(client.translate.events.interactionCreate.command_is_disabled); - } - - if (interaction.isChatInputCommand()) { - await interaction.deferReply(); - - try { - await command.function.command.execute(interaction); - - // Stores information when the bot is working properly. - if (client.mode === "start") { - set(ref(getDatabase(), "statistics/shioru/size/worked"), increment(1) || 1); - set(child(ref(getDatabase(), "statistics/shioru/commands"), command.name), increment(1) || 1); - } - } catch (error) { - if (interaction.replied || interaction.deferred) { - await interaction.followUp({ "content": client.translate.events.interactionCreate.command_error, "ephemeral": true }); - } else { - await interaction.reply({ "content": client.translate.events.interactionCreate.command_error, "ephemeral": true }); - } - - catchError(client, interaction, interaction.commandName, error); - } - } - if (interaction.isMessageContextMenuCommand()) { - await interaction.deferReply({ "ephemeral": true }); - - try { - await command.function.context.execute(interaction); - - // Stores information when the bot is working properly. - if (client.mode === "start") { - set(ref(getDatabase(), "statistics/shioru/size/worked"), increment(1) || 1); - set(child(ref(getDatabase(), "statistics/shioru/context"), command.name), increment(1) || 1); - } - } catch (error) { - if (interaction.replied || interaction.deferred) { - await interaction.followUp({ "content": client.translate.events.interactionCreate.command_error, "ephemeral": true }); - } else { - await interaction.reply({ "content": client.translate.events.interactionCreate.command_error, "ephemeral": true }); - } - - catchError(client, interaction, interaction.commandName, error); - } - } -} \ No newline at end of file diff --git a/source/events/interactionCreate.js b/source/events/interactionCreate.js new file mode 100644 index 00000000..8b48e0c8 --- /dev/null +++ b/source/events/interactionCreate.js @@ -0,0 +1,108 @@ +const { Events, ChannelType, PermissionsBitField } = require("discord.js"); +const { getDatabase, ref, child, set, increment } = require("firebase/database"); +const { BitwisePermissionFlags } = require("../utils/clientUtils"); +const { catchError } = require("../utils/consoleUtils"); +const { levelSystem, settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.InteractionCreate, + "once": false, + async execute(interaction) { + if (interaction.user.bot) return; + if (interaction.channel.type === ChannelType.DM) return; + + // Check permissions for application commands before working them. + if (!interaction.member.permissions.has(PermissionsBitField.Flags.UseApplicationCommands)) { + return await interaction.reply({ "content": interaction.client.translate.events.interactionCreate.no_permission, "ephemeral": true }); + } + + // Automatic settings data on database + if (interaction.client.mode === "start") { + settingsData(interaction.client, interaction.guild); + levelSystem(interaction.client, interaction, "POST", { "amount": 123, "type": "exp" }); + } + + // Get command when has interaction + const commandName = interaction.commandName; + const command = interaction.client.commands.get(commandName); + + if (command.permissions) { + // Check the permissions of the command for the user. + if (command.permissions.user) { + if (!interaction.member.permissions.has(command.permissions.user)) { + try { + return await interaction.reply({ "content": interaction.client.translate.events.interactionCreate.user_is_not_allowed.replace("%s", command.permissions.user.map(permission => BitwisePermissionFlags[permission]).join(", ")), "ephemeral": true }); + } catch (error) { + return catchError(interaction.client, interaction, interaction.commandName, "interactionCreate", error, true); + } + } + } + + // Check the permissions of the command for the bot. + if (command.permissions.client) { + if (!interaction.guild.members.me.permissions.has(command.permissions.client)) { + try { + return await interaction.member.send({ "content": interaction.client.translate.events.interactionCreate.client_is_not_allowed.replace("%s", command.permissions.client.map(permission => BitwisePermissionFlags[permission]).join(", ")), "ephemeral": true }); + } catch (error) { + return catchError(interaction.client, interaction, interaction.commandName, "interactionCreate", error, true); + } + } + } + } + + // When user interact in chat input + if (interaction.isChatInputCommand()) { + const guildSnapshot = interaction.client.api.guilds[interaction.guild.id]; + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), interaction.guild.id); + + if (!guildSnapshot.commands || !Object.keys(guildSnapshot.commands).includes(command.name)) { + set(child(child(guildRef, "commands"), command.name), true); + } + if ((typeof guildSnapshot.commands[command.name] === "boolean") && (command.enable !== guildSnapshot.commands[command.name])) { + command.enable = guildSnapshot.commands[command.name]; + } + if (!command.enable) { + return await interaction.reply(interaction.client.translate.events.interactionCreate.command_is_disabled); + } + + try { + command.function.command.execute(interaction); + + // Stores information when the bot is working properly. + if (interaction.client.mode === "start") { + set(ref(getDatabase(), "statistics/shioru/size/worked"), increment(1) || 1); + set(child(ref(getDatabase(), "statistics/shioru/commands"), command.name), increment(1) || 1); + } + } catch (error) { + if (interaction.replied || interaction.deferred) { + await interaction.followUp({ "content": interaction.client.translate.events.interactionCreate.command_error, "ephemeral": true }); + } else { + await interaction.reply({ "content": interaction.client.translate.events.interactionCreate.command_error, "ephemeral": true }); + } + + catchError(interaction.client, interaction, "interactionCreate", error); + } + } + + // When user interact in message context menu + if (interaction.isMessageContextMenuCommand()) { + try { + command.function.context.execute(interaction); + + // Stores information when the bot is working properly. + if (interaction.client.mode === "start") { + set(ref(getDatabase(), "statistics/shioru/size/worked"), increment(1) || 1); + set(child(ref(getDatabase(), "statistics/shioru/context"), command.name), increment(1) || 1); + } + } catch (error) { + if (interaction.replied || interaction.deferred) { + await interaction.followUp({ "content": interaction.client.translate.events.interactionCreate.command_error, "ephemeral": true }); + } else { + await interaction.reply({ "content": interaction.client.translate.events.interactionCreate.command_error, "ephemeral": true }); + } + + catchError(interaction.client, interaction, "interactionCreate", error); + } + } + } +} \ No newline at end of file diff --git a/source/events/invite/inviteCreate.js b/source/events/invite/inviteCreate.js deleted file mode 100644 index e87e32d0..00000000 --- a/source/events/invite/inviteCreate.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, invite) => { - if (client.mode === "start") { - settingsData(client, invite.guild, module.exports, invite); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), invite.guild.id); - const channelRef = child(guildRef, "notification/inviteCreate"); - const channelSnapshot = client.api.guilds[invite.guild.id].notification.inviteCreate; - - if (typeof channelSnapshot === "boolean") { - const notification = invite.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const inviteCreate = new EmbedBuilder() - .setTitle(client.translate.events.inviteCreate.invite_notification) - .setDescription(client.translate.events.inviteCreate.invite_create.replace("%s1", invite.url).replace("%s2", invite.expiresAt).replace("%s3", invite.maxUses).replace("%s4", invite.code)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [inviteCreate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, invite)); - } -}; \ No newline at end of file diff --git a/source/events/invite/inviteDelete.js b/source/events/invite/inviteDelete.js deleted file mode 100644 index 3640414c..00000000 --- a/source/events/invite/inviteDelete.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, invite) => { - if (client.mode === "start") { - settingsData(client, invite.guild, module.exports, invite); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), invite.guild.id); - const channelRef = child(guildRef, "notification/inviteDelete"); - const channelSnapshot = client.api.guilds[invite.guild.id].notification.inviteDelete; - - if (typeof channelSnapshot === "boolean") { - const notification = invite.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const inviteDelete = new EmbedBuilder() - .setTitle(client.translate.events.inviteDelete.invite_notification) - .setDescription(new Date() !== new Date(invite.expiresAt) ? client.translate.events.inviteDelete.invite_code_deleted.replace("%s", invite.code) : client.translate.events.inviteDelete.expires.replace("%s", invite.code)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [inviteDelete] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, invite)); - } -}; \ No newline at end of file diff --git a/source/events/inviteCreate.js b/source/events/inviteCreate.js new file mode 100644 index 00000000..74a814c8 --- /dev/null +++ b/source/events/inviteCreate.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.InviteCreate, + "once": false, + execute(invite) { + if (invite.client.mode === "start") { + settingsData(invite.client, invite.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), invite.guild.id); + const channelRef = child(guildRef, "notification/inviteCreate"); + const channelSnapshot = invite.client.api.guilds[invite.guild.id].notification.inviteCreate; + + if (typeof channelSnapshot === "boolean") { + const notification = invite.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const inviteCreate = new EmbedBuilder() + .setTitle(invite.client.translate.events.inviteCreate.invite_notification) + .setDescription(invite.client.translate.events.inviteCreate.invite_create.replace("%s1", invite.url).replace("%s2", invite.expiresAt).replace("%s3", invite.maxUses).replace("%s4", invite.code)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [inviteCreate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(invite)); + } + } +}; \ No newline at end of file diff --git a/source/events/inviteDelete.js b/source/events/inviteDelete.js new file mode 100644 index 00000000..d5828b5a --- /dev/null +++ b/source/events/inviteDelete.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.InviteDelete, + "once": false, + execute(invite) { + if (invite.client.mode === "start") { + settingsData(invite.client, invite.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), invite.guild.id); + const channelRef = child(guildRef, "notification/inviteDelete"); + const channelSnapshot = invite.client.api.guilds[invite.guild.id].notification.inviteDelete; + + if (typeof channelSnapshot === "boolean") { + const notification = invite.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const inviteDelete = new EmbedBuilder() + .setTitle(invite.client.translate.events.inviteDelete.invite_notification) + .setDescription(new Date() !== new Date(invite.expiresAt) ? invite.client.translate.events.inviteDelete.invite_code_deleted.replace("%s", invite.code) : invite.client.translate.events.inviteDelete.expires.replace("%s", invite.code)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [inviteDelete] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(invite)); + } + } +}; \ No newline at end of file diff --git a/source/events/message/messageCreate.js b/source/events/message/messageCreate.js deleted file mode 100644 index 3c780085..00000000 --- a/source/events/message/messageCreate.js +++ /dev/null @@ -1,17 +0,0 @@ -const { ChannelType } = require("discord.js"); -const { chatSystem, levelSystem, settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, message) => { - const mentioned = message.content.startsWith("<@!" + client.user.id + ">") || message.content.startsWith("<@" + client.user.id + ">"); - const arguments = message.content.trim().split(/ +/g); - - if (message.author.bot) return; - if (message.channel.type === ChannelType.DM) return; - if (client.mode === "start") { - settingsData(client, message.guild, module.exports, message); - if (client.temp.set !== 1) return; - - levelSystem(client, message, "POST", 89); - } - if (mentioned) return chatSystem(client, message, mentioned, arguments); -}; \ No newline at end of file diff --git a/source/events/messageCreate.js b/source/events/messageCreate.js new file mode 100644 index 00000000..1925f24e --- /dev/null +++ b/source/events/messageCreate.js @@ -0,0 +1,56 @@ +const { Events, ChannelType } = require("discord.js"); +const { getDatabase, ref, child, set, remove } = require("firebase/database"); +const { chatSystem, levelSystem, settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.MessageCreate, + "once": false, + async execute(message) { + if (message.author.bot) return; + if (message.channel.type === ChannelType.DM) return; + + // Automatic settings data on database + if (message.client.mode === "start") { + settingsData(message.client, message.guild); + levelSystem(message.client, message, "POST", { "amount": 89, "type": "exp" }); + } + + // Detect if user mention bot + const mentioned = message.content.startsWith("<@!" + message.client.user.id + ">") || message.content.startsWith("<@" + message.client.user.id + ">"); + const arguments = message.content.trim().split(/ +/g); + + if (mentioned) chatSystem(message.client, message, mentioned, arguments); + + // Auto remove AFK status + const guildID = message.guild.id; + const afkSnapshot = message.client.api.guilds[guildID].afk ?? ""; + const afkRef = child(child(ref(getDatabase(), "projects/shioru/guilds"), guildID), "afk"); + + if (afkSnapshot && afkSnapshot[message.author.id]) { + await message.channel.sendTyping(); + + try { + await message.member.setNickname(afkSnapshot[message.author.id].nickname); + } catch (error) { + console.log(error); + } + + await remove(afkRef, message.author.id); + await message.reply({ "content": message.client.translate.events.messageCreate.afk_user_come_back, "ephemeral": true }); + } else { + const members = message.mentions.users.first(); + + if (!members) return; + if (!afkSnapshot[members.id]) return; + + await message.channel.sendTyping(); + + const member = message.guild.members.cache.get(members.id); + const reason = afkSnapshot[members.id].message || message.client.translate.events.messageCreate.no_reason_for_afk; + + if (message.content.includes(members)) { + message.reply(message.client.translate.events.messageCreate.that_user_is_afk.replace("%s1", member.user.tag).replace("%s2", reason)); + } + } + } +}; \ No newline at end of file diff --git a/source/events/ready.js b/source/events/ready.js new file mode 100644 index 00000000..ab9d8a6c --- /dev/null +++ b/source/events/ready.js @@ -0,0 +1,271 @@ +const { Events, ActivityType } = require("discord.js"); +const { readdirSync } = require("node:fs"); +const { join } = require("node:path"); +const { getApps } = require("firebase/app"); +const { getFirestore, doc, setDoc } = require("firebase/firestore"); +const { getDatabase, get, onValue, ref, update } = require("firebase/database"); +const { checkForUpdates, updateApplicationCommands } = require("../utils/clientUtils"); +const { currencyFormatter } = require("../utils/miscUtils"); + +module.exports = { + "name": Events.ClientReady, + "once": true, + async execute(client) { + // Notify when the bot is online. + client.console.add("online-loading", { + "text": "Bot is now online at " + client.readyAt.toLocaleString() + ".", + "status": "non-spinnable" + }); + + // Client username + client.console.add("username-check-loading", { + "text": "Sign in with the username " + client.user.username + ".", + "status": "non-spinnable" + }); + + // Refreshing application (/) commands. + updateApplicationCommands(client); + + // Check for update + checkForUpdates(client); + + // Check server is set up. + if (!getApps.length) { + client.console.add("server-check-loading", { + "text": "Connected to the server successfully.", + "status": "non-spinnable" + }); + + client.api = {}; + client.api.statistics = {} + + // Organize data from a database. + const startLoadDataTime = new Date().getTime(); + + client.console.add("server-database-data-loading", { + "text": "Receiving data from database.", + "indent": 2 + }); + get(ref(getDatabase(), "projects/shioru")).then((data) => { + if (data.exists()) client.api = data.val(); + + onValue(ref(getDatabase(), "projects/shioru"), (snapshot) => { + if (snapshot.exists()) client.api = snapshot.val(); + }); + + client.console.succeed("server-database-data-loading", { + "text": "Completed receiving data from the database.: " + (((new Date().getTime() - startLoadDataTime) / 1000) + "s") + }); + }).catch((error) => { + client.console.fail("server-database-data-loading", { + "text": "There was an error getting data from the database.\n" + error + }); + }); + + // Organize statistics from a database. + const startLoadStatisticsTime = new Date().getTime(); + + client.console.add("server-database-statistics-loading", { + "text": "Receiving statistics from database.", + "indent": 2 + }); + get(ref(getDatabase(), "statistics/shioru")).then((data) => { + if (data.exists()) client.api.statistics = data.val(); + + onValue(ref(getDatabase(), "statistics/shioru"), (snapshot) => { + if (snapshot.exists()) client.api.statistics = snapshot.val(); + }); + + client.console.succeed("server-database-statistics-loading", { + "text": "Completed receiving statistics from the database.: " + (((new Date().getTime() - startLoadStatisticsTime) / 1000) + "s") + }); + }).catch((error) => { + client.console.fail("server-database-statistics-loading", { + "text": "There was an error getting statistics from the database.\n" + error + }); + }); + + // Send commands information + client.console.add("server-database-send-info-loading", { + "text": "Send information about the command.", + "indent": 2 + }); + + try { + const startSendDataTime = new Date().getTime(); + const foldersPath = join(__dirname, "../commands"); + const commandFolders = readdirSync(foldersPath); + + for (const [folderIndex, folder] of commandFolders.entries()) { + const commandsPath = join(foldersPath, folder); + const commandFiles = readdirSync(commandsPath).filter(file => file.endsWith(".js")); + + for (const [fileIndex, file] of commandFiles.entries()) { + const filePath = join(commandsPath, file); + const command = require(filePath); + + client.console.update("server-database-send-info-loading", { + "text": "Sending information about the " + command.name + " command." + }); + + setDoc(doc(getFirestore(), "Information", "shioru"), { + "commands": { + [command.category]: { + [command.name]: { + "name": command.name ?? "", + "description": { + "en-US": command.function.command.data.description, + "th": command.function.command.data.description_localizations ? command.function.command.data.description_localizations["th"] : "" + }, + "category": command.category ?? "", + "permissions": { + "client": command.permissions.client ? command.permissions.client.map(String) : [], + "user": command.permissions.user ? command.permissions.user.map(String) : [] + }, + "usage": command.usage ?? "", + "function": { + "command": command.function.command ? true : false, + "context": command.function.context ? true : false + } + } + } + } + }, { + "merge": true + }); + + if ((folderIndex === (commandFolders.length - 1)) && (fileIndex === (commandFiles.length - 1))) { + client.console.succeed("server-database-send-info-loading", { + "text": "Finished sending information about the command.: " + (((new Date().getTime() - startSendDataTime) / 1000) + "s") + }); + } + } + } + } catch (error) { + client.console.fail("server-database-send-info-loading", { + "text": "Failed to send information about the command.\n" + error + }); + } + + // Send bot statistics. + setInterval(() => { + const commandSize = client.commands.size; + const guildSize = client.guilds.cache.size; + const userSize = client.users.cache.size; + + const prevGuildSize = client.api.statistics ? client.api.statistics.size.guilds : guildSize; + const prevUserSize = client.api.statistics ? client.api.statistics.size.users : userSize; + + if (client.mode === "start") { + if (guildSize !== prevGuildSize || userSize !== prevUserSize) { + update(ref(getDatabase(), "statistics/shioru/size"), { + "commands": commandSize, + "guilds": guildSize, + "users": userSize + }); + } + } + }, 5000); + } else { + client.console.add("server-check-loading", { + "text": "Unable to connect to the provider server.", + "status": "non-spinnable" + }); + } + + // Setup bot activity. + let totalGuilds = 0, totalMembers = 0; + const commandSize = client.commands.size; + + if (client.shard && client.shard.count) { + const promises = [ + client.shard.fetchClientValues("guilds.cache.size"), + client.shard.broadcastEval(c => c.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)), + ]; + const results = await Promise.all(promises); + + totalGuilds = results[0].reduce((acc, guildCount) => acc + guildCount, 0); + totalMembers = results[1].reduce((acc, memberCount) => acc + memberCount, 0); + } else { + totalGuilds = client.guilds.cache.size; + totalMembers = client.users.cache.size; + } + + const activities = { + "production": [ + { + "name": currencyFormatter(totalGuilds, 1) + " Server" + (totalGuilds === 1 ? "" : "s"), + "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", + "type": ActivityType.Streaming + }, + { + "name": "/help", + "type": ActivityType.Watching + }, + { + "name": currencyFormatter(totalMembers, 1) + " Member" + (totalMembers === 1 ? "" : "s"), + "type": ActivityType.Watching + }, + { + "name": currencyFormatter(commandSize, 1) + " Command" + (commandSize === 1 ? "" : "s"), + "type": ActivityType.Listening + } + ], + "development": [ + { + "name": "🧶", + "type": ActivityType.Playing + }, + { + "name": "/", + "type": ActivityType.Listening + }, + { + "name": "📦", + "type": ActivityType.Playing + } + ] + }; + const activityType = client.mode === "start" ? activities.production : activities.development; + + client.user.setPresence({ + "status": "available", + "afk": false, + "activities": activityType + }); + + setInterval(async () => { + let totalGuilds = 0, totalMembers = 0; + + if (client.shard && client.shard.count) { + const promises = [ + client.shard.fetchClientValues("guilds.cache.size"), + client.shard.broadcastEval(c => c.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)), + ]; + const results = await Promise.all(promises); + + totalGuilds = results[0].reduce((acc, guildCount) => acc + guildCount, 0); + totalMembers = results[1].reduce((acc, memberCount) => acc + memberCount, 0); + } else { + totalGuilds = client.guilds.cache.size; + totalMembers = client.users.cache.size; + } + + const randomIndex = Math.floor(Math.random() * activityType.length); + const newActivity = activityType[randomIndex]; + + activities.production[0].name = currencyFormatter(totalGuilds, 1) + " Server" + (totalGuilds === 1 ? "" : "s"); + activities.production[2].name = currencyFormatter(totalMembers, 1) + " Member" + (totalMembers === 1 ? "" : "s"); + client.user.setActivity(newActivity); + }, 10000); + + // If everything is ready to go + client.startup.end = new Date().getTime(); + + client.console.add("startup-loading", { + "color": "blueBright", + "text": "Bot is ready to work on the servers!: " + (((client.startup.end - client.startup.start) / 1000) + "s"), + "status": "non-spinnable" + }); + } +}; diff --git a/source/events/role/roleCreate.js b/source/events/role/roleCreate.js deleted file mode 100644 index 3e55e1ed..00000000 --- a/source/events/role/roleCreate.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, role) => { - if (client.mode === "start") { - settingsData(client, role.guild, module.exports, role); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), role.guild.id); - const channelRef = child(guildRef, "notification/roleCreate"); - const channelSnapshot = client.api.guilds[role.guild.id].notification.roleCreate; - - if (typeof channelSnapshot === "boolean") { - const notification = role.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const roleCreate = new EmbedBuilder() - .setTitle(client.translate.events.roleCreate.role_notification) - .setDescription(client.translate.events.roleCreate.role_create.replace("%s", role.id)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [roleCreate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, role)); - } -}; \ No newline at end of file diff --git a/source/events/role/roleDelete.js b/source/events/role/roleDelete.js deleted file mode 100644 index 61b6bbf7..00000000 --- a/source/events/role/roleDelete.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, role) => { - if (client.mode === "start") { - settingsData(client, role.guild, module.exports, role); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), role.guild.id); - const channelRef = child(guildRef, "notification/roleDelete"); - const channelSnapshot = client.api.guilds[role.guild.id].notification.roleDelete; - - if (typeof channelSnapshot === "boolean") { - const notification = role.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const roleDelete = new EmbedBuilder() - .setTitle(client.translate.events.roleDelete.role_notification) - .setDescription(client.translate.events.roleDelete.role_delete.replace("%s", role.name)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [roleDelete] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, role)); - } -}; \ No newline at end of file diff --git a/source/events/role/roleUpdate.js b/source/events/role/roleUpdate.js deleted file mode 100644 index b34ad8a3..00000000 --- a/source/events/role/roleUpdate.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, oldRole, newRole) => { - if (client.mode === "start") { - settingsData(client, newRole.guild, module.exports, (oldRole, newRole)); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newRole.guild.id); - const channelRef = child(guildRef, "notification/roleUpdate"); - const channelSnapshot = client.api.guilds[newRole.guild.id].notification.roleUpdate; - - if (typeof channelSnapshot === "boolean") { - const notification = newRole.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const roleUpdate = new EmbedBuilder() - .setTitle(client.translate.events.roleUpdate.role_notification) - .setDescription(client.translate.events.roleUpdate.role_update.replace("%s1", oldRole.name).replace("%s2", newRole.id)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [roleUpdate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, oldRole, newRole)); - } -}; \ No newline at end of file diff --git a/source/events/roleCreate.js b/source/events/roleCreate.js new file mode 100644 index 00000000..982f88e0 --- /dev/null +++ b/source/events/roleCreate.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildRoleCreate, + "once": false, + execute(role) { + if (role.client.mode === "start") { + settingsData(role.client, role.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), role.guild.id); + const channelRef = child(guildRef, "notification/roleCreate"); + const channelSnapshot = role.client.api.guilds[role.guild.id].notification.roleCreate; + + if (typeof channelSnapshot === "boolean") { + const notification = role.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const roleCreate = new EmbedBuilder() + .setTitle(role.client.translate.events.roleCreate.role_notification) + .setDescription(role.client.translate.events.roleCreate.role_create.replace("%s", role.id)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [roleCreate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(role)); + } + } +}; \ No newline at end of file diff --git a/source/events/roleDelete.js b/source/events/roleDelete.js new file mode 100644 index 00000000..a1df5d13 --- /dev/null +++ b/source/events/roleDelete.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildRoleDelete, + "once": false, + execute(role) { + if (role.client.mode === "start") { + settingsData(role.client, role.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), role.guild.id); + const channelRef = child(guildRef, "notification/roleDelete"); + const channelSnapshot = role.client.api.guilds[role.guild.id].notification.roleDelete; + + if (typeof channelSnapshot === "boolean") { + const notification = role.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const roleDelete = new EmbedBuilder() + .setTitle(role.client.translate.events.roleDelete.role_notification) + .setDescription(role.client.translate.events.roleDelete.role_delete.replace("%s", role.name)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [roleDelete] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(role)); + } + } +}; \ No newline at end of file diff --git a/source/events/roleUpdate.js b/source/events/roleUpdate.js new file mode 100644 index 00000000..58d7ebbc --- /dev/null +++ b/source/events/roleUpdate.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildRoleUpdate, + "once": false, + execute(oldRole, newRole) { + if (newRole.client.mode === "start") { + settingsData(newRole.client, newRole.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newRole.guild.id); + const channelRef = child(guildRef, "notification/roleUpdate"); + const channelSnapshot = newRole.client.api.guilds[newRole.guild.id].notification.roleUpdate; + + if (typeof channelSnapshot === "boolean") { + const notification = newRole.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const roleUpdate = new EmbedBuilder() + .setTitle(newRole.client.translate.events.roleUpdate.role_notification) + .setDescription(newRole.client.translate.events.roleUpdate.role_update.replace("%s1", oldRole.name).replace("%s2", newRole.id)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [roleUpdate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(oldRole, newRole)); + } + } +}; \ No newline at end of file diff --git a/source/events/stage/stageInstanceCreate.js b/source/events/stage/stageInstanceCreate.js deleted file mode 100644 index 3c763efa..00000000 --- a/source/events/stage/stageInstanceCreate.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, stageInstance) => { - if (client.mode === "start") { - settingsData(client, stageInstance.guild, module.exports, stageInstance); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), stageInstance.guild.id); - const channelRef = child(guildRef, "notification/stageInstanceCreate"); - const channelSnapshot = client.api.guilds[stageInstance.guild.id].notification.stageInstanceCreate; - - if (typeof channelSnapshot === "boolean") { - const notification = stageInstance.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const stageInstanceCreate = new EmbedBuilder() - .setTitle(client.translate.events.stageInstanceCreate.stage_notification) - .setDescription(client.translate.events.stageInstanceCreate.stage_instance_create.replace("%s", stageInstance.id)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [stageInstanceCreate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, stageInstance)); - } -}; \ No newline at end of file diff --git a/source/events/stage/stageInstanceDelete.js b/source/events/stage/stageInstanceDelete.js deleted file mode 100644 index ccf514b4..00000000 --- a/source/events/stage/stageInstanceDelete.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, stageInstance) => { - if (client.mode === "start") { - settingsData(client, stageInstance.guild, module.exports, stageInstance); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), stageInstance.guild.id); - const channelRef = child(guildRef, "notification/stageInstanceDelete"); - const channelSnapshot = client.api.guilds[stageInstance.guild.id].notification.stageInstanceDelete; - - if (typeof channelSnapshot === "boolean") { - const notification = stageInstance.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const stageInstanceDelete = new EmbedBuilder() - .setTitle(client.translate.events.stageInstanceDelete.stage_notification) - .setDescription(client.translate.events.stageInstanceDelete.stage_instance_delete.replace("%s", stageInstance.name)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [stageInstanceDelete] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, stageInstance)); - } -}; \ No newline at end of file diff --git a/source/events/stage/stageInstanceUpdate.js b/source/events/stage/stageInstanceUpdate.js deleted file mode 100644 index 6647066f..00000000 --- a/source/events/stage/stageInstanceUpdate.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, oldStageInstance, newStageInstance) => { - if (client.mode === "start") { - settingsData(client, newStageInstance.guild, module.exports, (oldStageInstance, newStageInstance)); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newStageInstance.guild.id); - const channelRef = child(guildRef, "notification/stageInstanceUpdate"); - const channelSnapshot = client.api.guilds[newStageInstance.guild.id].notification.stageInstanceUpdate; - - if (typeof channelSnapshot === "boolean") { - const notification = newStageInstance.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const stageInstanceUpdate = new EmbedBuilder() - .setTitle(client.translate.events.stageInstanceUpdate.stage_notification) - .setDescription(client.translate.events.stageInstanceUpdate.stage_instance_update.replace("%s1", oldStageInstance.name).replace("%s2", newStageInstance.id)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [stageInstanceUpdate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, oldStageInstance, newStageInstance)); - } -}; \ No newline at end of file diff --git a/source/events/stageInstanceCreate.js b/source/events/stageInstanceCreate.js new file mode 100644 index 00000000..1b5e01f4 --- /dev/null +++ b/source/events/stageInstanceCreate.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.StageInstanceCreate, + "once": false, + execute(stageInstance) { + if (stageInstance.client.mode === "start") { + settingsData(stageInstance.client, stageInstance.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), stageInstance.guild.id); + const channelRef = child(guildRef, "notification/stageInstanceCreate"); + const channelSnapshot = stageInstance.client.api.guilds[stageInstance.guild.id].notification.stageInstanceCreate; + + if (typeof channelSnapshot === "boolean") { + const notification = stageInstance.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const stageInstanceCreate = new EmbedBuilder() + .setTitle(stageInstance.client.translate.events.stageInstanceCreate.stage_notification) + .setDescription(stageInstance.client.translate.events.stageInstanceCreate.stage_instance_create.replace("%s", stageInstance.id)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [stageInstanceCreate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(stageInstance)); + } + } +}; \ No newline at end of file diff --git a/source/events/stageInstanceDelete.js b/source/events/stageInstanceDelete.js new file mode 100644 index 00000000..3365adec --- /dev/null +++ b/source/events/stageInstanceDelete.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.StageInstanceDelete, + "once": false, + execute(stageInstance) { + if (stageInstance.client.mode === "start") { + settingsData(stageInstance.client, stageInstance.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), stageInstance.guild.id); + const channelRef = child(guildRef, "notification/stageInstanceDelete"); + const channelSnapshot = stageInstance.client.api.guilds[stageInstance.guild.id].notification.stageInstanceDelete; + + if (typeof channelSnapshot === "boolean") { + const notification = stageInstance.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const stageInstanceDelete = new EmbedBuilder() + .setTitle(stageInstance.client.translate.events.stageInstanceDelete.stage_notification) + .setDescription(stageInstance.client.translate.events.stageInstanceDelete.stage_instance_delete.replace("%s", stageInstance.name)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [stageInstanceDelete] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(stageInstance)); + } + } +}; \ No newline at end of file diff --git a/source/events/stageInstanceUpdate.js b/source/events/stageInstanceUpdate.js new file mode 100644 index 00000000..d3d9f8db --- /dev/null +++ b/source/events/stageInstanceUpdate.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.StageInstanceUpdate, + "once": false, + execute(oldStageInstance, newStageInstance) { + if (newStageInstance.client.mode === "start") { + settingsData(newStageInstance.client, newStageInstance.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newStageInstance.guild.id); + const channelRef = child(guildRef, "notification/stageInstanceUpdate"); + const channelSnapshot = newStageInstance.client.api.guilds[newStageInstance.guild.id].notification.stageInstanceUpdate; + + if (typeof channelSnapshot === "boolean") { + const notification = newStageInstance.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const stageInstanceUpdate = new EmbedBuilder() + .setTitle(newStageInstance.client.translate.events.stageInstanceUpdate.stage_notification) + .setDescription(newStageInstance.client.translate.events.stageInstanceUpdate.stage_instance_update.replace("%s1", oldStageInstance.name).replace("%s2", newStageInstance.id)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [stageInstanceUpdate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(oldStageInstance, newStageInstance)); + } + } +}; \ No newline at end of file diff --git a/source/events/sticker/stickerCreate.js b/source/events/sticker/stickerCreate.js deleted file mode 100644 index d3998e6f..00000000 --- a/source/events/sticker/stickerCreate.js +++ /dev/null @@ -1,30 +0,0 @@ -const { EmbedBuilder, StickerFormatType } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, sticker) => { - if (client.mode === "start") { - settingsData(client, sticker.guild, module.exports, sticker); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), sticker.guild.id); - const channelRef = child(guildRef, "notification/stickerCreate"); - const channelSnapshot = client.api.guilds[sticker.guild.id].notification.stickerCreate; - - if (typeof channelSnapshot === "boolean") { - const notification = sticker.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const stickerCreate = new EmbedBuilder() - .setTitle(client.translate.events.stickerCreate.sticker_notification) - .setDescription(client.translate.events.stickerCreate.sticker_create.replace("%s", sticker.name)) - .setThumbnail(sticker.format !== StickerFormatType.Lottie ? sticker.url : "") - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [stickerCreate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, sticker)); - } -}; \ No newline at end of file diff --git a/source/events/sticker/stickerDelete.js b/source/events/sticker/stickerDelete.js deleted file mode 100644 index e89bcfbe..00000000 --- a/source/events/sticker/stickerDelete.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, sticker) => { - if (client.mode === "start") { - settingsData(client, sticker.guild, module.exports, sticker); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), sticker.guild.id); - const channelRef = child(guildRef, "notification/stickerDelete"); - const channelSnapshot = client.api.guilds[sticker.guild.id].notification.stickerDelete; - - if (typeof channelSnapshot === "boolean") { - const notification = sticker.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const stickerDelete = new EmbedBuilder() - .setTitle(client.translate.events.stickerDelete.sticker_notification) - .setDescription(client.translate.events.stickerDelete.sticker_delete.replace("%s", sticker.name)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [stickerDelete] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, sticker)); - } -}; \ No newline at end of file diff --git a/source/events/sticker/stickerUpdate.js b/source/events/sticker/stickerUpdate.js deleted file mode 100644 index 69a82585..00000000 --- a/source/events/sticker/stickerUpdate.js +++ /dev/null @@ -1,30 +0,0 @@ -const { EmbedBuilder, StickerFormatType } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, oldSticker, newSticker) => { - if (client.mode === "start") { - settingsData(client, newSticker.guild, module.exports, (oldSticker, newSticker)); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newSticker.guild.id); - const channelRef = child(guildRef, "notification/stickerUpdate"); - const channelSnapshot = client.api.guilds[newSticker.guild.id].notification.stickerUpdate; - - if (typeof channelSnapshot === "boolean") { - const notification = newSticker.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const stickerUpdate = new EmbedBuilder() - .setTitle(client.translate.events.stickerUpdate.sticker_notification) - .setDescription(client.translate.events.stickerUpdate.sticker_update.replace("%s1", oldSticker.name).replace("%s2", newSticker.id)) - .setThumbnail(newSticker.format !== StickerFormatType.Lottie ? newSticker.url : "") - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [stickerUpdate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, oldSticker, newSticker)); - } -}; \ No newline at end of file diff --git a/source/events/stickerCreate.js b/source/events/stickerCreate.js new file mode 100644 index 00000000..c32ab1b8 --- /dev/null +++ b/source/events/stickerCreate.js @@ -0,0 +1,33 @@ +const { Events, EmbedBuilder, StickerFormatType } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildStickerCreate, + "once": false, + execute(sticker) { + if (sticker.client.mode === "start") { + settingsData(sticker.client, sticker.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), sticker.guild.id); + const channelRef = child(guildRef, "notification/stickerCreate"); + const channelSnapshot = sticker.client.api.guilds[sticker.guild.id].notification.stickerCreate; + + if (typeof channelSnapshot === "boolean") { + const notification = sticker.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const stickerCreate = new EmbedBuilder() + .setTitle(sticker.client.translate.events.stickerCreate.sticker_notification) + .setDescription(sticker.client.translate.events.stickerCreate.sticker_create.replace("%s", sticker.name)) + .setThumbnail(sticker.format !== StickerFormatType.Lottie ? sticker.url : "") + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [stickerCreate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(sticker)); + } + } +}; \ No newline at end of file diff --git a/source/events/stickerDelete.js b/source/events/stickerDelete.js new file mode 100644 index 00000000..29363b98 --- /dev/null +++ b/source/events/stickerDelete.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildStickerDelete, + "once": false, + execute(sticker) { + if (sticker.client.mode === "start") { + settingsData(sticker.client, sticker.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), sticker.guild.id); + const channelRef = child(guildRef, "notification/stickerDelete"); + const channelSnapshot = sticker.client.api.guilds[sticker.guild.id].notification.stickerDelete; + + if (typeof channelSnapshot === "boolean") { + const notification = sticker.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const stickerDelete = new EmbedBuilder() + .setTitle(sticker.client.translate.events.stickerDelete.sticker_notification) + .setDescription(sticker.client.translate.events.stickerDelete.sticker_delete.replace("%s", sticker.name)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [stickerDelete] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(sticker)); + } + } +}; \ No newline at end of file diff --git a/source/events/stickerUpdate.js b/source/events/stickerUpdate.js new file mode 100644 index 00000000..2f1b6f89 --- /dev/null +++ b/source/events/stickerUpdate.js @@ -0,0 +1,33 @@ +const { Events, EmbedBuilder, StickerFormatType } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.GuildStickerUpdate, + "once": false, + execute(oldSticker, newSticker) { + if (newSticker.client.mode === "start") { + settingsData(newSticker.client, newSticker.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newSticker.guild.id); + const channelRef = child(guildRef, "notification/stickerUpdate"); + const channelSnapshot = newSticker.client.api.guilds[newSticker.guild.id].notification.stickerUpdate; + + if (typeof channelSnapshot === "boolean") { + const notification = newSticker.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const stickerUpdate = new EmbedBuilder() + .setTitle(newSticker.client.translate.events.stickerUpdate.sticker_notification) + .setDescription(newSticker.client.translate.events.stickerUpdate.sticker_update.replace("%s1", oldSticker.name).replace("%s2", newSticker.id)) + .setThumbnail(newSticker.format !== StickerFormatType.Lottie ? newSticker.url : "") + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [stickerUpdate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(oldSticker, newSticker)); + } + } +}; \ No newline at end of file diff --git a/source/events/thread/threadCreate.js b/source/events/thread/threadCreate.js deleted file mode 100644 index b0b4b6bd..00000000 --- a/source/events/thread/threadCreate.js +++ /dev/null @@ -1,28 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, thread, newlyCreated) => { - if (client.mode === "start") { - settingsData(client, thread.guild, module.exports, (thread, newlyCreated)); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), thread.guild.id); - const channelRef = child(guildRef, "notification/threadCreate"); - const channelSnapshot = client.api.guilds[thread.guild.id].notification.threadCreate; - - if (typeof channelSnapshot === "boolean") { - const notification = thread.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const threadCreate = new EmbedBuilder() - .setTitle(client.translate.events.threadCreate.thread_notification) - .setDescription(client.translate.events.threadCreate.thread_create.replace("%s", thread.id)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - if (newlyCreated) notification.send({ "embeds": [threadCreate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, thread, newlyCreated)); - } -}; \ No newline at end of file diff --git a/source/events/thread/threadDelete.js b/source/events/thread/threadDelete.js deleted file mode 100644 index 1ac2706b..00000000 --- a/source/events/thread/threadDelete.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, thread) => { - if (client.mode === "start") { - settingsData(client, thread.guild, module.exports, thread); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), thread.guild.id); - const channelRef = child(guildRef, "notification/threadDelete"); - const channelSnapshot = client.api.guilds[thread.guild.id].notification.threadDelete; - - if (typeof channelSnapshot === "boolean") { - const notification = thread.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const threadDelete = new EmbedBuilder() - .setTitle(client.translate.events.threadDelete.thread_notification) - .setDescription(client.translate.events.threadDelete.thread_delete.replace("%s", thread.name)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [threadDelete] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, thread)); - } -}; \ No newline at end of file diff --git a/source/events/thread/threadUpdate.js b/source/events/thread/threadUpdate.js deleted file mode 100644 index f310a5cd..00000000 --- a/source/events/thread/threadUpdate.js +++ /dev/null @@ -1,29 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = (client, oldThread, newThread) => { - if (client.mode === "start") { - settingsData(client, newThread.guild, module.exports, (oldThread, newThread)); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newThread.guild.id); - const channelRef = child(guildRef, "notification/threadUpdate"); - const channelSnapshot = client.api.guilds[newThread.guild.id].notification.threadUpdate; - - if (typeof channelSnapshot === "boolean") { - const notification = newThread.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const threadUpdate = new EmbedBuilder() - .setTitle(client.translate.events.threadUpdate.thread_notification) - .setDescription(client.translate.events.threadUpdate.thread_update.replace("%s1", oldThread.name).replace("%s2", newThread.id)) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [threadUpdate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, oldThread, newThread)); - } -}; \ No newline at end of file diff --git a/source/events/threadCreate.js b/source/events/threadCreate.js new file mode 100644 index 00000000..9b569f25 --- /dev/null +++ b/source/events/threadCreate.js @@ -0,0 +1,31 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.ThreadCreate, + "once": false, + execute(thread, newlyCreated) { + if (thread.client.mode === "start") { + settingsData(thread.client, thread.guild, module.exports); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), thread.guild.id); + const channelRef = child(guildRef, "notification/threadCreate"); + const channelSnapshot = thread.client.api.guilds[thread.guild.id].notification.threadCreate; + + if (typeof channelSnapshot === "boolean") { + const notification = thread.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const threadCreate = new EmbedBuilder() + .setTitle(thread.client.translate.events.threadCreate.thread_notification) + .setDescription(thread.client.translate.events.threadCreate.thread_create.replace("%s", thread.id)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + if (newlyCreated) notification.send({ "embeds": [threadCreate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(thread, newlyCreated)); + } + } +}; \ No newline at end of file diff --git a/source/events/threadDelete.js b/source/events/threadDelete.js new file mode 100644 index 00000000..8a8a07f3 --- /dev/null +++ b/source/events/threadDelete.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.ThreadDelete, + "once": false, + execute(thread) { + if (thread.client.mode === "start") { + settingsData(thread.client, thread.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), thread.guild.id); + const channelRef = child(guildRef, "notification/threadDelete"); + const channelSnapshot = thread.client.api.guilds[thread.guild.id].notification.threadDelete; + + if (typeof channelSnapshot === "boolean") { + const notification = thread.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const threadDelete = new EmbedBuilder() + .setTitle(thread.client.translate.events.threadDelete.thread_notification) + .setDescription(thread.client.translate.events.threadDelete.thread_delete.replace("%s", thread.name)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [threadDelete] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(thread)); + } + } +}; \ No newline at end of file diff --git a/source/events/threadUpdate.js b/source/events/threadUpdate.js new file mode 100644 index 00000000..d34d7d5a --- /dev/null +++ b/source/events/threadUpdate.js @@ -0,0 +1,32 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.ThreadUpdate, + "once": false, + execute(oldThread, newThread) { + if (newThread.client.mode === "start") { + settingsData(newThread.client, newThread.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), newThread.guild.id); + const channelRef = child(guildRef, "notification/threadUpdate"); + const channelSnapshot = newThread.client.api.guilds[newThread.guild.id].notification.threadUpdate; + + if (typeof channelSnapshot === "boolean") { + const notification = newThread.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const threadUpdate = new EmbedBuilder() + .setTitle(newThread.client.translate.events.threadUpdate.thread_notification) + .setDescription(newThread.client.translate.events.threadUpdate.thread_update.replace("%s1", oldThread.name).replace("%s2", newThread.id)) + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [threadUpdate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(oldThread, newThread)); + } + } +}; \ No newline at end of file diff --git a/source/events/warn.js b/source/events/warn.js new file mode 100644 index 00000000..9d207659 --- /dev/null +++ b/source/events/warn.js @@ -0,0 +1,11 @@ +const { Events } = require("discord.js"); +const { logGenerator } = require("../utils/consoleUtils"); + +module.exports = { + "name": Events.Warn, + "once": false, + execute(info) { + logGenerator("warn", info); + console.warn(info); + } +}; \ No newline at end of file diff --git a/source/events/webhook/webhookUpdate.js b/source/events/webhook/webhookUpdate.js deleted file mode 100644 index 372308e5..00000000 --- a/source/events/webhook/webhookUpdate.js +++ /dev/null @@ -1,31 +0,0 @@ -const { EmbedBuilder } = require("discord.js"); -const { getDatabase, ref, child, set } = require("firebase/database"); -const { settingsData } = require("../../utils/databaseUtils"); - -module.exports = async (client, channel) => { - if (client.mode === "start") { - settingsData(client, channel.guild, module.exports, channel); - if (client.temp.set !== 1) return; - } - - const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), channel.guild.id); - const channelRef = child(guildRef, "notification/webhookUpdate"); - const channelSnapshot = client.api.guilds[channel.guild.id].notification.webhookUpdate; - - if (typeof channelSnapshot === "boolean") { - const notification = channel.guild.channels.cache.find(channels => channels.id === channelSnapshot); - const hooks = await channel.fetchWebhooks(); - const webhookUpdate = new EmbedBuilder() - .setTitle(client.translate.events.webhookUpdate.webhook_notification) - .setDescription(client.translate.events.webhookUpdate.webhook_update.replace("%s1", hooks.name ? hooks.name : "Webhook").replace("%s2", hooks.sourceGuild.name).replace("%s3", channel.id)) - .setThumbnail(hooks.avatarURL()) - .setTimestamp() - .setColor("Yellow"); - - if (!notification) return; - - notification.send({ "embeds": [webhookUpdate] }); - } else { - set(channelRef, channelSnapshot ? true : false).then(() => module.exports(client, channel)); - } -}; \ No newline at end of file diff --git a/source/events/webhookUpdate.js b/source/events/webhookUpdate.js new file mode 100644 index 00000000..fe175e9b --- /dev/null +++ b/source/events/webhookUpdate.js @@ -0,0 +1,34 @@ +const { Events, EmbedBuilder } = require("discord.js"); +const { getDatabase, ref, child, set } = require("firebase/database"); +const { settingsData } = require("../utils/databaseUtils"); + +module.exports = { + "name": Events.WebhooksUpdate, + "once": false, + async execute(channel) { + if (channel.client.mode === "start") { + settingsData(channel.client, channel.guild); + } + + const guildRef = child(ref(getDatabase(), "projects/shioru/guilds"), channel.guild.id); + const channelRef = child(guildRef, "notification/webhookUpdate"); + const channelSnapshot = channel.client.api.guilds[channel.guild.id].notification.webhookUpdate; + + if (typeof channelSnapshot === "boolean") { + const notification = channel.guild.channels.cache.find(channels => channels.id === channelSnapshot); + const hooks = await channel.fetchWebhooks(); + const webhookUpdate = new EmbedBuilder() + .setTitle(channel.client.translate.events.webhookUpdate.webhook_notification) + .setDescription(channel.client.translate.events.webhookUpdate.webhook_update.replace("%s1", hooks ? hooks.name : "Webhook").replace("%s2", hooks ? hooks.sourceGuild.name : "").replace("%s3", channel.id)) + .setThumbnail(hooks ? hooks.avatarURL() : "") + .setTimestamp() + .setColor("Yellow"); + + if (!notification) return; + + notification.send({ "embeds": [webhookUpdate] }); + } else { + set(channelRef, channelSnapshot ? true : false).then(() => module.exports.execute(channel)); + } + } +}; \ No newline at end of file