aboutsummaryrefslogtreecommitdiff
path: root/bot/src/plugins
diff options
context:
space:
mode:
authorAndrew Lee <andrew@alee14.me>2025-03-26 16:02:25 -0400
committerAndrew Lee <andrew@alee14.me>2025-03-26 16:04:06 -0400
commitbc64422fdf34e512509cfc931569715828047c24 (patch)
tree11cc24121519b5d2fd4c65907e1979d6f426981b /bot/src/plugins
parentf374c5bda7a9453266e46e77da3631d655998c68 (diff)
downloadAleeBot-bc64422fdf34e512509cfc931569715828047c24.tar.gz
AleeBot-bc64422fdf34e512509cfc931569715828047c24.tar.bz2
AleeBot-bc64422fdf34e512509cfc931569715828047c24.zip
QOTD implemented; Removed readyMsg (replaced with NODE_ENV); More activities
Diffstat (limited to 'bot/src/plugins')
-rw-r--r--bot/src/plugins/qotd.js44
1 files changed, 27 insertions, 17 deletions
diff --git a/bot/src/plugins/qotd.js b/bot/src/plugins/qotd.js
index a6ea73e..16ae507 100644
--- a/bot/src/plugins/qotd.js
+++ b/bot/src/plugins/qotd.js
@@ -1,28 +1,38 @@
import { EmbedBuilder } from 'discord.js';
import { abEmbedColour } from '../storage/consts.js';
import { quote as quoteDB } from '../models/quote.js';
+import { guildSettings } from '../models/guild-settings.js';
+import { schedule } from 'node-cron';
-export async function QuoteOfTheDay(client) {
- const channels = ['606602551634296968', '341669022179262464'];
- const quoteList = await quoteDB.findAll({ attributes: ['id'] });
- const random = crypto.getRandomValues(new Uint32Array(1));
+export function QuoteOfTheDay(client) {
+ schedule('0 0 * * *', async () => {
+ const enabledGuilds = await guildSettings.findAll({
+ where: { qotdToggle: true },
+ attributes: ['guildID', 'qotdChannelID']
+ });
- if (quoteList.length === 0) return console.log('[i] No quotes are currently in the database.');
+ const channels = enabledGuilds
+ .filter(guild => guild.qotdChannelID)
+ .map(guild => guild.qotdChannelID);
- let quoteID = quoteList[random[0] % quoteList.length].id;
+ const quoteList = await quoteDB.findAll({attributes: ['id']});
+ const random = crypto.getRandomValues(new Uint32Array(1));
- const quote = await quoteDB.findOne({ where: { id: quoteID } });
+ let quoteID = quoteList[random[0] % quoteList.length].id;
- let userSubmitter = await client.users.fetch(quote.submitter);
+ const quote = await quoteDB.findOne({where: {id: quoteID}});
- const quoteEmbed = new EmbedBuilder()
- .setAuthor({ name: quote.author, iconURL: quote.authorImage })
- .setDescription(quote.quote)
- .setColor(abEmbedColour)
- .setFooter({ text: `- ${quote.year}\nSubmitted by ${userSubmitter.username}` });
+ let userSubmitter = await client.users.fetch(quote.submitter);
- for (const channel of channels) {
- let qotdChannel = client.channels.cache.get(channel);
- await qotdChannel.send({ embeds: [quoteEmbed] });
- }
+ const quoteEmbed = new EmbedBuilder()
+ .setAuthor({name: quote.author, iconURL: quote.authorImage})
+ .setDescription(quote.quote)
+ .setColor(abEmbedColour)
+ .setFooter({text: `- ${quote.year}\nSubmitted by ${userSubmitter.username}`});
+
+ for (const channel of channels) {
+ let qotdChannel = client.channels.cache.get(channel);
+ await qotdChannel.send({ content: 'New Quote of the Day!', embeds: [quoteEmbed ]});
+ }
+ });
}