Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/commands/dailymsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports = {
),
/**
* @param {CommandInteraction} interaction
* @param {Client} client
* @param {WouldYou} client
* @param {guildModel} guildDb
*/
async execute(interaction, client, guildDb) {
Expand All @@ -110,11 +110,11 @@ module.exports = {
) {
switch (interaction.options.getSubcommand()) {
case 'message': {
if (guildDb.dailyMsg && interaction.options.getString("message") === "true") return await interaction.reply({
if (guildDb.dailyMsg && interaction.options.getString("message") === "true") return interaction.reply({
ephemeral: true,
content: `${Daily.embed.alreadytrue}`
})
if (!guildDb.dailyMsg && interaction.options.getString("message") === "false") return await interaction.reply({
if (!guildDb.dailyMsg && interaction.options.getString("message") === "false") return interaction.reply({
ephemeral: true,
content: `${Daily.embed.alreadyfalse}`
})
Expand All @@ -135,11 +135,11 @@ module.exports = {
case 'types': {
const types = interaction.options.getString("types") === "true" ? true : false;

if (guildDb.dailyRather && types) return await interaction.reply({
if (guildDb.dailyRather && types) return interaction.reply({
ephemeral: true,
content: `${Daily.embed.alreadytrue}`
})
if (!guildDb.dailyRather && !types) return await interaction.reply({
if (!guildDb.dailyRather && !types) return interaction.reply({
ephemeral: true,
content: `${Daily.embed.alreadyfalse}`
})
Expand All @@ -161,19 +161,27 @@ module.exports = {
case 'channel': {
const channel = interaction.options.getChannel("channel");

if (!channel?.permissionsFor(client?.user?.id)?.has([PermissionFlagsBits.ViewChannel])) return await interaction.reply({
if (!channel?.permissionsFor(client?.user?.id)?.has([PermissionFlagsBits.ViewChannel])) return interaction.reply({
ephemeral: true,
content: Daily.errorChannel.viewChannel
})
if (!channel?.permissionsFor(client?.user?.id)?.has([PermissionFlagsBits.SendMessages])) return await interaction.reply({
if (!channel?.permissionsFor(client?.user?.id)?.has([PermissionFlagsBits.SendMessages])) return interaction.reply({
ephemeral: true,
content: Daily.errorChannel.sendMessages
})
if (guildDb.dailyChannel && guildDb.dailyChannel === channel.id) return await interaction.reply({
if (!channel?.permissionsFor(client?.user?.id)?.has([PermissionFlagsBits.ManageWebhooks])) return interaction.reply({
ephemeral: true,
content: Daily.errorChannel.manageWebhooks
})
if (guildDb.dailyChannel && guildDb.dailyChannel === channel.id) return interaction.reply({
ephemeral: true,
content: Daily.errorChannel.alreadySet
})

await client.webhookHandler.sendWebhook(channel, channel.id, {
content: '<:roundyou:1009964111045607525> This channel will be used to send daily Would You messages.'
})

await client.database.updateGuild(interaction.guildId, {
dailyChannel: channel.id,
}, true)
Expand All @@ -191,7 +199,7 @@ module.exports = {
case 'role': {
const role = interaction.options.getRole("role");

if (guildDb.dailyRole && guildDb.dailyRole === role.id) return await interaction.reply({
if (guildDb.dailyRole && guildDb.dailyRole === role.id) return interaction.reply({
ephemeral: true,
content: Daily.errorRole
})
Expand All @@ -215,15 +223,15 @@ module.exports = {
const userInput = interaction.options.getString("timezone");
const lowerCaseUserInput = userInput.toLowerCase();

if (guildDb.dailyTimezone.toLowerCase() === lowerCaseUserInput) return await interaction.reply({
if (guildDb.dailyTimezone.toLowerCase() === lowerCaseUserInput) return interaction.reply({
ephemeral: true,
content: Daily.timezone.errorSame
})
if (!isValid(lowerCaseUserInput)) return await interaction.reply({
if (!isValid(lowerCaseUserInput)) return interaction.reply({
ephemeral: true,
content: Daily.timezone.errorInvalid
})
if (!dateType(lowerCaseUserInput)) return await interaction.reply({
if (!dateType(lowerCaseUserInput)) return interaction.reply({
ephemeral: true,
content: Daily.timezone.errorInvalid
})
Expand Down
53 changes: 35 additions & 18 deletions src/events/guildCreate.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
const { WebhookClient, EmbedBuilder } = require('discord.js');
const {WebhookClient, EmbedBuilder} = require('discord.js');
require('dotenv').config();

module.exports = async (client, guild) => {
if (!guild?.name) return;
if (!guild?.name) return;

// Create and save the settings in the cache so that we don't need to do that at a command run
await client.database.getGuild(guild?.id, true);
// Create and save the settings in the cache so that we don't need to do that at a command run
await client.database.getGuild(guild?.id, true);

const webhookClient = new WebhookClient({ url: process.env.WEBHOOK });
const webhookPrivate = new WebhookClient({ url: process.env.WEBHOOKPRIVATE });
const webhookPrivate = new WebhookClient({url: process.env.WEBHOOKPRIVATE});

let features;
if (guild.features && guild.features.includes("VERIFIED") || guild.features.includes("PARTNERED")) {
features = guild.features.includes("VERIFIED") ? `<:verified_green:1072265950134550548>` : `<:partner:1072265822577360982>`
}
let features;
if (guild.features && guild.features.includes("VERIFIED") || guild.features.includes("PARTNERED")) {
features = guild.features.includes("VERIFIED") ? `<:verified_green:1072265950134550548>` : `<:partner:1072265822577360982>`
}

webhookPrivate.send({
embeds: [new EmbedBuilder().setTitle(`→ Joined Server`).setColor(`#0598F4`).setThumbnail(guild.iconURL({ format: 'png', dynamic: true })).setDescription(`**Name**: ${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}\n**Users**: ${guild.memberCount.toLocaleString()}${features ? `\n**Features**: ${features}` : ``}`)]
})
await webhookPrivate.send({
avatarURL: 'https://wouldyoubot.gg/static/img/round.webp', // Make sure to update this if you ever change the link thx <3
username: global?.devBot ? 'Dev Bot' : 'Main Bot',
embeds: [
new EmbedBuilder()
.setTitle(`→ Joined Server`)
.setColor(`#0598F4`)
.setThumbnail(guild.iconURL({
format: 'png',
dynamic: true
}))
.setDescription(`**Name**: ${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}\n**Users**: ${guild.memberCount.toLocaleString()}${features ? `\n**Features**: ${features}` : ``}`)
.setFooter({
text: global?.devBot ? 'Dev Bot' : 'Main Bot',
})
]
})

webhookClient.send({
content: `<:GoodCheck:1025490645525209148> Joined ${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}. I'm now in ${client.guilds.cache.size} guilds.`,
username: `${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}`,
avatarURL: guild.iconURL({ format: 'webp', dynamic: true, size: 1024 }),
}).catch((err) => console.log(err));
if (!global?.devBot) {
const webhookClient = new WebhookClient({url: process.env.WEBHOOK});

await webhookClient.send({
content: `<:GoodCheck:1025490645525209148> Joined ${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}. I'm now in ${client.guilds.cache.size} guilds.`,
username: `${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}`,
avatarURL: guild.iconURL({format: 'webp', dynamic: true, size: 1024}),
}).catch((err) => console.log(err));
}
};
53 changes: 35 additions & 18 deletions src/events/guildDelete.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
const { WebhookClient, EmbedBuilder } = require('discord.js');
const {WebhookClient, EmbedBuilder} = require('discord.js');
require('dotenv').config();

module.exports = async (client, guild) => {
if(!guild?.name) return;
if (!guild?.name) return;

// Only delete the guild settings from the cache we don't want a data lose but also don't need not used data in the cache :)
await client.database.deleteGuild(guild?.id, true);
// Only delete the guild settings from the cache we don't want a data lose but also don't need not used data in the cache :)
await client.database.deleteGuild(guild?.id, true);

const webhookClient = new WebhookClient({ url: process.env.WEBHOOK });
const webhookPrivate = new WebhookClient({ url: process.env.WEBHOOKPRIVATE });
const webhookPrivate = new WebhookClient({url: process.env.WEBHOOKPRIVATE});

let features;
if (guild.features && guild.features.includes("VERIFIED") || guild.features.includes("PARTNERED")) {
features = guild.features.includes("VERIFIED") ? `<:verified_green:1072265950134550548>` : `<:partner:1072265822577360982>`;
};
let features;
if (guild.features && guild.features.includes("VERIFIED") || guild.features.includes("PARTNERED")) {
features = guild.features.includes("VERIFIED") ? `<:verified_green:1072265950134550548>` : `<:partner:1072265822577360982>`;
}

webhookPrivate.send({
embeds: [new EmbedBuilder().setTitle(`← Left Server`).setColor(`#0598F4`).setThumbnail(guild.iconURL({ format: 'png', dynamic: true })).setDescription(`**Name**: ${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}\n**Users**: ${guild.memberCount.toLocaleString()}${features ? `\n**Features**: ${features}` : ``}`)]
});
await webhookPrivate.send({
avatarURL: 'https://wouldyoubot.gg/static/img/round.webp', // Make sure to update this if you ever change the link thx <3
username: global?.devBot ? 'Dev Bot' : 'Main Bot',
embeds: [
new EmbedBuilder()
.setTitle(`← Left Server`)
.setColor(`#0598F4`)
.setThumbnail(guild.iconURL({
format: 'png',
dynamic: true
}))
.setDescription(`**Name**: ${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}\n**Users**: ${guild.memberCount.toLocaleString()}${features ? `\n**Features**: ${features}` : ``}`)
.setFooter({
text: global?.devBot ? 'Dev Bot' : 'Main Bot',
})
]
});

webhookClient.send({
content: `<:BadCheck:1025490660968628436> Left ${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}. I'm now in ${client.guilds.cache.size} guilds.`,
username: `${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}`,
avatarURL: guild.iconURL({ format: 'webp', dynamic: true, size: 1024 }),
}).catch((err) => console.log(err));
if (!global?.devBot) {
const webhookClient = new WebhookClient({url: process.env.WEBHOOK});

await webhookClient.send({
content: `<:BadCheck:1025490660968628436> Left ${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}. I'm now in ${client.guilds.cache.size} guilds.`,
username: `${guild.name.replace("Discord", "").replace("discord", "").replace("Everyone", "").replace("everyone", "")}`,
avatarURL: guild.iconURL({format: 'webp', dynamic: true, size: 1024}),
}).catch((err) => console.log(err));
}
};
18 changes: 18 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
const WouldYou = require('./util/wouldYou');
const {ChalkAdvanced} = require("chalk-advanced");

// Token to UserID Function
// Credits to Meister#9667 for helping me with this
const retriveUserIdbyToken = (token) => {
const parseuser = (token.split('.'))[0]
const buff = Buffer.from(parseuser, 'base64');
const userid = buff.toString('utf-8');
return userid;
}

global.devBot = false;

const botId = retriveUserIdbyToken(process.env.DISCORD_TOKEN);
if(botId !== '981649513427111957' || process.env.STATUS === 'DEVELOPMENT') {
global.devBot = true;
} else if(process.env.STATUS === 'DEVELOPMENT' && botId === '981649513427111957') {
throw new Error('Are you stupid? Why should you run the main bot with status "DEVELOPMENT"?!');
}

const client = new WouldYou();
client.loginBot().then(() => {
console.log(
Expand Down
1 change: 1 addition & 0 deletions src/languages/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
"errorChannel": {
"viewChannel": "Der angegebene Kanal erlaubt es mir nicht, ihn zu sehen. Bitte wähle einen Kanal, auf den ich Zugriff habe.",
"sendMessages": "Der angegebene Kanal erlaubt es mir nicht nachrichten zu senden. Bitte wähle einen Kanal, auf den ich Zugriff habe.",
"manageWebhooks": "Der angegebene Kanal erlaubt es mir nicht Webhooks zu erstellen. Bitte wähle einen Kanal, in dem ich Webhooks erstellen kann.",
"alreadySet": "Der angegebene Kanal ist derselbe, der bereits gesetzt ist. Stelle sicher, dass du einen anderen Kanal wählen."
},
"success": {
Expand Down
1 change: 1 addition & 0 deletions src/languages/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
"errorChannel": {
"viewChannel": "The channel provided doesn't allow me to view it. Select a channel which I have access to.",
"sendMessages": "The channel provided doesn't allow me to send messages to it. Select a channel which I have access to.",
"manageWebhooks": "The channel provided doesn't allow me to create webhooks inside of it. Select a channel which I can create webhooks.",
"alreadySet": "The provided channel is the same channel that is already set. Make sure to choose a different channel."
},
"success": {
Expand Down
1 change: 1 addition & 0 deletions src/languages/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
"errorChannel": {
"viewChannel": "No tengo permiso para ver ese canal. Selecciona un canal al que tenga acceso.",
"sendMessages": "No tengo permiso para enviar mensajes a ese canal. Selecciona un canal al que tenga acceso.",
"manageWebhooks": "El canal proporcionado no me permite crear webhooks dentro de él. Seleccione un canal en el que pueda crear webhooks.",
"alreadySet": "El canal proporcionado es el mismo canal que ya está configurado. Asegúrate de elegir un canal diferente."
},
"success": {
Expand Down
4 changes: 0 additions & 4 deletions src/util/Models/guildModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ const guildProfile = new Schema(
type: String,
default: "America/Chicago"
},
dailyDay: {
type: Number,
default: 0,
},
replay: {
type: Boolean,
default: true,
Expand Down
20 changes: 8 additions & 12 deletions src/util/dailyMessage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {EmbedBuilder} = require('discord.js');
const mom = require("moment-timezone");
const {ChalkAdvanced} = require("chalk-advanced");
const CronJob = require('cron').CronJob;

module.exports = class DailyMessage {
Expand All @@ -21,29 +22,24 @@ module.exports = class DailyMessage {
* @return {Promise<void>}
*/
async runSchedule() {
const today = new Date();
let guilds = await this.c.database.getAll();
guilds = guilds.filter(g => this.c.guilds.cache.has(g.guildID) && g.dailyMsg && Number(g.dailyDay) !== today.getDay());
guilds = guilds.filter(g => this.c.guilds.cache.has(g.guildID) && g.dailyMsg);

console.log(
`${ChalkAdvanced.white('Daily Message')} ${ChalkAdvanced.gray(
'>',
)} ${ChalkAdvanced.green('Running daily message check for ' + guilds.length + ' guilds')}`,
);

let i = 0;
for (const db of guilds) {
i++;
setTimeout(async () => {
if (!db.dailyMsg) return;
if (!isNaN(db.dailyDay)) {
if (db.dailyDay === new Date().getDay()) return;
}

if (mom.tz(db.dailyTimezone).format("HH:mm") === "12:00") {
await this.c.database.updateGuild(db.guildID, {
dailyDay: today.getDay()
}, false)

const channel = await this.c.channels.fetch(db.dailyChannel).catch(err => {
});

channel.data = db;

if (!channel?.id) return; // Always directly return before do to many actions

const {Useless_Powers, Useful_Powers} = await require(`../data/power-${db.language}.json`);
Expand Down
Loading