Skip to content

Commit

Permalink
Merge pull request #43 from Would-You-Bot/dailymsg
Browse files Browse the repository at this point in the history
Dailymsg
  • Loading branch information
mezotv authored Oct 14, 2022
2 parents 32c34a2 + 08292cf commit e407f24
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/util/Models/guildModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const guildProfile = new Schema(
},
dailyDay: {
type: Number,
default: 0,
},
nsfw: {
type: Boolean,
Expand Down
24 changes: 10 additions & 14 deletions src/util/dailyMsgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
};
};
3 changes: 2 additions & 1 deletion src/util/dbHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'>',
Expand Down
18 changes: 16 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,23 @@ 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==
dependencies:
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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit e407f24

Please # to comment.