From cf1382d88c5e3298923c8cb243b7bc5751e68b53 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 2 Mar 2025 22:27:57 -0500 Subject: Ported more commands; Made embed colour a const; Cleanup --- bot/api/server.js | 75 --------------- bot/package.json | 2 +- bot/src/api/server.js | 75 +++++++++++++++ bot/src/bot.js | 6 +- bot/src/commands/about.js | 4 +- bot/src/commands/avatar.js | 21 +++- bot/src/commands/info.js | 3 +- bot/src/commands/settings.js | 10 ++ bot/src/commands/userinfo.js | 21 ++++ bot/src/events/ClientReady.js | 12 ++- bot/src/events/InteractionCreate.js | 12 ++- bot/src/storage/activities.js | 184 ++++++++++++++++++------------------ bot/src/storage/consts.js | 1 + 13 files changed, 239 insertions(+), 187 deletions(-) delete mode 100644 bot/api/server.js create mode 100644 bot/src/api/server.js create mode 100644 bot/src/commands/settings.js create mode 100644 bot/src/commands/userinfo.js create mode 100644 bot/src/storage/consts.js (limited to 'bot') diff --git a/bot/api/server.js b/bot/api/server.js deleted file mode 100644 index ac4f8ca..0000000 --- a/bot/api/server.js +++ /dev/null @@ -1,75 +0,0 @@ -import express from 'express'; -import cors from 'cors'; - -import 'dotenv/config'; -import { readFileSync } from 'node:fs'; - -const app = express(); - -export const apiServer = (client) => { - app.use(cors()); // Allow cross-origin requests - app.use(express.json()); - - app.get('/api/version', (req, res) => { - const { version } = JSON.parse(readFileSync('./package.json', 'utf-8')); - res.json({ - version: version - }); - - }); - - app.get('/api/uptime', (req, res) => { - res.json({ - uptime: client.uptime - }); - }); - - app.get('/api/servers', (req, res) => { - const guildsInfo = []; - - if (client.guilds.cache.size === 0) { - res.json({ - message: 'No servers found' - }); - } else { - client.guilds.cache.forEach((guild) => { - const guildInfo = { - name: guild.name, - members: guild.memberCount, - id: guild.id - }; - guildsInfo.push(guildInfo); - }); - } - - res.json(guildsInfo); - - }); - - app.post('/api/leave', (req, res) => { - const { id } = req.body; - let guild = client.guilds.cache.get(id); - - try { - guild.leave().then(guild => { - res.json({ - guild: guild.name, - left: true - }); - }); - - } catch (error) { - console.error('Error leaving server:', error); - res.status(500).res.json({ - guild: guild.name, - left: false - }); - } - }); - - // Start the server - app.listen(process.env.port, () => { - console.log(`[i] Starting API at http://localhost:${process.env.port}`); - }); -}; - diff --git a/bot/package.json b/bot/package.json index a343f58..1adf119 100644 --- a/bot/package.json +++ b/bot/package.json @@ -1,6 +1,6 @@ { "name": "aleebot", - "version": "4.0.0", + "version": "4.0.0 Beta", "main": "src/bot.js", "type": "module", "author": "Andrew Lee", diff --git a/bot/src/api/server.js b/bot/src/api/server.js new file mode 100644 index 0000000..ac4f8ca --- /dev/null +++ b/bot/src/api/server.js @@ -0,0 +1,75 @@ +import express from 'express'; +import cors from 'cors'; + +import 'dotenv/config'; +import { readFileSync } from 'node:fs'; + +const app = express(); + +export const apiServer = (client) => { + app.use(cors()); // Allow cross-origin requests + app.use(express.json()); + + app.get('/api/version', (req, res) => { + const { version } = JSON.parse(readFileSync('./package.json', 'utf-8')); + res.json({ + version: version + }); + + }); + + app.get('/api/uptime', (req, res) => { + res.json({ + uptime: client.uptime + }); + }); + + app.get('/api/servers', (req, res) => { + const guildsInfo = []; + + if (client.guilds.cache.size === 0) { + res.json({ + message: 'No servers found' + }); + } else { + client.guilds.cache.forEach((guild) => { + const guildInfo = { + name: guild.name, + members: guild.memberCount, + id: guild.id + }; + guildsInfo.push(guildInfo); + }); + } + + res.json(guildsInfo); + + }); + + app.post('/api/leave', (req, res) => { + const { id } = req.body; + let guild = client.guilds.cache.get(id); + + try { + guild.leave().then(guild => { + res.json({ + guild: guild.name, + left: true + }); + }); + + } catch (error) { + console.error('Error leaving server:', error); + res.status(500).res.json({ + guild: guild.name, + left: false + }); + } + }); + + // Start the server + app.listen(process.env.port, () => { + console.log(`[i] Starting API at http://localhost:${process.env.port}`); + }); +}; + diff --git a/bot/src/bot.js b/bot/src/bot.js index 07b13a8..7f1f41a 100644 --- a/bot/src/bot.js +++ b/bot/src/bot.js @@ -2,12 +2,12 @@ import { Client, GatewayIntentBits } from 'discord.js'; import 'dotenv/config'; import { event } from './handlers/event.js'; import { command } from './handlers/command.js'; -import { apiServer } from '../api/server.js'; +import { apiServer } from './api/server.js'; const client = new Client({ intents: [GatewayIntentBits.Guilds] }); -command(client).then(() => console.log('[i] Command module loaded')); -event(client).then(() => console.log('[i] Event module loaded')); +command(client).then(() => console.log('[>] Command module loaded')); +event(client).then(() => console.log('[>] Event module loaded')); apiServer(client); if (process.argv.indexOf('--beta') === -1) { diff --git a/bot/src/commands/about.js b/bot/src/commands/about.js index c75391a..8d3efab 100644 --- a/bot/src/commands/about.js +++ b/bot/src/commands/about.js @@ -6,6 +6,7 @@ import { ButtonStyle } from 'discord.js'; import { readFileSync } from 'node:fs'; +import { abEmbedColour } from '../storage/consts.js'; const { version } = JSON.parse(readFileSync('./package.json', 'utf-8')); @@ -18,11 +19,12 @@ export default { .setAuthor({ name: `AleeBot ${version}`, iconURL: interaction.client.user.avatarURL() }) .addFields( { name: 'About AleeBot', value: 'AleeBot is an all-in-one bot that\'s made from the Discord.JS API!' }, + { name: 'Servers', value: `${interaction.client.guilds.cache.size}` }, { name: 'License', value: 'GNU General Public License v3.0' }, { name: 'Contributors', value: '- <@297201585090723841> (Uptime command from 2.x)' } ) .setFooter({ text: '© Copyright 2017-2025 Andrew Lee Projects' }) - .setColor('#1fd619'); + .setColor(abEmbedColour); let Buttons = new ActionRowBuilder() .addComponents( diff --git a/bot/src/commands/avatar.js b/bot/src/commands/avatar.js index 2c3cdeb..3d98608 100644 --- a/bot/src/commands/avatar.js +++ b/bot/src/commands/avatar.js @@ -7,16 +7,27 @@ export default { .addUserOption(option => option .setName('username') - .setDescription('The user to get the avatar of.') - .setRequired(false)), + .setDescription('The user to get the avatar of.')) + .addBooleanOption(option => + option + .setName('server') + .setDescription('Gets the member\'s server profile picture.')), async execute(interaction) { const username = interaction.options.getUser('username'); + const server = interaction.options.getBoolean('server'); + + if (username && server) { + const member = interaction.guild.members.cache.get(username.id); + return await interaction.reply(member.avatarURL({ dynamic: true, format: 'png', size: 1024 })); + } else if (server) { + return await interaction.reply(interaction.member.avatarURL({ dynamic: true, format: 'png', size: 1024 })); + } - if(!username) { - await interaction.reply(interaction.user.avatarURL({ dynamic: true, format: 'png', size: 1024 })); + if (!username) { + return await interaction.reply(interaction.user.avatarURL({ dynamic: true, format: 'png', size: 1024 })); } else { - await interaction.reply(username.avatarURL({ dynamic: true, format: 'png', size: 1024 })); + return await interaction.reply(username.avatarURL({ dynamic: true, format: 'png', size: 1024 })); } } }; diff --git a/bot/src/commands/info.js b/bot/src/commands/info.js index e9de440..64d8f7a 100644 --- a/bot/src/commands/info.js +++ b/bot/src/commands/info.js @@ -1,5 +1,6 @@ import { SlashCommandBuilder, EmbedBuilder, version } from 'discord.js'; import { hostname, platform, release } from 'os'; +import { abEmbedColour } from '../storage/consts.js'; export default { data: new SlashCommandBuilder() @@ -15,7 +16,7 @@ export default { { name: 'OS Platform: ', value: platform(), inline: true }, { name: 'OS Version: ', value: release(), inline: true } ) - .setColor('#1fd619'); + .setColor(abEmbedColour); return await interaction.reply({ embeds: [embed] }); } }; diff --git a/bot/src/commands/settings.js b/bot/src/commands/settings.js new file mode 100644 index 0000000..a04d1c2 --- /dev/null +++ b/bot/src/commands/settings.js @@ -0,0 +1,10 @@ +import { SlashCommandBuilder } from 'discord.js'; + +export default { + data: new SlashCommandBuilder() + .setName('settings') + .setDescription('User settings for AleeBot.'), + async execute(interaction) { + return await interaction.reply(`**PONG!** :ping_pong: ${Math.round(interaction.client.ws.ping)} ms`); + } +}; diff --git a/bot/src/commands/userinfo.js b/bot/src/commands/userinfo.js new file mode 100644 index 0000000..01b7577 --- /dev/null +++ b/bot/src/commands/userinfo.js @@ -0,0 +1,21 @@ +import { SlashCommandBuilder, EmbedBuilder } from 'discord.js'; +import { abEmbedColour } from '../storage/consts.js'; + +export default { + data: new SlashCommandBuilder() + .setName('userinfo') + .setDescription('Information about a user.'), + async execute(interaction) { + const userEmbed = new EmbedBuilder() + .setAuthor({ name: interaction.user.tag, iconURL: interaction.user.avatarURL() }) + .setDescription('User Information') + .setThumbnail(interaction.user.avatarURL()) + .addFields( + { name: 'Names', value: `**Display Name:** ${interaction.member.displayName}\n**Username:** ${interaction.user.username}`}, + { name: 'Identity', value: `**User ID:** ${interaction.user.id}` }, + { name: 'Create and Join Times', value: `**Created At:** ${interaction.member.user.createdAt.toUTCString()}\n**Joined Guild At:** ${interaction.member.joinedAt.toUTCString()}`} + ) + .setColor(abEmbedColour); + return await interaction.reply({embeds: [userEmbed]}); + } +}; diff --git a/bot/src/events/ClientReady.js b/bot/src/events/ClientReady.js index c3c6055..335a2ac 100644 --- a/bot/src/events/ClientReady.js +++ b/bot/src/events/ClientReady.js @@ -1,21 +1,23 @@ import { Events } from 'discord.js'; import { readFileSync } from 'node:fs'; -import { activities as activity } from '../storage/activities.js'; +import { activities } from '../storage/activities.js'; +const { version } = JSON.parse(readFileSync('./package.json', 'utf-8')); function botActivity(client) { + const activity = activities[Math.floor(Math.random() * activities.length)]; + client.user.setPresence({ activities: [{ - name: activity[Math.floor(Math.random() * activity.length)] + name: activity.name, + type: activity.type }], status: 'online', afk: false, }); - console.log(`[>] Updated bot presence to "${client.user.presence.activities[0].name}"`); + console.log(`[>] Updated bot presence to "${activity.name}"`); } -const { version } = JSON.parse(readFileSync('./package.json', 'utf-8')); - export default { name: Events.ClientReady, once: true, diff --git a/bot/src/events/InteractionCreate.js b/bot/src/events/InteractionCreate.js index 4e39241..eadef09 100644 --- a/bot/src/events/InteractionCreate.js +++ b/bot/src/events/InteractionCreate.js @@ -2,7 +2,7 @@ import { Events, MessageFlags } from 'discord.js'; export default { name: Events.InteractionCreate, - async execute(interaction, client) { + async execute(interaction) { if (!interaction.isChatInputCommand()) return; const command = interaction.client.commands.get(interaction.commandName); @@ -10,10 +10,14 @@ export default { if (!command) return; try { - await command.execute(interaction, client); + await command.execute(interaction); } catch (e) { - console.error(e); - await interaction.reply({ content: `Something went wrong. Send the following error message to Alee:\n\`\`\`${e}\`\`\``, flags: MessageFlags.Ephemeral }); + console.log(e); + if (interaction.replied || interaction.deferred) { + await interaction.followUp({ content: `Something went wrong. The following error message:\n\`\`\`${e}\`\`\``, flags: MessageFlags.Ephemeral }); + } else { + await interaction.reply({ content: `Something went wrong. The following error message:\n\`\`\`${e}\`\`\``, flags: MessageFlags.Ephemeral }); + } } } }; diff --git a/bot/src/storage/activities.js b/bot/src/storage/activities.js index 4702594..b50f2dd 100644 --- a/bot/src/storage/activities.js +++ b/bot/src/storage/activities.js @@ -4,98 +4,98 @@ const { version: abVersion } = JSON.parse(readFileSync('./package.json', 'utf-8' const activities = [ - `AleeBot ${abVersion}`, - 'Coding bytes', - 'Drawing shapes', - 'Fighting Quad', - 'Installing Windows 11', - 'Breaking Windows 10', - 'Beating up big tech', - 'Deleting Google', - 'Deleting Apple', - 'Deleting System32', - 'Deleting /usr/bin/', - 'Watering down the Apple walled garden', - 'Reticulating splines', - 'Generating world', - 'Never punch a tree...', - 'Collecting data', - 'Dag dag!', - 'Developed by Andrew Lee', - 'When will 2.13 release?', - 'Alert Irruption !!!', - 'when', - 'Frying Shrimpbot', - 'RADIATION BABY', - 'Frivolously Spending', - 'Thanks! @Victor', - 'MCA DiscoVision', - 'Werq', - 'Pombo', - 'Ian Clary\'s First Day At FrivoloCo!', - 'Squid Airlines', - 'AirCS Race', - 'FrivoloCo', - 'I WANT 2 ORDER', - 'I REALLY WANT 2 ORDER', - 'Monica Is Going To Cosume You', - 'BLÅHAJ', - 'ShiftOS', - 'Histacom', - 'Wall Street', - 'Mac OS X Jaguar', - 'Abunchoo 12.10', - 'MikeOS', - 'theBeat', - 'FRESHMusicPlayer', - 'theShell', - 'theBeat', - 'theSlate', - 'theDesk', - 'Ultra Jump Mania!', - 'Battle Blaze', - 'Tempest', - 'Turbo Crash 9', - 'Pocket Gakusei', - 'Hidden Heroes', - 'Skybreakers', - 'Always Running', - 'Only Up', - 'Trade', - 'Breeze', - 'Steady', - 'Bluejay', - 'Exposing TAS-Corp', - 'Fighting Evelyn Claythorne', - 'Frying Dr. Sheridan', - 'Hacking SherCorp', - 'Games with Tari', - 'Decommissioning Meta Runners', - 'Installing Meta Runners', - '90% bug free!', - 'Google Wallet', - 'Apple Pay', - 'Splatoon 3', - 'Super Mario 64', - 'Minceraft', - 'Mario Kart 8', - 'bnbmc', - 'Evaluating JavaScript code', - 'Evaluating C# code', - 'Forkbombing FMP', - 'Merging with DLAP', - 'Now asbestos-free!', - 'May contain nuts!', - 'MythOS', - 'Also try Scratch!', - 'Funky!', - 'Apple Vision Pro', - 'What is Web3?', - 'GNU\'s NOT UNIX!', - 'Linux, but actually GNU/Linux', - 'Debloating my ThinkPad', - 'Turbotastic!', - `Now running on Discord.JS ${discordVersion}!` + { name: `AleeBot ${abVersion}`, type: 4 }, + { name: 'Coding bytes', type: 4 }, + { name: 'Drawing shapes', type: 4 }, + { name: 'Fighting Quad', type: 4 }, + { name: 'Installing Windows 11', type: 4 }, + { name: 'Breaking Windows 10', type: 4 }, + { name: 'Beating up big tech', type: 4 }, + { name: 'Deleting Google', type: 4 }, + { name: 'Deleting Apple', type: 4 }, + { name: 'Deleting System32', type: 4 }, + { name: 'Deleting /usr/bin/', type: 4 }, + { name: 'Watering down the Apple walled garden', type: 4 }, + { name: 'Reticulating splines', type: 4 }, + { name: 'Generating world', type: 4 }, + { name: 'Never punch a tree...', type: 4 }, + { name: 'Collecting data', type: 4 }, + { name: 'Dag dag!', type: 4 }, + { name: 'Developed by Andrew Lee', type: 4 }, + { name: 'When will 2.13 release?', type: 4 }, + { name: 'Alert Irruption !!!', type: 4}, + { name: 'when', type: 4 }, + { name: 'Frying Shrimpbot', type: 4 }, + { name: 'RADIATION BABY', type: 4 }, + { name: 'Frivolously Spending', type: 4 }, + { name: 'Thanks! @Victor', type: 4 }, + { name: 'MCA DiscoVision', type: 2 }, + { name: 'Werq', type: 2 }, + { name: 'Pombo', type: 4 }, + { name: 'Ian Clary\'s First Day At FrivoloCo!', type: 0 }, + { name: 'Squid Airlines', type: 0 }, + { name: 'AirCS Race', type: 1 }, + { name: 'FrivoloCo', type: 2 }, + { name: 'I WANT 2 ORDER', type: 4 }, + { name: 'I REALLY WANT 2 ORDER', type: 4 }, + { name: 'Monica Is Going To Cosume You', type: 4 }, + { name: 'BLÅHAJ', type: 4 }, + { name: 'ShiftOS', type: 0 }, + { name: 'Histacom', type: 2 }, + { name: 'Wall Street', type: 4 }, + { name: 'Mac OS X Jaguar', type: 0 }, + { name: 'Abunchoo 12.10', type: 0 }, + { name: 'MikeOS', type: 0 }, + { name: 'theBeat', type: 0 }, + { name: 'FRESHMusicPlayer', type: 0 }, + { name: 'theShell', type: 0 }, + { name: 'theBeat', type: 0 }, + { name: 'theSlate', type: 0 }, + { name: 'theDesk', type: 0 }, + { name: 'Ultra Jump Mania!', type: 0 }, + { name: 'Battle Blaze', type: 0 }, + { name: 'Tempest', type: 0 }, + { name: 'Turbo Crash 9', type: 0 }, + { name: 'Pocket Gakusei', type: 0 }, + { name: 'Hidden Heroes', type: 0 }, + { name: 'Skybreakers', type: 0 }, + { name: 'Always Running', type: 0 }, + { name: 'Only Up', type: 0 }, + { name: 'Trade', type: 0 }, + { name: 'Breeze', type: 0 }, + { name: 'Steady', type: 0 }, + { name: 'Bluejay', type: 0 }, + { name: 'Exposing TAS-Corp', type: 4 }, + { name: 'Fighting Evelyn Claythorne', type: 4 }, + { name: 'Frying Dr. Sheridan', type: 4 }, + { name: 'Hacking SherCorp', type: 4 }, + { name: 'Games with Tari', type: 0 }, + { name: 'Decommissioning Meta Runners', type: 4 }, + { name: 'Installing Meta Runners', type: 0 }, + { name: '90% bug free!', type: 4 }, + { name: 'Google Wallet', type: 0 }, + { name: 'Apple Pay', type: 0 }, + { name: 'Splatoon 3', type: 0 }, + { name: 'Super Mario 64', type: 0 }, + { name: 'Minceraft', 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: 'Forkbombing FMP', type: 4 }, + { name: 'Merging with DLAP', type: 0 }, + { name: 'Now asbestos-free!', type: 4 }, + { name: 'May contain nuts!', type: 4 }, + { name: 'MythOS', type: 0 }, + { name: 'Also try Scratch!', type: 4 }, + { name: 'Funky!', type: 4 }, + { 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: 'Debloating my ThinkPad', type: 4 }, + { name: 'Turbotastic!', type: 4 }, + { name: `Now running on Discord.JS ${discordVersion}!`, type: 4 } ]; export { activities }; diff --git a/bot/src/storage/consts.js b/bot/src/storage/consts.js new file mode 100644 index 0000000..89f1b8a --- /dev/null +++ b/bot/src/storage/consts.js @@ -0,0 +1 @@ +export const abEmbedColour = '#0066a6'; -- cgit v1.2.3