diff --git a/events/client/ready.js b/events/client/ready.js index 59b91da..1a4298d 100755 --- a/events/client/ready.js +++ b/events/client/ready.js @@ -96,8 +96,8 @@ module.exports = client => { {text: "[help"}, {text: "[help"}, {text: "Like ur cut G"}, - {text: "une dernière fois Daft Punk", type: "LISTENING"} - {text: "Doki doki blue skies"} + {text: "une dernière fois Daft Punk", type: "LISTENING"}, + {text: "Doki doki blue skies"}, ] var status, lastStatus = "" diff --git a/handlers/timedMessages.js b/handlers/timedMessages.js new file mode 100644 index 0000000..ce5717b --- /dev/null +++ b/handlers/timedMessages.js @@ -0,0 +1,43 @@ +const { readdirSync } = require("fs"); +const ascii = require("ascii-table"); +let table = new ascii("Timed messages"); +table.setHeading("Name", "Load status"); +module.exports = (client) => { + try{ + const timesMessagesFiles = readdirSync(`./timedMessages/`).filter((file) => file.endsWith(".js")); // Get all the js files + for (let file of timesMessagesFiles) { + let pull = require(`../timedMessages/${file}`); + if (pull.name && pull.time) { + ([hour, second] = pull.time.split(":")) + + function getNextRunETA(hour, second) { + var todayDate = new Date(); + var nextRunDate = new Date(); + nextRunDate.setHours(hour, second, 0) + if (nextRunDate <= todayDate) { + nextRunDate.setDate(todayDate.getDate() + 1) + } + return nextRunDate - todayDate; + } + + function runMessage(hour, second) { + pull.run(client) + + setTimeout(runMessage, getNextRunETA(hour, second), hour, second) + } + + setTimeout(runMessage, getNextRunETA(hour, second), hour, second) + + table.addRow(pull.name, "Ready"); + } else { + table.addRow(file, `error->missing a name or time or is not a string.`); + continue; + } + } + console.log(table.toString().cyan); + }catch (e){ + console.log(String(e.stack).bgRed) + } +}; + +/** Template by Tomato#6966 | https://github.com/Tomato6966/Discord-Js-Handler-Template */ diff --git a/index.js b/index.js index d6d78b9..1dda16c 100755 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ client.keywords = new Discord.Collection(); // all the keywords the bot will rea client.dmCommands = new Discord.Collection(); // all the private commands //Loading files, with the client variable like Command Handler, Event Handler, ... -["command", "dmCommand", "events", "keywords"].forEach(handler => { +["command", "dmCommand", "events", "keywords", "timedMessages"].forEach(handler => { require(`./handlers/${handler}`)(client); }); diff --git a/timedMessages/hellcase.js b/timedMessages/hellcase.js new file mode 100644 index 0000000..238e4d1 --- /dev/null +++ b/timedMessages/hellcase.js @@ -0,0 +1,30 @@ +const { MessageEmbed, Message } = require("discord.js"); +const config = require("../botconfig/config.json"); +const ee = require("../botconfig/embed.json"); +const { sendNinluc } = require("../handlers/functions"); + +const RAPPEL_CHANNEL_ID = "1296051297262370866"; + +module.exports = { + name: "Hellcase", + time: "21:30", + run: async (client) => { + try { + client.channels.fetch(RAPPEL_CHANNEL_ID) + .then(channel => channel.send({ + embeds: [ + new MessageEmbed() + .setColor(ee.color) + .setFooter({ text: ee.footertext, iconURL: ee.footericon }) + .setTitle(`Rappel : Caisse gratuite Hellcase`) + .setDescription("[Hellcase](https://hellcase.com/)") + ], + }) + ); + } catch (e) { + console.log(String(e.stack).bgRed); + } + }, +}; + +/** Template by Tomato#6966 | https://github.com/Tomato6966/Discord-Js-Handler-Template */ diff --git a/timedMessages/snap.js b/timedMessages/snap.js new file mode 100644 index 0000000..ffc91f5 --- /dev/null +++ b/timedMessages/snap.js @@ -0,0 +1,29 @@ +const { MessageEmbed, Message } = require("discord.js"); +const config = require("../botconfig/config.json"); +const ee = require("../botconfig/embed.json"); +const { sendNinluc } = require("../handlers/functions"); + +const RAPPEL_CHANNEL_ID = "1296051297262370866"; + +module.exports = { + name: "Shop Marvel Snap", + time: "21:00", + run: async (client) => { + try { + client.channels.fetch(RAPPEL_CHANNEL_ID) + .then(channel => channel.send({ + embeds: [ + new MessageEmbed() + .setColor(ee.color) + .setFooter({ text: ee.footertext, iconURL: ee.footericon }) + .setTitle(`Rappel : Shop Marvel Snap`) + ], + }) + ); + } catch (e) { + console.log(String(e.stack).bgRed); + } + }, +}; + +/** Template by Tomato#6966 | https://github.com/Tomato6966/Discord-Js-Handler-Template */