Skip to content

Commit

Permalink
ℹ️ Add new events
Browse files Browse the repository at this point in the history
  • Loading branch information
Maseshi committed Aug 10, 2022
1 parent 7051e9e commit f0589aa
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
40 changes: 40 additions & 0 deletions source/events/guild/guildBanAdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { EmbedBuilder } = require("discord.js");
const { getDatabase, ref, child, get, set } = require("firebase/database");
const { settingsData } = require("../../utils/databaseUtils");
const { catchError } = require("../../utils/consoleUtils");

module.exports = (client, ban) => {
if (client.mode === "start") {
settingsData(client, ban.guild, module.exports, ban);
if (client.temp.set !== 1) return;
}

const db = getDatabase();
const childRef = child(ref(db, "Shioru/apps/discord/guilds"), ban.guild.id);
const channelRef = child(childRef, "config/notification/guildBanAdd");

get(channelRef).then((snapshot) => {
if (snapshot.exists()) {
const notifyId = snapshot.val();

if (notifyId) {
const notification = ban.guild.channels.cache.find(channels => channels.id === notifyId);
const guildBanAddEmbed = new EmbedBuilder()
.setTitle(client.translate.events.guildBanAdd.system_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, false).then(() => {
module.exports(client, ban);
});
}
}).catch((error) => {
catchError(client, ban.guild.systemChannel, "guildBanAdd", error);
});
};
40 changes: 40 additions & 0 deletions source/events/guild/guildBanRemove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { EmbedBuilder } = require("discord.js");
const { getDatabase, ref, child, get, set } = require("firebase/database");
const { settingsData } = require("../../utils/databaseUtils");
const { catchError } = require("../../utils/consoleUtils");

module.exports = (client, ban) => {
if (client.mode === "start") {
settingsData(client, ban.guild, module.exports, ban);
if (client.temp.set !== 1) return;
}

const db = getDatabase();
const childRef = child(ref(db, "Shioru/apps/discord/guilds"), ban.guild.id);
const channelRef = child(childRef, "config/notification/guildBanRemove");

get(channelRef).then((snapshot) => {
if (snapshot.exists()) {
const notifyId = snapshot.val();

if (notifyId) {
const notification = ban.guild.channels.cache.find(channels => channels.id === notifyId);
const guildBanRemoveEmbed = new EmbedBuilder()
.setTitle(client.translate.events.guildBanRemove.system_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, false).then(() => {
module.exports(client, ban);
});
}
}).catch((error) => {
catchError(client, ban.guild.systemChannel, "guildBanRemove", error);
});
};

0 comments on commit f0589aa

Please sign in to comment.