From bc64422fdf34e512509cfc931569715828047c24 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Wed, 26 Mar 2025 16:02:25 -0400 Subject: QOTD implemented; Removed readyMsg (replaced with NODE_ENV); More activities --- bot/Dockerfile | 6 +----- bot/bun.lockb | Bin 134376 -> 134763 bytes bot/package.json | 1 + bot/src/api/routes/settings.js | 5 ++++- bot/src/events/ClientReady.js | 8 ++++---- bot/src/plugins/qotd.js | 44 +++++++++++++++++++++++++---------------- bot/src/storage/activities.js | 36 +++++++++++++++++++++++++++++++-- bot/src/storage/consts.js | 1 - 8 files changed, 71 insertions(+), 30 deletions(-) (limited to 'bot') diff --git a/bot/Dockerfile b/bot/Dockerfile index c21fd47..ae74f3a 100644 --- a/bot/Dockerfile +++ b/bot/Dockerfile @@ -2,12 +2,8 @@ FROM oven/bun:latest WORKDIR /bot -COPY package.json ./ - -COPY bun.lockb ./ +COPY . . RUN bun install -COPY . . - ENTRYPOINT ["bun", "start"] diff --git a/bot/bun.lockb b/bot/bun.lockb index 86b95df..070f3d3 100644 Binary files a/bot/bun.lockb and b/bot/bun.lockb differ diff --git a/bot/package.json b/bot/package.json index 4c937be..cdfb6a3 100644 --- a/bot/package.json +++ b/bot/package.json @@ -17,6 +17,7 @@ "discord.js": "^14.18.0", "express": "^4.21.2", "jsonwebtoken": "^9.0.2", + "node-cron": "^3.0.3", "ollama": "^0.5.14", "sequelize": "^6.37.6", "sqlite3": "^5.1.7" diff --git a/bot/src/api/routes/settings.js b/bot/src/api/routes/settings.js index 794d302..3722fd2 100644 --- a/bot/src/api/routes/settings.js +++ b/bot/src/api/routes/settings.js @@ -10,7 +10,10 @@ export function settingsRouter(client) { try { const settings = await guildSettings.findOne({ where: { guildID: req.params.id } }); - if (!settings) return res.sendStatus(404); + if (!settings) { + await guildSettings.create({ guildID: req.params.id }); + return res.status(200).send({ message: 'Added new guild' }); + } let channels = []; diff --git a/bot/src/events/ClientReady.js b/bot/src/events/ClientReady.js index 6a6b097..7f998ad 100644 --- a/bot/src/events/ClientReady.js +++ b/bot/src/events/ClientReady.js @@ -2,8 +2,8 @@ import { EmbedBuilder, Events, version } from 'discord.js'; import { readFileSync } from 'node:fs'; import { activities } from '../storage/activities.js'; -import { readyMsg, abEmbedColour } from '../storage/consts.js'; -// import { QuoteOfTheDay } from '../plugins/qotd.js'; +import { abEmbedColour } from '../storage/consts.js'; +import { QuoteOfTheDay } from '../plugins/qotd.js'; const { version: abVersion } = JSON.parse(readFileSync('./package.json', 'utf-8')); function botActivity(client) { @@ -29,9 +29,9 @@ export default { console.log(`[i] Running version ${abVersion} | Serving in ${client.guilds.cache.size} guilds`); await botActivity(client); - //await QuoteOfTheDay(client); + await QuoteOfTheDay(client); - if (readyMsg) { + if (process.env.NODE_ENV !== 'development') { const readyEmbed = new EmbedBuilder() .setAuthor({ name: 'AleeBot Status', iconURL: client.user.avatarURL() }) .setDescription('AleeBot has started') 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 ]}); + } + }); } diff --git a/bot/src/storage/activities.js b/bot/src/storage/activities.js index 155eeaa..73051de 100644 --- a/bot/src/storage/activities.js +++ b/bot/src/storage/activities.js @@ -4,6 +4,7 @@ const { version: abVersion } = JSON.parse(readFileSync('./package.json', 'utf-8' export const activities = [ { name: `AleeBot ${abVersion}`, type: 4 }, + { name: `Now running on Discord.JS ${discordVersion}!`, type: 4 }, { name: 'Coding bytes', type: 4 }, { name: 'Drawing shapes', type: 4 }, { name: 'Fighting Quad', type: 4 }, @@ -40,7 +41,7 @@ export const activities = [ { name: 'Monica Is Going To Cosume You', type: 4 }, { name: 'BLĂ…HAJ', type: 4 }, { name: 'ShiftOS', type: 0 }, - { name: 'Histacom', type: 2 }, + { name: 'Histacom', type: 0 }, { name: 'Wall Street', type: 4 }, { name: 'Mac OS X Jaguar', type: 0 }, { name: 'Abunchoo 12.10', type: 0 }, @@ -77,10 +78,12 @@ export const activities = [ { name: 'Splatoon 3', type: 0 }, { name: 'Super Mario 64', type: 0 }, { name: 'Minceraft', type: 0 }, + { name: 'Minecraft', type: 0 }, { name: 'Mario Kart 8', type: 0 }, { name: 'bnbmc', type: 0 }, { name: 'Evaluating JavaScript code', type: 4 }, { name: 'Evaluating C# code', type: 4 }, + { name: 'Evaluating Rust code', type: 4 }, { name: 'Forkbombing FMP', type: 4 }, { name: 'Merging with DLAP', type: 4 }, { name: 'Now asbestos-free!', type: 4 }, @@ -96,6 +99,35 @@ export const activities = [ { name: 'Turbotastic!', type: 4 }, { name: 'Artemis', type: 0 }, { name: 'Helping Kapuletti Industries', type: 4 }, + { name: 'Frank (The Game)', type: 0 }, + { name: 'Blasting earbuds with the Maraca Cracker 9000', type: 4 }, + { name: 'Scarlet Fire', type: 2 }, { name: 'The Beat 92.5 - MTL\'s Perfect Mix', type: 2 }, - { name: `Now running on Discord.JS ${discordVersion}!`, type: 4 } + { name: 'Removing unsafe code', type: 4 }, + { name: 'Google Pixel 7', type: 0 }, + { name: 'FreeSO', type: 0 }, + { name: 'The Sims 1', type: 0 }, + { name: 'The Sims 2', type: 0 }, + { name: 'The Sims 3', type: 0 }, + { name: 'The Sims 4', type: 0 }, + { name: 'inZOI', type: 0 }, + { name: 'Paralives', type: 0 }, + { name: 'CollabVM', type: 0 }, + { name: '86Box', type: 0 }, + { name: 'AIM', type: 0 }, + { name: 'Software Inc.', type: 0 }, + { name: 'Nintendo GameBoy', type: 0 }, + { name: 'Nintendo GameBoy Advanced', type: 0 }, + { name: 'Nintendo DS', type: 0 }, + { name: 'Nintendo DSi', type: 0 }, + { name: 'Nintendo 3DS', type: 0 }, + { name: 'Nintendo Entertainment System', type: 0 }, + { name: 'Super Nintendo Entertainment System', type: 0 }, + { name: 'Nintendo 64', type: 0 }, + { name: 'Nintendo Gamecube', type: 0 }, + { name: 'Nintendo Wii', type: 0 }, + { name: 'Nintendo Wii U', type: 0 }, + { name: 'Nintendo Switch', type: 0 }, + { name: 'Nintendo Switch 2', type: 0 }, + { name: 'Sony Playstation 2', type: 0 } ]; diff --git a/bot/src/storage/consts.js b/bot/src/storage/consts.js index 9a408f4..231f5ca 100644 --- a/bot/src/storage/consts.js +++ b/bot/src/storage/consts.js @@ -1,5 +1,4 @@ export const abEmbedColour = '#0066a6'; -export const readyMsg = false; export const ollamaGlobal = true; export const ollamaModel = 'aleebot-deepseek'; export const featureSuggestChannel = '427495678390960148'; -- cgit v1.2.3