diff --git a/src/util/Models/guildModel.js b/src/util/Models/guildModel.js index 24ad1a03..7e313139 100644 --- a/src/util/Models/guildModel.js +++ b/src/util/Models/guildModel.js @@ -35,6 +35,7 @@ const guildProfile = new Schema( }, dailyDay: { type: Number, + default: 0, }, nsfw: { type: Boolean, diff --git a/src/util/dailyMsgs.js b/src/util/dailyMsgs.js index ca8e2b54..99d65b15 100644 --- a/src/util/dailyMsgs.js +++ b/src/util/dailyMsgs.js @@ -6,9 +6,11 @@ module.exports = async (client) => { const guilds = await guildLang.find(); guilds.map(async db => { if (!db.dailyMsg) return; - if (!client.channels.cache.get(db.dailyChannel)) return - if (db.dailyDay && db.dailyDay !== new Date().getDay()) return; - if (mom.tz(db.dailyTimezone).format("HH") === "12") { + if (!isNaN(db.dailyDay)) { if (db.dailyDay === new Date().getDay()) return; } + if (mom.tz(db.dailyTimezone).format("HH:mm") === "16:25") { + db.dailyDay = new Date().getDay(); + db.save(); + const { Useless_Powers, Useful_Powers, } = await require(`../data/power-${db.language}.json`); const { WouldYou } = await require(`../languages/${db.language}.json`); let power; @@ -52,21 +54,15 @@ module.exports = async (client) => { if (db.dailyRole) { client.channels.cache .get(db.dailyChannel) - .send({ embeds: [embed], content: `<@&${db.dailyRole}>` }).catch(() => { }) + .send({ embeds: [embed], content: `<@&${db.dailyRole}>` }) + .catch(() => { }) } else { client.channels.cache .get(db.dailyChannel) - .send({ embeds: [embed] }).catch(() => { }) - } - - if (db.dailyDay === 6) { - db.dailyDay = 0; - return db.save() + .send({ embeds: [embed] }) + .catch(() => { }) } - - db.dailyDay = new Date().getDay() + 1; - db.save() } }) }, 4000) -}; +}; \ No newline at end of file diff --git a/src/util/dbHandler.js b/src/util/dbHandler.js index 3fd58f62..85927dbc 100644 --- a/src/util/dbHandler.js +++ b/src/util/dbHandler.js @@ -3,8 +3,9 @@ require('dotenv').config(); const { ChalkAdvanced } = require('chalk-advanced'); -connect(process.env.MONGO_URI || 'mongodb://localhost:27017/wouldyou', { +connect(process.env.MONGO_URI, { useNewUrlParser: true, + serverSelectionTimeoutMS: 1000 }).then(() => console.log( `${ChalkAdvanced.white('Database')} ${ChalkAdvanced.gray( '>', diff --git a/yarn.lock b/yarn.lock index b103382b..419fd836 100644 --- a/yarn.lock +++ b/yarn.lock @@ -251,7 +251,7 @@ asynckit@^0.4.0: resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== -axios@^0.27.2, axios@^0.27.3: +axios@^0.27.2: version "0.27.2" resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== @@ -259,6 +259,15 @@ axios@^0.27.2, axios@^0.27.3: follow-redirects "^1.14.9" form-data "^4.0.0" +axios@^0.27.3: + version "1.1.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.1.2.tgz#8b6f6c540abf44ab98d9904e8daf55351ca4a331" + integrity sha512-bznQyETwElsXl2RK7HLLwb5GPpOLlycxHCtrpDR/4RqqBzjARaOTo3jz4IgtntWUYee7Ne4S8UHd92VCuzPaWA== + dependencies: + follow-redirects "^1.15.0" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + balanced-match@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" @@ -891,7 +900,7 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787" integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== -follow-redirects@^1.14.9: +follow-redirects@^1.14.9, follow-redirects@^1.15.0: version "1.15.2" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== @@ -1633,6 +1642,11 @@ proxy-addr@~2.0.7: forwarded "0.2.0" ipaddr.js "1.9.1" +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + pstree.remy@^1.1.8: version "1.1.8" resolved "https://registry.yarnpkg.com/pstree.remy/-/pstree.remy-1.1.8.tgz#c242224f4a67c21f686839bbdb4ac282b8373d3a"