From c06c0be2e7520ceaf5284472d0d99c7417aceb7a Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 20 Mar 2025 01:47:19 -0400 Subject: New command; New logging feature; QOTD (WIP) --- bot/src/commands/timer.js | 51 +++++++++++++++++++++++++++++++++++++ bot/src/events/ClientReady.js | 5 ++-- bot/src/events/GuildMemberUpdate.js | 26 +++++++++++++++++++ bot/src/events/MessageCreate.js | 2 ++ bot/src/events/MessageDelete.js | 2 +- bot/src/events/MessageUpdate.js | 5 ++-- bot/src/init.js | 4 ++- bot/src/plugins/chatbot.js | 1 + bot/src/plugins/eval.js | 3 +++ bot/src/plugins/qotd.js | 28 ++++++++++++++++++++ bot/src/storage/activities.js | 9 ++++--- bot/src/utils/i18n.js | 1 + 12 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 bot/src/commands/timer.js create mode 100644 bot/src/events/GuildMemberUpdate.js create mode 100644 bot/src/plugins/chatbot.js create mode 100644 bot/src/plugins/eval.js create mode 100644 bot/src/plugins/qotd.js create mode 100644 bot/src/utils/i18n.js (limited to 'bot/src') diff --git a/bot/src/commands/timer.js b/bot/src/commands/timer.js new file mode 100644 index 0000000..3b3807e --- /dev/null +++ b/bot/src/commands/timer.js @@ -0,0 +1,51 @@ +import { SlashCommandBuilder, time, TimestampStyles } from 'discord.js'; + +export default { + data: new SlashCommandBuilder() + .setName('timer') + .setDescription('Reminds you for something after a certain amount of time.') + .addIntegerOption(option => + option + .setName('seconds') + .setDescription('Seconds to wait for.')) + .addIntegerOption(option => + option + .setName('minutes') + .setDescription('Minutes to wait for.')) + .addIntegerOption(option => + option + .setName('hours') + .setDescription('Hours to wait for.')) + .addStringOption(option => + option + .setName('message') + .setDescription('Enter the message you want to be reminded of.')), + async execute(interaction) { + let timer = 0; + const seconds = interaction.options.getInteger('seconds') || 0; + const minutes = interaction.options.getInteger('minutes') || 0; + const hours = interaction.options.getInteger('hours') || 0; + const message = interaction.options.getString('message'); + const content = message ? `Reason: \`\`\`\n${message}\n\`\`\`` : ''; + if (!seconds && !minutes && !hours) return await interaction.reply({ content: 'Please provide a time to wait for.', ephemeral: true }); + + timer = seconds + (minutes * 60) + (hours * 3600); + + if (timer > 0) { + const date = new Date(); + date.setSeconds(date.getSeconds() + timer); + const timeString = time(date, TimestampStyles.RelativeTime); + await interaction.reply(`Timer set! Will remind you ${timeString}`); + } + + setTimeout(async function(){ + if (interaction.guild) { + let remindChannel = interaction.client.channels.cache.get(interaction.channel.id); + if (!remindChannel) return console.error('Unknown channel.'); + return await remindChannel.send({ content: `${interaction.user}, You have been reminded.${message ? '\n\n' + content : ''}` }); + } else { + return await interaction.user.send({ content: `You have been reminded.${message ? '\n\n' + content : ''}` }); + } + }, timer * 1000); + } +}; diff --git a/bot/src/events/ClientReady.js b/bot/src/events/ClientReady.js index ec22ba6..c806d6a 100644 --- a/bot/src/events/ClientReady.js +++ b/bot/src/events/ClientReady.js @@ -3,6 +3,7 @@ import { readFileSync } from 'node:fs'; import { activities } from '../storage/activities.js'; import { readyMsg, abEmbedColour } from '../storage/consts.js'; +// import { QuoteOfTheDay } from '../plugins/qotd.js'; const { version: abVersion } = JSON.parse(readFileSync('./package.json', 'utf-8')); function botActivity(client) { @@ -13,8 +14,7 @@ function botActivity(client) { name: activity.name, type: activity.type }], - status: 'online', - afk: false, + status: 'online' }); console.log(`[>] Updated bot presence to "${activity.name}"`); } @@ -29,6 +29,7 @@ export default { console.log(`[i] Running version ${abVersion} | Serving in ${client.guilds.cache.size} guilds`); await botActivity(client); + //await QuoteOfTheDay(client); if (readyMsg) { const readyEmbed = new EmbedBuilder() diff --git a/bot/src/events/GuildMemberUpdate.js b/bot/src/events/GuildMemberUpdate.js new file mode 100644 index 0000000..77906c7 --- /dev/null +++ b/bot/src/events/GuildMemberUpdate.js @@ -0,0 +1,26 @@ +import { EmbedBuilder, Events } from 'discord.js'; +import { guildSettings } from '../models/guild-settings.js'; + +export default { + name: Events.GuildMemberUpdate, + async execute(member, newMember) { + const guildSetting = await guildSettings.findOne({ where: { guildID: member.guild.id } }); + if (!guildSetting || !guildSetting.logChannelID) return; + if (!member.nickname || member.nickname === newMember.nickname) return; + + const logEmbed = new EmbedBuilder() + .setAuthor({ name: 'AleeBot Logging', iconURL: member.client.user.avatarURL() }) + .setDescription(`${member.user} has changed their nickname.`) + .addFields( + { name: 'Old Nickname: ', value: `${member.nickname}`, inline: true }, + { name: 'New Nickname: ', value: `${newMember.nickname}`, inline: true }, + ) + .setColor('#ffff1a') + .setTimestamp(); + + let guildMember = member.client.channels.cache.get(guildSetting.logChannelID); + if (!guildMember) return; + + await guildMember.send({ embeds: [logEmbed] }); + } +}; diff --git a/bot/src/events/MessageCreate.js b/bot/src/events/MessageCreate.js index 8234c5b..406539e 100644 --- a/bot/src/events/MessageCreate.js +++ b/bot/src/events/MessageCreate.js @@ -14,6 +14,8 @@ export default { const args = msg.content.slice(`${msg.client.user}`.length).trim(); + // TODO: Check if the person mentions a specific command that executes eval, then start a message collection. + if (msg.mentions.has(msg.client.user)) { if (!guildSetting.ollamaEnabled) return; if (!ollamaGlobal) return msg.reply('Sorry, the LLM chatbot feature has been turned off.'); diff --git a/bot/src/events/MessageDelete.js b/bot/src/events/MessageDelete.js index dc9b53f..86e3dd8 100644 --- a/bot/src/events/MessageDelete.js +++ b/bot/src/events/MessageDelete.js @@ -9,7 +9,7 @@ export default { const guildSetting = await guildSettings.findOne({ where: { guildID: msg.guild.id } }); if (!guildSetting || !guildSetting.logChannelID) return; - const useEmbedFields = msg.content.length <= 1023; + const useEmbedFields = msg.content.length <= 1024; const logEmbed = new EmbedBuilder() .setAuthor({ name: 'AleeBot Logging', iconURL: msg.client.user.avatarURL() }) diff --git a/bot/src/events/MessageUpdate.js b/bot/src/events/MessageUpdate.js index b73d6ac..4f4a593 100644 --- a/bot/src/events/MessageUpdate.js +++ b/bot/src/events/MessageUpdate.js @@ -8,8 +8,8 @@ export default { if (!msg.guild || !guildSetting || !guildSetting.logChannelID) return; if (msg.content === newmsg.content) return; - const useEmbedFields = msg.content.length <= 1023 && - newmsg.content.length <= 1023; + const useEmbedFields = msg.content.length <= 1024 && + newmsg.content.length <= 1024; const logEmbed = new EmbedBuilder() .setAuthor({ name: 'AleeBot Logging', iconURL: msg.client.user.avatarURL() }) @@ -33,6 +33,7 @@ export default { } else { let messageContent = []; messageContent.push(`Before:\n${msg.content}`); + messageContent.push('-----------------------------------'); messageContent.push(`After:\n${newmsg.content}`); messageContent = messageContent.join('\n'); diff --git a/bot/src/init.js b/bot/src/init.js index 8da3783..3557757 100644 --- a/bot/src/init.js +++ b/bot/src/init.js @@ -5,7 +5,9 @@ import { command } from './handlers/command.js'; //import { deployCommands } from './util/deploy.js'; export async function init(client) { - await syncDB(); + if (process.env.NODE_ENV === 'development') { + await syncDB(); + } //deployCommands().then(() => console.log('[>] Deployed commands')); await apiServer(client); await event(client).then(() => console.log('[>] Event module loaded')); diff --git a/bot/src/plugins/chatbot.js b/bot/src/plugins/chatbot.js new file mode 100644 index 0000000..f4095a2 --- /dev/null +++ b/bot/src/plugins/chatbot.js @@ -0,0 +1 @@ +// add llm feature here diff --git a/bot/src/plugins/eval.js b/bot/src/plugins/eval.js new file mode 100644 index 0000000..47b3988 --- /dev/null +++ b/bot/src/plugins/eval.js @@ -0,0 +1,3 @@ +export async function evaluation() { + +} diff --git a/bot/src/plugins/qotd.js b/bot/src/plugins/qotd.js new file mode 100644 index 0000000..a6ea73e --- /dev/null +++ b/bot/src/plugins/qotd.js @@ -0,0 +1,28 @@ +import { EmbedBuilder } from 'discord.js'; +import { abEmbedColour } from '../storage/consts.js'; +import { quote as quoteDB } from '../models/quote.js'; + +export async function QuoteOfTheDay(client) { + const channels = ['606602551634296968', '341669022179262464']; + const quoteList = await quoteDB.findAll({ attributes: ['id'] }); + const random = crypto.getRandomValues(new Uint32Array(1)); + + if (quoteList.length === 0) return console.log('[i] No quotes are currently in the database.'); + + let quoteID = quoteList[random[0] % quoteList.length].id; + + const quote = await quoteDB.findOne({ where: { id: quoteID } }); + + let userSubmitter = await client.users.fetch(quote.submitter); + + 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({ embeds: [quoteEmbed] }); + } +} diff --git a/bot/src/storage/activities.js b/bot/src/storage/activities.js index df3bab5..155eeaa 100644 --- a/bot/src/storage/activities.js +++ b/bot/src/storage/activities.js @@ -70,7 +70,7 @@ export const activities = [ { name: 'Hacking SherCorp', type: 4 }, { name: 'Games with Tari', type: 0 }, { name: 'Decommissioning Meta Runners', type: 4 }, - { name: 'Installing Meta Runners', type: 0 }, + { name: 'Installing Meta Runners', type: 4 }, { name: '90% bug free!', type: 4 }, { name: 'Google Wallet', type: 0 }, { name: 'Apple Pay', type: 0 }, @@ -82,7 +82,7 @@ export const activities = [ { name: 'Evaluating JavaScript code', type: 4 }, { name: 'Evaluating C# code', type: 4 }, { name: 'Forkbombing FMP', type: 4 }, - { name: 'Merging with DLAP', type: 0 }, + { name: 'Merging with DLAP', type: 4 }, { name: 'Now asbestos-free!', type: 4 }, { name: 'May contain nuts!', type: 4 }, { name: 'MythOS', type: 0 }, @@ -91,10 +91,11 @@ export const activities = [ { name: 'Apple Vision Pro', type: 0 }, { name: 'What is Web3?', type: 4 }, { name: 'GNU\'s NOT UNIX!', type: 4 }, - { name: 'Linux, but actually GNU/Linux', type: 4 }, + { name: 'Linux, but actually GNU/Linux', type: 0 }, { name: 'Debloating my ThinkPad', type: 4 }, { name: 'Turbotastic!', type: 4 }, { name: 'Artemis', type: 0 }, - { name: 'The Beat 92.5 - Montreal\'s Perfect Mix', type: 2 }, + { name: 'Helping Kapuletti Industries', type: 4 }, + { name: 'The Beat 92.5 - MTL\'s Perfect Mix', type: 2 }, { name: `Now running on Discord.JS ${discordVersion}!`, type: 4 } ]; diff --git a/bot/src/utils/i18n.js b/bot/src/utils/i18n.js new file mode 100644 index 0000000..2b4a4be --- /dev/null +++ b/bot/src/utils/i18n.js @@ -0,0 +1 @@ +// Feature for AleeBot 4.1 -- cgit v1.2.3