From cc3bcfa137fcab337e509b380784fbe7ed6bb240 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Fri, 3 Jan 2020 14:44:02 -0500 Subject: added eslint --- storage/settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'storage/settings.json') diff --git a/storage/settings.json b/storage/settings.json index 05117e9..83932cc 100644 --- a/storage/settings.json +++ b/storage/settings.json @@ -1,4 +1,4 @@ { - "abVersion": "2.12.0", - "prefix": "ab:" + "abVersion": "2.13.0 Beta", + "prefix": "abb:" } -- cgit v1.2.3 From 08a026ae7c9dc201740a7ae837a6090283f36252 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 29 Jul 2021 16:07:01 -0400 Subject: New branch name --- storage/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'storage/settings.json') diff --git a/storage/settings.json b/storage/settings.json index 83932cc..8f0e530 100644 --- a/storage/settings.json +++ b/storage/settings.json @@ -1,4 +1,4 @@ { - "abVersion": "2.13.0 Beta", + "abVersion": "2.13.0 Alpha Temp Branch", "prefix": "abb:" } -- cgit v1.2.3 From 0c0155a4d207611fb3d975f9e7e56d04fff63d44 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sat, 14 Oct 2023 00:16:49 -0400 Subject: Docker; Removed packages; Removed binaryworks refs --- .dockerignore | 2 + Dockerfile | 15 +++++ To be worked on/addquote.js | 132 ++++++++++++++++++++++++++++++++++++++++++++ bot_discord.js | 66 ++++++++++++---------- commands/addquote.js | 61 -------------------- commands/help.js | 5 +- commands/interrogate.js | 4 +- commands/quote.js | 12 ++-- commands/serverinfo.js | 6 +- commands/slowdown.js | 2 +- commands/suggest.js | 6 +- commands/suggestfeature.js | 14 ++--- commands/userinfo.js | 2 +- package.json | 8 +-- storage/activities.js | 4 +- storage/settings.json | 2 +- 16 files changed, 218 insertions(+), 123 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 To be worked on/addquote.js delete mode 100644 commands/addquote.js (limited to 'storage/settings.json') diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5171c54 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1256d22 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM node:alpine + +WORKDIR /usr/src/bot + +COPY package.json ./ + +COPY tokens.json ./ + +COPY yarn.lock ./ + +RUN yarn install + +COPY . . + +CMD ["node", "bot_discord.js"] diff --git a/To be worked on/addquote.js b/To be worked on/addquote.js new file mode 100644 index 0000000..5f2b9bc --- /dev/null +++ b/To be worked on/addquote.js @@ -0,0 +1,132 @@ +/** ************************************** + * + * AddQuote: Command for AleeBot + * Copyright (C) 2017-2021 Alee Productions + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * *************************************/ +const quoteDB = require('../models/quote'); +const { MessageEmbed } = require("discord.js"); +module.exports.run = async (client, message, args) => { + if (!['242775871059001344'].includes(message.author.id)) return message.reply('**This command is disabled due to a new system being implemented.**'); + try { + let newAuthor; + let newAuthorImage; + let newQuote; + let newYear; + + let quoteOriginator; + + let isSetupRunning = false; + + const setupProcess = [ + 'Provide the name of the author.', + 'Submit the image of the author\nYou need to use a picture link that ends in .jpg or .png (like those from IMGUR or Google Images), and the picture should be either 128x128 pixels or 512x512 pixels in size.', + 'Enter the quote', + 'Specify the year from which the quote originates.' + ] + + let setupMessage = "Welcome to the AleeBot Quote Setup!\n" + setupMessage += "Please follow these rules when submitting quotes\n" + setupMessage += "```1. Do not use profanity or offensive language.\n" + setupMessage += "2. Do not send any personal information.\n" + setupMessage += "3. Only send noteworthy quotes.```\n" + setupMessage += "We reserve the right to reject any quotes that do not meet our criteria.\n" + + let counter = 0 + + if (isSetupRunning) { + return await message.reply('You are already setting up the quote.'); + } + const filter = m => m.author.id === message.author.id + + isSetupRunning = true; + await message.reply(':arrow_left: Check your DMs to continue.') + await message.author.send(setupMessage); + await message.author.send(setupProcess[counter++]); + + const collector = message.channel.createMessageCollector({ + filter, + max: setupProcess.length, + time: 1000 * 60 + }); + + collector.on('collect', message => { + console.log(`Collected ${message.content} from ${message.author.tag}`) + if (setupProcess.length > setupProcess.length + 1) { + message.author.send(setupProcess[counter++]); + } + }); + + collector.on('end', collected => { + if (collected.size === 0 && collected.size < 2) { + message.author.send('Quote setup was not completed, rerun the command.') + } else { + let quoteContent = []; + + collected.forEach((message) => { + quoteContent.push(message.content) + }) + + newAuthor = quoteContent[0] + newAuthorImage = quoteContent[1] + newQuote = quoteContent[2] + newYear = quoteContent[3] + + const setupEmbed = new MessageEmbed() + .setAuthor('AleeBot Quote Setup', client.user.avatarURL()) + .setDescription('Are you happy with this quote?\nThis quote will be sent for manual approval') + .addField('Author', newAuthor) + .addField('Author Image (URL)', newAuthorImage) + .addField('Quote', newQuote) + .addField('Year', newYear); + + message.author.send({embeds:[setupEmbed]}) + quoteOriginator = message.author.tag + console.log(`This quote has been originated from ${quoteOriginator}`) + isSetupRunning = false; + } + + }); + + /*await quoteDB.create({ + author: newAuthor, + authorImage: newAuthorImage, + quote: newQuote, + year: newYear, + });*/ + + //let messageReact = await message.author.send({embeds: [setupEmbed]}); + /*await messageReact.react('🧑'); + await messageReact.react('📷'); + await messageReact.react('🖋️'); + await messageReact.react('📅');*/ + + } catch (error) { + console.log(error) + } +}; + +exports.conf = { + aliases: [], + guildOnly: true, +}; +exports.help = { + name: 'addquote', + description: 'Adds a quote to the database.', + usage: 'addquote', + category: '- Quote Commands', +}; + diff --git a/bot_discord.js b/bot_discord.js index 00afe45..b32e018 100644 --- a/bot_discord.js +++ b/bot_discord.js @@ -23,7 +23,7 @@ const client = new Discord.Client({ parse: ['users', 'roles'], repliedUser: true }, - intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MEMBERS'] + intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MEMBERS', 'GUILD_MESSAGE_REACTIONS'] }); const moment = require('moment'); const express = require('express'); @@ -37,12 +37,12 @@ const api = require('./tokens.json'); const { activity } = require('./storage/activities'); const active = new Map(); let autoRole = true; -let readyEmbedMessage = false; +let readyEmbedMessage = true; const ownerID = '242775871059001344'; let logChannel = '318874545593384970'; let statusChannelID = '606602551634296968'; let serverWhitelist = "243022206437687296"; -let roleWhitelist = "657426918416580614" +let roleWhitelist = "657426918416580614"; const log = (message) => { console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${message}`.white); @@ -130,23 +130,14 @@ rl.on('line', function(cmd) { } } break; - case 'channels': - if (!args[1]) { - console.log('[!] Please insert the guild\'s ID.'.yellow); - } else { - let guild = client.guilds.get(args[1]); - console.log('[i] These are the channels that this guild have:'.blue); - for ([id, channel, guild] of guild && client.channels) { - console.log(` Channel: #${channel.name} - ID: ${channel.id}`.blue); - } - } - break; case 'leave': if (!args[1]) { console.log('[!] Please insert the guild\'s ID.'.yellow); } else { - let guild = client.guilds.get(args[1]); - guild.leave(); + let guild = client.guilds.cache.get(args[1]); + guild.leave().then(guild => { + console.log(`AleeBot has left ${guild.name}`) + }); } break; case 'broadcast': @@ -155,11 +146,13 @@ rl.on('line', function(cmd) { } else { const broadcast = args.join(' ').slice(48); let guild = null; - guild = client.guilds.get(args[1]); + guild = client.guilds.cache.get(args[1]); let channel = null; - channel = guild.channels.get(args[2]); + channel = guild.channels.cache.get(args[2]); if (channel != null) { - channel.send(broadcast); + channel.send(`**[Broadcast]** ${broadcast}`); + } else { + console.log('[X] Broadcast cannot be blank'.red) } } break; @@ -169,12 +162,17 @@ rl.on('line', function(cmd) { let uptimeMinutes = Math.floor(uptime / 60); const minutes = uptime % 60; let hours = 0; + let days = 0; while (uptimeMinutes >= 60) { hours++; uptimeMinutes = uptimeMinutes - 60; } + while (hours >= 24) { + days++; + hours = hours - 24; + } const uptimeSeconds = minutes % 60; - console.log(`[i] AleeBot has been up for ${hours} hours, ${uptimeMinutes} minutes, and ${uptimeSeconds} seconds.`.blue); + console.log(`[i] AleeBot has been up for ${days} days, ${hours} hours, ${uptimeMinutes} minutes, and ${uptimeSeconds} seconds.`); break; case 'activity': console.log('[i] Generating new activity'.blue); @@ -198,7 +196,6 @@ rl.on('line', function(cmd) { case 'help': let msg = ('AleeBot '+ settings.abVersion +' Console Help\n\n'); msg += ('guilds - Shows all guilds that AleeBot\'s on.\n'); - msg += ('channels - Shows all the channels that the guilds have.\n'); msg += ('leave - Leaves a guild.\n'); msg += ('broadcast - Broadcasts a message to a server.\n'); msg += ('uptime - Shows the uptime for AleeBot.\n'); @@ -239,7 +236,7 @@ client.on('ready', async () => { .setDescription('AleeBot has started') .addField('Version', settings.abVersion, true) .addField('Discord.JS Version', Discord.version, true) - .addField('Prefix', `\`${settings.prefix}\``, true) + .addField('Prefix', `\`${settings.prefix}\``) .setColor('#5cd65c'); let statusChannel = client.channels.cache.get(statusChannelID); if (!statusChannel) return console.error('The status channel does not exist! Skipping.'); @@ -388,12 +385,25 @@ client.on('guildDelete', (guild) => { statusChannel.send({ embeds: [logEmbed]}); }); -/* -AutoPoster(api.dbltoken, client) - .on('posted', () => { - log('[>] Posted stats to Top.gg!'.blue); - }) -*/ +client.on("messageReactionAdd", async (reaction, user) => { + // When a reaction is received, check if the structure is partial + if (reaction.partial) { + // If the message this reaction belongs to was removed, the fetching might result in an API error which should be handled + try { + await reaction.fetch(); + } catch (error) { + console.error('Something went wrong when fetching the message:', error); + // Return as `reaction.message.author` may be undefined/null + return; + } + } + + // Now the message has been cached and is fully available + console.log(`${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`); + // The reaction is now also fully available and the properties will be reflected accurately: + console.log(`${reaction.count} user(s) have given the same reaction to this message!`); +}); + client.on('messageCreate', async(msg) => { if (!client.application?.owner) await client.application?.fetch(); if (msg.author.bot) return; diff --git a/commands/addquote.js b/commands/addquote.js deleted file mode 100644 index 477d891..0000000 --- a/commands/addquote.js +++ /dev/null @@ -1,61 +0,0 @@ -/** ************************************** - * - * AddQuote: Command for AleeBot - * Copyright (C) 2017-2021 Alee Productions - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * *************************************/ -const quoteDB = require('../models/quote'); -const Discord = require("discord.js"); -module.exports.run = async (client, message, args) => { - if (!['242775871059001344'].includes(message.author.id)) return message.reply('**This command is disabled due to a new system being implemented.**'); - try { - let newAuthor; - let newAuthorImage; - let newQuote; - let newYear; - - const quote = await quoteDB.create({ - author: newAuthor, - authorImage: newAuthorImage, - quote: newQuote, - year: newYear - }) - - const setupEmbed = new Discord.MessageEmbed() - .setTitle('AleeBot Quote Setup', client.user.avatarURL()) - .setDescription('Input the data to the following embed') - .addField('Author', newAuthor, true) - .addField('Author Image (URL)', newAuthorImage, true) - .addField('Quote', newQuote, true) - .addField('Year', newYear, true); - - message.reply({embeds: [setupEmbed]}); - } catch (error) { - console.log(error) - } -}; - -exports.conf = { - aliases: [], - guildOnly: true, -}; -exports.help = { - name: 'addquote', - description: 'Sets the guild prefix.', - usage: 'addquote [author] [authorImage] [quote] [year]', - category: '- Quote Commands', -}; - diff --git a/commands/help.js b/commands/help.js index e925754..0b9191e 100644 --- a/commands/help.js +++ b/commands/help.js @@ -40,8 +40,9 @@ module.exports.run = async (client, message) => { const prefix = prefixes[message.guild.id].prefixes; if (!message.guild.members.cache.get(client.user.id).permissions.has('EMBED_LINKS')) return message.reply('ERROR: AleeBot doesn\'t have the permission to send embed links, please enable them to use the full help.'); const embed = new Discord.MessageEmbed() - .setAuthor('AleeBot ' + require('../storage/settings.json').abVersion + ` Help | Serving in ${client.guilds.cache.size} servers`, client.user.avatarURL()) - .setDescription('[!] Currently on the Alpha-Temp branch. Meaning that experimental features are enabled in this bot...') + .setAuthor('AleeBot ' + require('../storage/settings.json').abVersion + ` Help`, client.user.avatarURL()) + .setDescription('Every command you input into AleeBot is `ab:`') + .setFooter(`Currently serving on ${client.guilds.cache.size} servers`) .setColor('#1fd619') categories.forEach(function(x) { diff --git a/commands/interrogate.js b/commands/interrogate.js index 16a1887..3386352 100644 --- a/commands/interrogate.js +++ b/commands/interrogate.js @@ -18,7 +18,7 @@ * * *************************************/ module.exports.run = async (client, message, args) => { - if (message.guild.id != '243022206437687296') return message.reply('This is a Binaryworks exclusive command.'); + if (message.guild.id !== '243022206437687296') return message.reply('This is a Binaryworks exclusive command.'); if (!message.member.permissions.has('BAN_MEMBERS')) return message.reply('It looks like that you don\'t have the permissions to jail members.'); if (!message.guild.members.cache.get(client.user.id).permissions.has('MANAGE_ROLES')) return message.reply('Uhh... I don\'t have permission to jail members.'); @@ -38,5 +38,5 @@ exports.help = { name: 'interrogate', description: 'Interrogates a member', usage: 'interrogate [user]', - category: '- Binaryworks Exclusive Commands', + category: '- ALP Exclusive Commands', }; diff --git a/commands/quote.js b/commands/quote.js index 81f9142..37f5714 100644 --- a/commands/quote.js +++ b/commands/quote.js @@ -24,23 +24,23 @@ module.exports.run = async (client, message, args) => { if (quoteID === undefined) { const quoteList = await quoteDB.findAll({ attributes: ['id'] }) - quoteID = Math.floor(Math.random() * (quoteList.length - 1)) + 1 + const random = crypto.getRandomValues(new Uint32Array(1)); + quoteID = quoteList[random[0] % quoteList.length].id; } const quote = await quoteDB.findOne({ where: { id: quoteID } }) if (quote) { - const embed = new MessageEmbed() - .setAuthor({ name: quote.author, iconURL: quote.authorImage}) + const quoteEmbed = new MessageEmbed() + .setAuthor({ name: quote.author, iconURL: quote.authorImage }) .setDescription(quote.quote) .setColor('#1fd619') .setFooter('- ' + quote.year); - await message.reply('Alright, here\'s your quote.') - await message.channel.send({embeds:[embed]}); + await message.reply({ content: 'Alright, here\'s your quote.', embeds: [quoteEmbed] }) } else { - message.reply('Cannot find quote'); + message.reply('Cannot find quote, specify the correct quote id.'); } diff --git a/commands/serverinfo.js b/commands/serverinfo.js index 0a2e077..67442a2 100644 --- a/commands/serverinfo.js +++ b/commands/serverinfo.js @@ -20,14 +20,14 @@ module.exports.run = async (client, message) => { const Discord = require('discord.js'); const listedChannels = []; + let guildOwner = await message.guild.fetchOwner(); let memberCountNoBots = await message.guild.members.fetch().then((members) => members.filter(member => !member.user.bot).size); const embed = new Discord.MessageEmbed() .setAuthor(`${message.guild.name}`, `${message.guild.iconURL()}`) .setDescription('Server Information') .setThumbnail(message.guild.iconURL()) - .addField('Server Name:', `${message.guild.name}`) - .addField('Server ID:', `${message.guild.id}`) - .addField('Created At:', `${message.guild.createdAt.toUTCString()}`) + .addField('Main Information', `**Server Name:** ${message.guild.name}\n**Server ID:** ${message.guild.id}\n**Server Owner:** ${guildOwner.user.tag}`) + .addField('Join Dates', `**Created At:** ${message.guild.createdAt.toUTCString()}\n**AleeBot Joined:** ${message.guild.joinedAt.toUTCString()}`) /*message.guild.channels.cacheType.forEach(channel => { listedChannels.push(channel) })*/ diff --git a/commands/slowdown.js b/commands/slowdown.js index 44d8230..55e441b 100644 --- a/commands/slowdown.js +++ b/commands/slowdown.js @@ -21,7 +21,7 @@ module.exports.run = async (client, message, args) => { if (!message.member.permissions.has('MANAGE_CHANNELS')) return message.reply('It looks like that you don\'t have the permissions to slowdown channels.'); if (isNaN(args[0])) return message.reply('Please input a valid number to slowdown a channel.'); await message.channel.setRateLimitPerUser(args[0]); - message.channel.send(`This channel has been slowdowned for ${args[0]} second(s).`); + message.channel.send(`This channel has been slowdown for ${args[0]} second(s).`); }; diff --git a/commands/suggest.js b/commands/suggest.js index 0ca21b8..b503139 100644 --- a/commands/suggest.js +++ b/commands/suggest.js @@ -18,7 +18,7 @@ * * *************************************/ module.exports.run = async (client, message, args) => { - if (message.guild.id != '243022206437687296') return message.reply('This is a Binaryworks exclusive command.'); + if (message.guild.id !== '243022206437687296') return message.reply('This is a Andrew Lee Projects exclusive command.'); const {MessageEmbed} = require('discord.js'); client.channels.cache.get('427495678390960148').send({ embeds: [ new MessageEmbed() @@ -39,7 +39,7 @@ exports.conf = { }; exports.help = { name: 'suggest', - description: 'Suggest a feature in Binaryworks.', + description: 'Suggest a feature in Andrew Lee Projects.', usage: 'suggest [suggestion]', - category: '- Binaryworks Exclusive Commands', + category: '- ALP Exclusive Commands', }; diff --git a/commands/suggestfeature.js b/commands/suggestfeature.js index c7623d2..21b6849 100644 --- a/commands/suggestfeature.js +++ b/commands/suggestfeature.js @@ -1,5 +1,5 @@ /**************************************** - * + * * SuggestFeature: Command for AleeBot * Copyright (C) 2017-2021 Alee Productions * @@ -15,11 +15,11 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * *************************************/ module.exports.run = async (client, message, args) => { const { MessageEmbed } = require('discord.js'); - + client.channels.cache.get('427495678390960148').send({ embeds: [ new MessageEmbed() .setColor('#1fd619') @@ -28,10 +28,10 @@ module.exports.run = async (client, message, args) => { .addField('Suggestion Contents', args.join(' ')) .setFooter(`Sending from ${message.guild.name}`, message.guild.iconURL())]} ); - await message.reply('Your suggestion has been shown to the Binaryworks discord server!'); - + await message.reply('Your suggestion has been shown to the Andrew Lee Projects discord server!'); + }; - + exports.conf = { aliases: [], guildOnly: false, @@ -42,4 +42,4 @@ exports.help = { usage: 'suggestfeature [suggestion]', category: '- General Commands', }; - + diff --git a/commands/userinfo.js b/commands/userinfo.js index a812dc4..bc7ec8e 100644 --- a/commands/userinfo.js +++ b/commands/userinfo.js @@ -23,7 +23,7 @@ module.exports.run = async (client, message) => { .setAuthor(message.author.tag, message.author.avatarURL()) .setDescription('User Information') .setThumbnail(message.author.avatarURL()) - .addField('Names', `**Username:** ${message.author.username}\n**Current Nickname:** ${message.member.displayName}`) + .addField('Names', `**Display Name:** ${message.member.displayName}\n**Username:** ${message.author.username}\n**Server Nickname:** ${message.member.displayName}`) .addField('Identity', `**User ID:** ${message.author.id} `) .addField('Create and Join Times', `**Created At:** ${message.member.user.createdAt.toUTCString()}\n**Joined Guild At:** ${message.member.joinedAt.toUTCString()}`) .setColor('#1fd619'); diff --git a/package.json b/package.json index 91c283c..4c23498 100644 --- a/package.json +++ b/package.json @@ -18,25 +18,19 @@ }, "homepage": "https://github.com/Alee14/AleeBot#readme", "dependencies": { - "@top-gg/sdk": "^3.1.2", "blessed": "^0.1.81", "colors": "^1.3.0", "discord.js": "^13.0.1", "eslint": "^7.1.0", "express": "^4.17.1", - "fs": "0.0.1-security", "git-last-commit": "^0.3.0", "i18next": "^19.4.4", "moment": "^2.21.0", - "mongoose": "^5.11.8", - "node-opus": "^0.3.0", "os": "^0.1.1", "parse-ms": "^1.0.1", "readline": "^1.3.0", "sequelize": "^6.30.0", - "sqlite3": "^5.1.6", - "topgg-autoposter": "^2.0.0", - "ytdl-core": "^0.20.4" + "sqlite3": "^5.1.6" }, "devDependencies": { "nodemon": "^2.0.2" diff --git a/storage/activities.js b/storage/activities.js index 418a038..2b2a286 100644 --- a/storage/activities.js +++ b/storage/activities.js @@ -87,12 +87,14 @@ const activities = [ 'MythOS', 'Also try Scratch!', 'Funky!', + 'Apple Vision Pro', 'What is Web3?', 'GNU\'s NOT UNIX!', 'Linux, but actually GNU/Linux', - 'Praise RMS!', + 'Praise RMS! (dont)', 'Praying to St IGNUcius', 'Debloating my ThinkPad', + 'Turbotastic!', 'Goddamn Idiotic Truckload of Windows', `Now running on Discord.JS ${version}!` ]; diff --git a/storage/settings.json b/storage/settings.json index 8f0e530..83932cc 100644 --- a/storage/settings.json +++ b/storage/settings.json @@ -1,4 +1,4 @@ { - "abVersion": "2.13.0 Alpha Temp Branch", + "abVersion": "2.13.0 Beta", "prefix": "abb:" } -- cgit v1.2.3 From 632ce4387c3458c87931528f4a047f0df103e5a7 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sat, 14 Oct 2023 00:23:17 -0400 Subject: Fixed some problems --- commands/help.js | 2 +- storage/settings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'storage/settings.json') diff --git a/commands/help.js b/commands/help.js index 0b9191e..7a824f1 100644 --- a/commands/help.js +++ b/commands/help.js @@ -41,7 +41,7 @@ module.exports.run = async (client, message) => { if (!message.guild.members.cache.get(client.user.id).permissions.has('EMBED_LINKS')) return message.reply('ERROR: AleeBot doesn\'t have the permission to send embed links, please enable them to use the full help.'); const embed = new Discord.MessageEmbed() .setAuthor('AleeBot ' + require('../storage/settings.json').abVersion + ` Help`, client.user.avatarURL()) - .setDescription('Every command you input into AleeBot is `ab:`') + .setDescription('Every command you input into AleeBot is `' + prefix + '`') .setFooter(`Currently serving on ${client.guilds.cache.size} servers`) .setColor('#1fd619') diff --git a/storage/settings.json b/storage/settings.json index 83932cc..b53fd84 100644 --- a/storage/settings.json +++ b/storage/settings.json @@ -1,4 +1,4 @@ { "abVersion": "2.13.0 Beta", - "prefix": "abb:" + "prefix": "ab:" } -- cgit v1.2.3 From f5de90ba89146008af78c16e798e216efccf0c50 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sat, 11 Jan 2025 11:55:18 -0500 Subject: Ability to add quotes, web interface, pending quotes --- api/server.js | 78 +++++++++++++++++ bot_discord.js | 30 +++---- commands/about.js | 3 +- commands/addquote.js | 198 +++++++++++++++++++++++++++--------------- commands/quote.js | 4 +- commands/setup.js | 6 +- deprecated/balance.js | 50 ----------- deprecated/buy.js | 114 ------------------------ deprecated/daily.js | 56 ------------ deprecated/pay.js | 60 ------------- models/quote.js | 27 +++++- package.json | 1 + storage/activities.js | 2 - storage/settings.json | 2 +- sync-database.js | 8 +- web/.gitignore | 24 +++++ web/.vscode/extensions.json | 4 + web/.vscode/launch.json | 11 +++ web/astro.config.mjs | 9 ++ web/bun.lockb | Bin 0 -> 172416 bytes web/package.json | 19 ++++ web/public/favicon.svg | 9 ++ web/src/components/Quotes.jsx | 86 ++++++++++++++++++ web/src/layouts/Layout.astro | 22 +++++ web/src/pages/index.astro | 29 +++++++ web/src/styles/Quote.css | 33 +++++++ web/tsconfig.json | 14 +++ yarn.lock | 12 ++- 28 files changed, 528 insertions(+), 383 deletions(-) create mode 100644 api/server.js delete mode 100644 deprecated/balance.js delete mode 100644 deprecated/buy.js delete mode 100644 deprecated/daily.js delete mode 100644 deprecated/pay.js create mode 100644 web/.gitignore create mode 100644 web/.vscode/extensions.json create mode 100644 web/.vscode/launch.json create mode 100644 web/astro.config.mjs create mode 100644 web/bun.lockb create mode 100644 web/package.json create mode 100644 web/public/favicon.svg create mode 100644 web/src/components/Quotes.jsx create mode 100644 web/src/layouts/Layout.astro create mode 100644 web/src/pages/index.astro create mode 100644 web/src/styles/Quote.css create mode 100644 web/tsconfig.json (limited to 'storage/settings.json') diff --git a/api/server.js b/api/server.js new file mode 100644 index 0000000..a918308 --- /dev/null +++ b/api/server.js @@ -0,0 +1,78 @@ +const express = require('express'); +const cors = require('cors'); +const { pendingQuote, quote: approvedQuote } = require('../models/quote.js'); + +const app = express(); +const PORT = 3000; + +const createServer = () => { + app.use(cors()); // Allow cross-origin requests + app.use(express.json()); + + // Endpoint to get all pending quotes + app.get('/api/pending-quotes', async (req, res) => { + try { + const quotes = await pendingQuote.findAll(); + res.json(quotes); + } catch (error) { + console.error('Error fetching quotes:', error); + res.status(500).send('Internal Server Error'); + } + }); + + app.post('/api/approve-quote', async (req, res) => { + const { id } = req.body; + try { + const quote = await pendingQuote.findByPk(id); + if (quote) { + await approvedQuote.create({ + author: quote.author, + quote: quote.quote, + year: quote.year, + authorImage: quote.authorImage + }); + await pendingQuote.destroy({ where: { id } }); + res.status(200).send('Quote approved'); + } else { + res.status(404).send('Quote not found'); + } + } catch (error) { + console.error('Error approving quote:', error); + res.status(500).send('Internal Server Error'); + } + }); + + app.post('/api/reject-quote', async (req, res) => { + const { id } = req.body; + try { + const quote = await pendingQuote.findByPk(id); + if (quote) { + await pendingQuote.destroy({ where: { id } }); + res.status(200).send('Quote rejected'); + } else { + res.status(404).send('Quote not found'); + } + } catch (error) { + console.error('Error rejecting quote:', error); + res.status(500).send('Internal Server Error'); + } + }); + + app.get('/api/version', (req, res) => { + const { abVersion } = require('../storage/settings.json'); + res.json(abVersion); + + }); + + app.get('/' , (req, res) => { + res.send('API for AleeBot'); + // Most likely going to redirect to the frontend + }); + + // Start the server + app.listen(PORT, () => { + console.log(`Server is running on http://localhost:${PORT}`); + }); +}; + +module.exports = createServer; diff --git a/bot_discord.js b/bot_discord.js index df2264f..8bfa7da 100644 --- a/bot_discord.js +++ b/bot_discord.js @@ -1,7 +1,7 @@ /** ************************************** * * AleeBot: Made for discord servers - * Copyright (C) 2017-2022 Andrew Lee Projects + * Copyright (C) 2017-2025 Andrew Lee Projects * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,17 +24,16 @@ const client = new Discord.Client({ parse: ['users', 'roles'], repliedUser: true }, - intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MEMBERS', 'GUILD_MESSAGE_REACTIONS'] + intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MEMBERS', 'GUILD_MESSAGE_REACTIONS', 'DIRECT_MESSAGES', 'DIRECT_MESSAGE_REACTIONS'] }); const moment = require('moment'); -const express = require('express'); const fs = require('fs'); const readline = require('readline'); const colors = require('colors'); //const i18next = require('i18next'); -const web = express(); const settings = require('./storage/settings.json'); const { activity } = require('./storage/activities'); +const createServer = require("./api/server"); const active = new Map(); let autoRole = true; let readyEmbedMessage = true; @@ -50,11 +49,11 @@ const log = (message) => { function botPresence() { client.user.setPresence({ - activities: [{ - name: activity[Math.floor(Math.random() * activity.length)] - }], - status: 'online', - afk: false, + activities: [{ + name: activity[Math.floor(Math.random() * activity.length)] + }], + status: 'online', + afk: false, }); log(`[>] Updated bot presence to "${client.user.presence.activities[0].name}"`.green); } @@ -65,7 +64,7 @@ const rl = readline.createInterface({ prompt: '> '.gray, }); -console.log(`AleeBot ${settings.abVersion}: Copyright (C) 2017-2023 Andrew Lee Projects`.gray); +console.log(`AleeBot ${settings.abVersion}: Copyright (C) 2017-2025 Andrew Lee Projects`.gray); console.log('This program comes with ABSOLUTELY NO WARRANTY; for details type `show w\'.'.gray); console.log('This is free software, and you are welcome to redistribute it'.gray); console.log('under certain conditions; type `show c\' for details.\n'.gray); @@ -219,13 +218,7 @@ client.on('ready', async () => { botPresence(); - web.get('/', (req, res) => { - res.send("Hello World! This is going to become the AleeBot dashboard..."); - }); - - web.listen(process.env.port, () => { - console.log(`Listening at https://localhost:${process.env.port}`) - }) + createServer(); setInterval(function() { botPresence(); @@ -286,7 +279,7 @@ client.on('guildMemberRemove', (member) => { client.on('messageUpdate', async (oldMessage, newMessage) => { - if (oldMessage.guild.id !== serverWhitelist) return; + if (!oldMessage.guild || oldMessage.guild.id !== serverWhitelist) return; if (oldMessage.content === newMessage.content) { return; } @@ -407,6 +400,7 @@ client.on("messageReactionAdd", async (reaction, user) => { client.on('messageCreate', async(msg) => { if (!client.application?.owner) await client.application?.fetch(); if (msg.author.bot) return; + if (!msg.guild) return; const prefixes = JSON.parse(fs.readFileSync('./storage/prefixes.json', 'utf8')); diff --git a/commands/about.js b/commands/about.js index 7272b6a..0ae756d 100644 --- a/commands/about.js +++ b/commands/about.js @@ -17,7 +17,6 @@ * along with this program. If not, see . * * *************************************/ -const {MessageButton} = require("discord.js"); module.exports.run = async (client, message) => { const { MessageEmbed, MessageButton, MessageActionRow } = require('discord.js'); @@ -30,7 +29,7 @@ module.exports.run = async (client, message) => { .addField('About AleeBot', 'AleeBot is an all-in-one bot that\'s made from the Discord.JS API!') .addField('License', 'GNU General Public License v3.0') .addField('Contributors', Contributors) - .setFooter('© Copyright 2017-2023 Andrew Lee Projects') + .setFooter('© Copyright 2017-2025 Andrew Lee Projects') .setColor('#1fd619'); let Buttons = new MessageActionRow() diff --git a/commands/addquote.js b/commands/addquote.js index 5f2b9bc..52f7b21 100644 --- a/commands/addquote.js +++ b/commands/addquote.js @@ -17,105 +17,164 @@ * along with this program. If not, see . * * *************************************/ -const quoteDB = require('../models/quote'); +const { pendingQuote } = require('../models/quote'); const { MessageEmbed } = require("discord.js"); -module.exports.run = async (client, message, args) => { - if (!['242775871059001344'].includes(message.author.id)) return message.reply('**This command is disabled due to a new system being implemented.**'); - try { - let newAuthor; - let newAuthorImage; - let newQuote; - let newYear; - - let quoteOriginator; +module.exports.run = async (client, message) => { + try { + let newAuthor, newAuthorImage, newQuote, newYear; let isSetupRunning = false; const setupProcess = [ - 'Provide the name of the author.', - 'Submit the image of the author\nYou need to use a picture link that ends in .jpg or .png (like those from IMGUR or Google Images), and the picture should be either 128x128 pixels or 512x512 pixels in size.', - 'Enter the quote', - 'Specify the year from which the quote originates.' - ] - - let setupMessage = "Welcome to the AleeBot Quote Setup!\n" - setupMessage += "Please follow these rules when submitting quotes\n" - setupMessage += "```1. Do not use profanity or offensive language.\n" - setupMessage += "2. Do not send any personal information.\n" - setupMessage += "3. Only send noteworthy quotes.```\n" - setupMessage += "We reserve the right to reject any quotes that do not meet our criteria.\n" + 'Provide the name of the author:', + 'Submit the image of the author:\nYou need to use a picture link that ends in .jpg or .png (like those from IMGUR or Google Images), and the picture should be either 128x128 pixels or 512x512 pixels in size.', + 'Enter the quote:', + 'Specify the year from which the quote originates:' + ]; + + async function createQuote() { + await pendingQuote.create({ + author: newAuthor, + authorImage: newAuthorImage, + quote: newQuote, + year: newYear, + }); + } - let counter = 0 + let setupMessage = "Welcome to the AleeBot Quote Setup!\n"; + setupMessage += "Please follow these rules when submitting quotes:\n"; + setupMessage += "```1. Do not use profanity or offensive language.\n"; + setupMessage += "2. Do not send any personal information.\n"; + setupMessage += "3. Only send noteworthy quotes.```\n"; + setupMessage += "We reserve the right to reject any quotes that do not meet our criteria.\n"; if (isSetupRunning) { - return await message.reply('You are already setting up the quote.'); + return await message.reply('You are already setting up a quote.'); } - const filter = m => m.author.id === message.author.id + + const filter = (m) => m.author.id === message.author.id; isSetupRunning = true; - await message.reply(':arrow_left: Check your DMs to continue.') - await message.author.send(setupMessage); - await message.author.send(setupProcess[counter++]); + await message.reply(':arrow_left: Check DMs to continue.'); + + const dmChannel = await message.author.createDM(); + await dmChannel.send(setupMessage); + await dmChannel.send(setupProcess[0]); - const collector = message.channel.createMessageCollector({ + let counter = 1; + const collector = dmChannel.createMessageCollector({ filter, max: setupProcess.length, - time: 1000 * 60 + time: 1000 * 120 }); - collector.on('collect', message => { - console.log(`Collected ${message.content} from ${message.author.tag}`) - if (setupProcess.length > setupProcess.length + 1) { - message.author.send(setupProcess[counter++]); + collector.on('collect', async () => { + if (counter < setupProcess.length) { + await dmChannel.send(setupProcess[counter++]); } }); - collector.on('end', collected => { - if (collected.size === 0 && collected.size < 2) { - message.author.send('Quote setup was not completed, rerun the command.') + collector.on('end', async (collected) => { + if (collected.size < setupProcess.length) { + dmChannel.send('Quote setup was not completed. Please rerun the command.'); } else { - let quoteContent = []; - - collected.forEach((message) => { - quoteContent.push(message.content) - }) - - newAuthor = quoteContent[0] - newAuthorImage = quoteContent[1] - newQuote = quoteContent[2] - newYear = quoteContent[3] + const quoteContent = collected.map((m) => m.content); + newAuthor = quoteContent[0]; + newAuthorImage = quoteContent[1]; + newQuote = quoteContent[2]; + newYear = quoteContent[3]; const setupEmbed = new MessageEmbed() .setAuthor('AleeBot Quote Setup', client.user.avatarURL()) - .setDescription('Are you happy with this quote?\nThis quote will be sent for manual approval') + .setDescription('Are you happy with this quote?\nThis quote will be sent for manual approval automatically in 2 minutes.') .addField('Author', newAuthor) .addField('Author Image (URL)', newAuthorImage) .addField('Quote', newQuote) - .addField('Year', newYear); + .addField('Year', newYear) + .setColor('#1fd619'); + + let messageReact = await dmChannel.send({embeds: [setupEmbed]}); + await messageReact.react('🧑'); + await messageReact.react('📷'); + await messageReact.react('🖋️'); + await messageReact.react('📅'); + await messageReact.react('✅'); + await messageReact.react('❌'); + + const reactionFilter = (reaction, user) => { + return ['🧑', '📷', '🖋️', '📅', '✅', '❌'].includes(reaction.emoji.name) && user.id === message.author.id; + }; + + const reactionCollector = messageReact.createReactionCollector({ + filter: reactionFilter, + time: 1000 * 120 + }); + + reactionCollector.on('collect', async (reaction) => { + switch (reaction.emoji.name) { + case '🧑': + await dmChannel.send('You selected the author. Please provide the name of the author.'); + const authorResponse = await dmChannel.awaitMessages({ filter, max: 1, time: 60000 }); + if (authorResponse.size) newAuthor = authorResponse.first().content; + await dmChannel.send('Updated author name.'); + break; + case '📷': + await dmChannel.send('You selected the author image. Please provide the image URL.'); + const imageResponse = await dmChannel.awaitMessages({ filter, max: 1, time: 60000 }); + if (imageResponse.size) newAuthorImage = imageResponse.first().content; + await dmChannel.send('Updated author URL.'); + break; + case '🖋️': + await dmChannel.send('You selected the quote. Please provide the quote.'); + const quoteResponse = await dmChannel.awaitMessages({ filter, max: 1, time: 60000 }); + if (quoteResponse.size) newQuote = quoteResponse.first().content; + await dmChannel.send('Updated quote.'); + break; + case '📅': + await dmChannel.send('You selected the year. Please provide the year.'); + const yearResponse = await dmChannel.awaitMessages({ filter, max: 1, time: 60000 }); + if (yearResponse.size) newYear = yearResponse.first().content; + await dmChannel.send('Updated year.'); + break; + case '✅': + reactionCollector.stop('completed'); + break; + case '❌': + reactionCollector.stop('cancelled'); + break; + } + + const updatedEmbed = new MessageEmbed() + .setAuthor('AleeBot Quote Setup', client.user.avatarURL()) + .setDescription('Are you happy with this quote?\nThis quote will be sent for manual approval automatically in 2 minutes.') + .addField('Author', newAuthor) + .addField('Author Image (URL)', newAuthorImage) + .addField('Quote', newQuote) + .addField('Year', newYear) + .setColor('#1fd619'); + + await messageReact.edit({embeds: [updatedEmbed]}); + }); + + reactionCollector.on('end', async (collected, reason) => { + if (reason === 'cancelled') { + isSetupRunning = false; + dmChannel.send('Cancelling quote setup.'); + } else if (reason === 'completed') { + dmChannel.send('Sending this quote for manual approval.'); + isSetupRunning = false; + await createQuote(); + } else { + dmChannel.send('You have not responded. Sending this quote for manual approval.'); + isSetupRunning = false; + await createQuote(); + } + }); - message.author.send({embeds:[setupEmbed]}) - quoteOriginator = message.author.tag - console.log(`This quote has been originated from ${quoteOriginator}`) - isSetupRunning = false; } - }); - - /*await quoteDB.create({ - author: newAuthor, - authorImage: newAuthorImage, - quote: newQuote, - year: newYear, - });*/ - - //let messageReact = await message.author.send({embeds: [setupEmbed]}); - /*await messageReact.react('🧑'); - await messageReact.react('📷'); - await messageReact.react('🖋️'); - await messageReact.react('📅');*/ - } catch (error) { - console.log(error) + console.error(error); } }; @@ -123,6 +182,7 @@ exports.conf = { aliases: [], guildOnly: true, }; + exports.help = { name: 'addquote', description: 'Adds a quote to the database.', diff --git a/commands/quote.js b/commands/quote.js index 37f5714..02699cd 100644 --- a/commands/quote.js +++ b/commands/quote.js @@ -18,7 +18,7 @@ * * *************************************/ module.exports.run = async (client, message, args) => { - const quoteDB = require('../models/quote'); + const { quote: quoteDB } = require('../models/quote'); const { MessageEmbed } = require('discord.js'); let quoteID = args[0]; @@ -38,7 +38,7 @@ module.exports.run = async (client, message, args) => { .setColor('#1fd619') .setFooter('- ' + quote.year); - await message.reply({ content: 'Alright, here\'s your quote.', embeds: [quoteEmbed] }) + await message.reply({ embeds: [quoteEmbed] }) } else { message.reply('Cannot find quote, specify the correct quote id.'); } diff --git a/commands/setup.js b/commands/setup.js index 5c2f232..380e85e 100644 --- a/commands/setup.js +++ b/commands/setup.js @@ -20,14 +20,12 @@ module.exports.run = async (client, message) => { if (!['242775871059001344', message.guild.ownerId].includes(message.author.id)) return message.reply(':warning: You must be a server owner or be the creator of the bot to access this command.'); - message.reply('Look at your DMs.'); - //message.reply("This feature is coming soon. Stay tuned!"); + message.reply(':arrow_left: Check DMs to continue.'); const Discord = require('discord.js'); const setupEmbed = new Discord.MessageEmbed() .setTitle('AleeBot Setup', client.user.avatarURL()) .setDescription('Select the options') - .addField('Chat Logs', 'channelid', true) - .addField('Joining & Leaving Logs', 'placeholder', true) + .addField('Logging', 'channelid', true) .addField('Broadcast', 'placeholder', true) .addField('Broadcast', 'placeholder', true); diff --git a/deprecated/balance.js b/deprecated/balance.js deleted file mode 100644 index bf7618c..0000000 --- a/deprecated/balance.js +++ /dev/null @@ -1,50 +0,0 @@ -/** ************************************** - * - * Balance: Command for AleeBot - * Copyright (C) 2017-2021 Alee Productions - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * *************************************/ -module.exports.run = async (client, message) => { - const db = require('quick.db'); - const {MessageEmbed} = require('discord.js'); - - const user = message.mentions.users.first() || message.author; - - let balance = await db.fetch(`userBalance_${user.id}`); - - if (balance === null) { - db.set(`userBalance_${message.author.id}`, 0); - balance = 0; - } - const embed = new MessageEmbed() - .setDescription('**AleeCorp Bank**') - .addField('Account Holder: ', user.username, true) - .addField('Account Balance: ', balance, true) - .setColor('#1fd619'); - - message.channel.send({embed}); -}; - -exports.conf = { - aliases: ['bal', 'money'], - guildOnly: false, -}; -exports.help = { - name: 'balance', - description: 'Checks the balance of AleeBot', - usage: 'balance [@someone (optional)]', - category: '- Economy Commands', -}; diff --git a/deprecated/buy.js b/deprecated/buy.js deleted file mode 100644 index 98d4fcf..0000000 --- a/deprecated/buy.js +++ /dev/null @@ -1,114 +0,0 @@ -/** ************************************** - * - * Buy: Command for AleeBot - * Copyright (C) 2017-2021 Alee Productions - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * *************************************/ -module.exports.run = async (client, message, args) => { -const Discord = require('discord.js'); -const fs = require('fs') -const db = require('quick.db'); -const items = JSON.parse(fs.readFileSync('./storage/items.json', 'utf8')); - - let categories = []; - - if (!args.join(" ")) { - - - for (var i in items) { - - - if (!categories.includes(items[i].type)) { - categories.push(items[i].type) - } - - } - - - const embed = new Discord.MessageEmbed() - .setDescription(`Available Items`) - .setColor('#1fd619') - - for (var i = 0; i < categories.length; i++) { - - var tempDesc = ''; - - for (var c in items) { - if (categories[i] === items[c].type) { - - tempDesc += `${items[c].name} - ${items[c].price}$ - ${items[c].desc}\n`; - - } - - } - - embed.addField(categories[i], tempDesc); - - } - - - return message.channel.send({ - embed - }); - - - } - - let itemName = ''; - let itemPrice = 0; - let itemDesc = ''; - - for (var i in items) { - if (args.join(" ").trim().toUpperCase() === items[i].name.toUpperCase()) { - itemName = items[i].name; - itemPrice = items[i].price; - itemDesc = items[i].desc; - } - } - - - if (itemName === '') { - return message.channel.send(`Item ${args.join(" ").trim()} not found.`) - } - - let selfBalance = await db.fetch(`userBalance_${message.author.id}`); - - if (selfBalance === null) { - db.set(`userBalance_${message.author.id}`, 0); - selfBalance = 0 - } - - if (itemPrice > selfBalance) return message.reply('You don\'t have enough money for this item.') - - db.subtract(`userBalance_${message.author.id}`, itemPrice); - - if (itemName === 'Programmer Role') { - message.guild.members.get(message.author.id).addRole(message.guild.roles.find("name", "Programmers")); - } - - message.channel.send('You bought ' + itemName + '!'); -}; - -exports.conf = { - aliases: [], - guildOnly: false, -}; -exports.help = { - name: 'buy', - description: 'Buy things.', - usage: 'buy [item]', - category: '- Economy Commands', -}; diff --git a/deprecated/daily.js b/deprecated/daily.js deleted file mode 100644 index 4a38f26..0000000 --- a/deprecated/daily.js +++ /dev/null @@ -1,56 +0,0 @@ -/** ************************************** - * - * Daily: Command for AleeBot - * Copyright (C) 2017-2021 Alee Productions - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * *************************************/ -const db = require('quick.db'); -ms = require('parse-ms'); - -module.exports.run = async (client, message) => { - const cooldown = 8.64e+7; - const amount = 100; - - const lastDaily = await db.fetch(`lastDaily_${message.author.id}`); - - if (lastDaily !== null && cooldown - (Date.now() - lastDaily) > 0) { - const timeObj = ms(cooldown - (Date.now() - lastDaily)); - - message.reply(`You already collected your money, please wait **${timeObj.hours}h ${timeObj.minutes}m**!`); - } else { - message.channel.send(`You have successfully collected $${amount} dollars!`); - - const balance = await db.fetch(`userBalance_${message.author.id}`); - - if (balance == null) { - db.set(`userBalance_${message.author.id}`, 0); - } - - db.set(`lastDaily_${message.author.id}`, Date.now()); - db.add(`userBalance_${message.author.id}`, 100); - } -}; - -exports.conf = { - aliases: [], - guildOnly: false, -}; -exports.help = { - name: 'daily', - description: 'This gives you money everyday.', - usage: 'daily', - category: '- Economy Commands', -}; diff --git a/deprecated/pay.js b/deprecated/pay.js deleted file mode 100644 index 42e0f28..0000000 --- a/deprecated/pay.js +++ /dev/null @@ -1,60 +0,0 @@ -/** ************************************** - * - * Pay: Command for AleeBot - * Copyright (C) 2017-2021 Alee Productions - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * *************************************/ - -module.exports.run = async (client, message, args) => { - const db = require('quick.db'); - if (!message.mentions.members.first()) return message.reply('Please mention a user...'); - - const targetMember = message.mentions.members.first(); - const amount = parseInt(args.join(' ').replace(targetMember, '')); - - if (isNaN(amount)) return message.reply('Please define an amount.'); - - let targetBalance = await db.fetch(`userBalance_${targetMember.id}`); - let selfBalance = await db.fetch(`userBalance_${message.author.id}`); - - if (targetBalance === null) { - db.set(`userBalance_${targetMember.id}`, 0); - targetBalance = 0; - } - - if (selfBalance === null) { - db.set(`userBalance_${message.author.id}`, 0); - selfBalance = 0; - } - - if (amount > selfBalance) return message.reply('Sorry you don\'t have enough money.'); - - db.add(`userBalance_${targetMember.id}`, amount); - db.subtract(`userBalance_${message.author.id}`, amount); - - message.reply(`Successfully transfered $${amount} to ${targetMember.user}`); -}; - -exports.conf = { - aliases: ['transfer'], - guildOnly: false, -}; -exports.help = { - name: 'pay', - description: 'You can pay others!', - usage: 'pay [@user] [interger]', - category: '- Economy Commands', -}; diff --git a/models/quote.js b/models/quote.js index f31b472..eab4f57 100644 --- a/models/quote.js +++ b/models/quote.js @@ -26,4 +26,29 @@ const quote = sequelize.define('quotes', { }) -module.exports = quote +const pendingQuote = sequelize.define('pending-quotes', { + id: { + type: Sequelize.INTEGER, + autoIncrement: true, + primaryKey: true + }, + author: { + type: Sequelize.STRING, + allowNull: false + }, + authorImage: { + type: Sequelize.STRING, + allowNull: false + }, + quote: { + type: Sequelize.TEXT, + allowNull: false + }, + year: { + type: Sequelize.STRING, + allowNull: false + } + +}) + +module.exports = { quote, pendingQuote }; diff --git a/package.json b/package.json index 6e07caa..9584d19 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "dependencies": { "blessed": "^0.1.81", "colors": "^1.3.0", + "cors": "^2.8.5", "discord.js": "^13.0.1", "dotenv": "^16.3.1", "eslint": "^7.1.0", diff --git a/storage/activities.js b/storage/activities.js index 2b2a286..5d0161e 100644 --- a/storage/activities.js +++ b/storage/activities.js @@ -92,10 +92,8 @@ const activities = [ 'GNU\'s NOT UNIX!', 'Linux, but actually GNU/Linux', 'Praise RMS! (dont)', - 'Praying to St IGNUcius', 'Debloating my ThinkPad', 'Turbotastic!', - 'Goddamn Idiotic Truckload of Windows', `Now running on Discord.JS ${version}!` ]; diff --git a/storage/settings.json b/storage/settings.json index b53fd84..83932cc 100644 --- a/storage/settings.json +++ b/storage/settings.json @@ -1,4 +1,4 @@ { "abVersion": "2.13.0 Beta", - "prefix": "ab:" + "prefix": "abb:" } diff --git a/sync-database.js b/sync-database.js index 2462f29..f7b9211 100644 --- a/sync-database.js +++ b/sync-database.js @@ -1,9 +1,13 @@ -const quoteDB = require("./models/quote"); +const { quote, pendingQuote } = require("./models/quote"); const guildDB = require ('./models/guild-settings'); -quoteDB.sync({alter: true}).then(() => { +quote.sync({alter: true}).then(() => { console.log('Quote database synced!') }); +pendingQuote.sync({alter: true}).then(() => { + console.log('Pending Quote database synced!') +}); + guildDB.sync({alter: true}).then(() => { console.log('Guild database synced!') }); diff --git a/web/.gitignore b/web/.gitignore new file mode 100644 index 0000000..016b59e --- /dev/null +++ b/web/.gitignore @@ -0,0 +1,24 @@ +# build output +dist/ + +# generated types +.astro/ + +# dependencies +node_modules/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store + +# jetbrains setting folder +.idea/ diff --git a/web/.vscode/extensions.json b/web/.vscode/extensions.json new file mode 100644 index 0000000..22a1505 --- /dev/null +++ b/web/.vscode/extensions.json @@ -0,0 +1,4 @@ +{ + "recommendations": ["astro-build.astro-vscode"], + "unwantedRecommendations": [] +} diff --git a/web/.vscode/launch.json b/web/.vscode/launch.json new file mode 100644 index 0000000..d642209 --- /dev/null +++ b/web/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "command": "./node_modules/.bin/astro dev", + "name": "Development server", + "request": "launch", + "type": "node-terminal" + } + ] +} diff --git a/web/astro.config.mjs b/web/astro.config.mjs new file mode 100644 index 0000000..53e49de --- /dev/null +++ b/web/astro.config.mjs @@ -0,0 +1,9 @@ +// @ts-check +import { defineConfig } from 'astro/config'; + +import react from '@astrojs/react'; + +// https://astro.build/config +export default defineConfig({ + integrations: [react()] +}); \ No newline at end of file diff --git a/web/bun.lockb b/web/bun.lockb new file mode 100644 index 0000000..b648049 Binary files /dev/null and b/web/bun.lockb differ diff --git a/web/package.json b/web/package.json new file mode 100644 index 0000000..811ab8b --- /dev/null +++ b/web/package.json @@ -0,0 +1,19 @@ +{ + "name": "aleebot-web", + "type": "module", + "version": "0.0.1", + "scripts": { + "dev": "astro dev", + "build": "astro build", + "preview": "astro preview", + "astro": "astro" + }, + "dependencies": { + "@astrojs/react": "^4.1.3", + "@types/react": "^19.0.4", + "@types/react-dom": "^19.0.2", + "astro": "^5.1.5", + "react": "^19.0.0", + "react-dom": "^19.0.0" + } +} diff --git a/web/public/favicon.svg b/web/public/favicon.svg new file mode 100644 index 0000000..f157bd1 --- /dev/null +++ b/web/public/favicon.svg @@ -0,0 +1,9 @@ + + + + diff --git a/web/src/components/Quotes.jsx b/web/src/components/Quotes.jsx new file mode 100644 index 0000000..1d563e7 --- /dev/null +++ b/web/src/components/Quotes.jsx @@ -0,0 +1,86 @@ +import { useState, useEffect } from 'react'; +import '../styles/Quote.css' + +export function PendingQuotes() { + const [quotes, setQuotes] = useState([]); + + const fetchQuotes = async () => { + try { + const response = await fetch('http://localhost:3000/api/pending-quotes'); + const data = await response.json(); + setQuotes(data); + } catch (error) { + console.error('Failed to fetch quotes:', error); + } + }; + + useEffect(() => { + fetchQuotes(); + }, []); + + const approveQuote = async (id) => { + try { + const response = await fetch('http://localhost:3000/api/approve-quote', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ id }), + }); + + if (response.ok) { + fetchQuotes(); // Refresh the listing after approving the quote + } else { + console.error('Failed to approve quote'); + } + } catch (error) { + console.error('Error approving quote:', error); + } + }; + + const rejectQuote = async (id) => { + try { + const response = await fetch('http://localhost:3000/api/reject-quote', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ id }), + }); + + if (response.ok) { + fetchQuotes(); // Refresh the listing after approving the quote + } else { + console.error('Failed to reject quote'); + } + } catch (error) { + console.error('Error rejecting quote:', error); + } + }; + + return ( +
+

Pending Quotes

+ {quotes.length > 0 ? ( +
    + {quotes.map((quote) => ( +
  • +
    +
    + No Profile +

    {quote.author}

    +
    +

    {quote.quote}

    + - {quote.year} +
    + + +
  • + ))} +
+ ) : ( +

No pending quotes available.

+ )} +
+ ); +} diff --git a/web/src/layouts/Layout.astro b/web/src/layouts/Layout.astro new file mode 100644 index 0000000..e455c61 --- /dev/null +++ b/web/src/layouts/Layout.astro @@ -0,0 +1,22 @@ + + + + + + + + Astro Basics + + + + + + + diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro new file mode 100644 index 0000000..b5c607d --- /dev/null +++ b/web/src/pages/index.astro @@ -0,0 +1,29 @@ +--- +import Layout from '../layouts/Layout.astro'; +import { PendingQuotes } from '../components/Quotes'; + +const version = await fetch('http://localhost:3000/api/version').then(res => res.json()); +--- + + +
+

AleeBot {version}

+ +
+
+ + diff --git a/web/src/styles/Quote.css b/web/src/styles/Quote.css new file mode 100644 index 0000000..8adfb29 --- /dev/null +++ b/web/src/styles/Quote.css @@ -0,0 +1,33 @@ +.quote { + display: flex; + flex-direction: column; + background: #555555; + color: #FFFFFF; + padding: 1em; +} + +ul.quoteList { + margin: 0; + padding: 0; +} + +li.quoteList { + list-style-type: none; + margin-top: 1em; + margin-bottom: 1em; +} + +.author { + display: flex; + flex-direction: row; +} + +h1.quoteAuthor { + font-size: 1.5em; + padding: 0; + margin: 0 0 0 .5em; +} + +.quoteText { + margin: .5em 0; +} diff --git a/web/tsconfig.json b/web/tsconfig.json new file mode 100644 index 0000000..69c1600 --- /dev/null +++ b/web/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "astro/tsconfigs/strict", + "include": [ + ".astro/types.d.ts", + "**/*" + ], + "exclude": [ + "dist" + ], + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "react" + } +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 5942f18..d266f22 100644 --- a/yarn.lock +++ b/yarn.lock @@ -513,6 +513,14 @@ cookie@0.5.0: resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b" integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw== +cors@^2.8.5: + version "2.8.5" + resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29" + integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g== + dependencies: + object-assign "^4" + vary "^1" + cross-spawn@^7.0.2: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" @@ -1507,7 +1515,7 @@ npmlog@^6.0.0: gauge "^4.0.3" set-blocking "^2.0.0" -object-assign@^4.1.1: +object-assign@^4, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg== @@ -2100,7 +2108,7 @@ validator@^13.7.0: resolved "https://registry.yarnpkg.com/validator/-/validator-13.9.0.tgz#33e7b85b604f3bbce9bb1a05d5c3e22e1c2ff855" integrity sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA== -vary@~1.1.2: +vary@^1, vary@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg== -- cgit v1.2.3 From de5ee661cad7b1fef0f319cbaccd888cb75a1dd4 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 12 Jan 2025 00:45:51 -0500 Subject: Fixed environment variable, prefix using ab --- Dockerfile | 3 ++- api/server.js | 6 +++--- storage/settings.json | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'storage/settings.json') diff --git a/Dockerfile b/Dockerfile index 3f4f771..44c3d57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,4 +12,5 @@ RUN yarn install COPY . . -ENTRYPOINT ["node", "bot_discord.js", "--beta"] +ENTRYPOINT ["node", "bot_discord.js"] + diff --git a/api/server.js b/api/server.js index a6cb48c..2a2afad 100644 --- a/api/server.js +++ b/api/server.js @@ -1,9 +1,9 @@ const express = require('express'); const cors = require('cors'); const quotesRouter = require('./routes/quotes'); +require('dotenv').config() const app = express(); -const PORT = 3000; const createServer = () => { app.use(cors()); // Allow cross-origin requests @@ -18,8 +18,8 @@ const createServer = () => { }); // Start the server - app.listen(PORT, () => { - console.log(`Server is running on http://localhost:${PORT}`); + app.listen(process.env.port, () => { + console.log(`Server is running on http://localhost:${process.env.port}`); }); }; diff --git a/storage/settings.json b/storage/settings.json index 83932cc..b53fd84 100644 --- a/storage/settings.json +++ b/storage/settings.json @@ -1,4 +1,4 @@ { "abVersion": "2.13.0 Beta", - "prefix": "abb:" + "prefix": "ab:" } -- cgit v1.2.3 From 5777f96394444dab18a81d6f085ac81df3e62008 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Tue, 25 Feb 2025 23:13:39 -0500 Subject: 2.13 Release (finally); Added more API entries; Proper logging --- api/server.js | 51 +++++++++++++++++++- bot_discord.js | 108 ++++++++++++++++++++++++------------------ commands/addquote.js | 4 +- commands/quote.js | 3 +- commands/setlogchannel.js | 25 ++++++---- models/guild-settings.js | 25 ++++++---- package.json | 2 +- storage/settings.json | 2 +- sync-database.js | 4 +- web/astro.config.mjs | 10 +++- web/src/components/Quotes.jsx | 7 +-- web/src/pages/index.astro | 3 +- 12 files changed, 165 insertions(+), 79 deletions(-) (limited to 'storage/settings.json') diff --git a/api/server.js b/api/server.js index 2a2afad..acfe528 100644 --- a/api/server.js +++ b/api/server.js @@ -5,7 +5,7 @@ require('dotenv').config() const app = express(); -const createServer = () => { +const apiServer = (client) => { app.use(cors()); // Allow cross-origin requests app.use(express.json()); @@ -17,10 +17,57 @@ const createServer = () => { }); + app.get('/api/uptime', (req, res) => { + res.json(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(`Server is running on http://localhost:${process.env.port}`); }); }; -module.exports = createServer; +module.exports = apiServer; diff --git a/bot_discord.js b/bot_discord.js index 5a38940..1a87074 100644 --- a/bot_discord.js +++ b/bot_discord.js @@ -33,12 +33,15 @@ const colors = require('colors'); //const i18next = require('i18next'); const settings = require('./storage/settings.json'); const { activity } = require('./storage/activities'); -const createServer = require("./api/server"); +const apiServer = require("./api/server"); const active = new Map(); let autoRole = true; let readyEmbedMessage = true; + +const { guildSettings } = require('./models/guild-settings'); + const ownerID = '242775871059001344'; -let logChannel = '318874545593384970'; +//let logChannel = '318874545593384970'; let statusChannelID = '606602551634296968'; let serverWhitelist = "243022206437687296"; let roleWhitelist = "657426918416580614"; @@ -218,7 +221,7 @@ client.on('ready', async () => { botPresence(); - createServer(); + apiServer(client); setInterval(function() { botPresence(); @@ -238,8 +241,10 @@ client.on('ready', async () => { rl.prompt(); }); -client.on('guildMemberAdd', (member) => { - if (member.guild.id !== serverWhitelist) return; +client.on('guildMemberAdd', async (member) => { + const guildSetting = await guildSettings.findOne({ where: { guildID: member.guild.id } }); + if (!guildSetting || !guildSetting.logChannelID) return; + const logEmbed = new Discord.MessageEmbed() .setAuthor('AleeBot Logging', client.user.avatarURL()) .setDescription(`A user has joined this server!`) @@ -249,7 +254,7 @@ client.on('guildMemberAdd', (member) => { .setColor('#4bff31') .setTimestamp(); - let guildMember = client.channels.cache.get(logChannel); + let guildMember = client.channels.cache.get(guildSetting.logChannelID); if (!guildMember) return; guildMember.send({ embeds: [logEmbed]}); @@ -261,8 +266,10 @@ client.on('guildMemberAdd', (member) => { } }); -client.on('guildMemberRemove', (member) => { - if (member.guild.id !== serverWhitelist) return; +client.on('guildMemberRemove', async (member) => { + const guildSetting = await guildSettings.findOne({ where: { guildID: member.guild.id } }); + if (!guildSetting || !guildSetting.logChannelID) return; + const logEmbed = new Discord.MessageEmbed() .setAuthor('AleeBot Logging', client.user.avatarURL()) .setDescription(`A user has left this server!`) @@ -271,7 +278,7 @@ client.on('guildMemberRemove', (member) => { .setColor('#ec2727') .setTimestamp(); - let guildMember = client.channels.cache.get(logChannel); + let guildMember = client.channels.cache.get(guildSetting.logChannelID); if (!guildMember) return; guildMember.send({ embeds: [logEmbed]}); @@ -279,7 +286,10 @@ client.on('guildMemberRemove', (member) => { client.on('messageUpdate', async (oldMessage, newMessage) => { - if (!oldMessage.guild || oldMessage.guild.id !== serverWhitelist) return; + const guildSetting = await guildSettings.findOne({ where: { guildID: oldMessage.guild.id } }); + if (!oldMessage.guild || !guildSetting || !guildSetting.logChannelID) return; + + //if (!oldMessage.guild || oldMessage.guild.id !== serverWhitelist) return; if (oldMessage.content === newMessage.content) { return; } @@ -292,14 +302,18 @@ client.on('messageUpdate', async (oldMessage, newMessage) => { .setTimestamp() .setFooter(`Author ID: ${oldMessage.author.id}`); - let editMessage = client.channels.cache.get(logChannel); + let editMessage = client.channels.cache.get(guildSetting.logChannelID); if (!editMessage) return; editMessage.send({ embeds: [logEmbed]}); }); -client.on('messageDelete', (message) => { - if (message.guild.id !== serverWhitelist) return; +client.on('messageDelete', async (message) => { + if (!message.content) return; + + const guildSetting = await guildSettings.findOne({ where: { guildID: message.guild.id } }); + if (!guildSetting || !guildSetting.logChannelID) return; + const logEmbed = new Discord.MessageEmbed() .setAuthor('AleeBot Logging', client.user.avatarURL()) .setDescription(`A message from ${message.author.username} was deleted in <#${message.channel.id}>`) @@ -308,43 +322,47 @@ client.on('messageDelete', (message) => { .setTimestamp() .setFooter(`Author ID: ${message.author.id}`); - let deleteMessage = client.channels.cache.get(logChannel); + let deleteMessage = client.channels.cache.get(guildSetting.logChannelID); if (!deleteMessage) return; deleteMessage.send({ embeds: [logEmbed]}); }); -client.on('guildBanAdd', (guild, user) => { - if (guild.id !== serverWhitelist) return; - const logEmbed = new Discord.MessageEmbed() - .setAuthor('AleeBot Logging', client.user.avatarURL()) - .setDescription(`This user got banned from ${guild.name}`) - .addField('User:', `${user.tag}`) - .addField('User ID:', `${user.id}`) - .setColor('#ff021b') - .setTimestamp(); - - let banMessage = client.channels.cache.get(logChannel); - if (!banMessage) return; - - banMessage.send({ embeds: [logEmbed]}); -}); - -client.on('guildBanRemove', (guild, user) => { - if (guild.id !== serverWhitelist) return; - const logEmbed = new Discord.MessageEmbed() - .setAuthor('AleeBot Logging', client.user.avatarURL()) - .setDescription(`This user got unbanned from ${guild.name}`) - .addField('User:', `${user.tag}`) - .addField('User ID:', `${user.id}`) - .setColor('#ff021b') - .setTimestamp(); - - let banMessage = client.channels.cache.get(logChannel); - if (!banMessage) return; - - banMessage.send({ embeds: [logEmbed]}); -}); +// client.on('guildBanAdd', async (guild, user) => { +// const guildSetting = await guildSettings.findOne({ where: { guildID: guild.id } }); +// if (!guildSetting || !guildSetting.logChannelID) return; +// +// const logEmbed = new Discord.MessageEmbed() +// .setAuthor('AleeBot Logging', client.user.avatarURL()) +// .setDescription(`This user got banned from ${guild.name}`) +// .addField('User:', `${user.tag}`) +// .addField('User ID:', `${user.id}`) +// .setColor('#ff021b') +// .setTimestamp(); +// +// let banMessage = client.channels.cache.get(guildSetting.logChannelID); +// if (!banMessage) return; +// +// banMessage.send({ embeds: [logEmbed]}); +// }); +// +// client.on('guildBanRemove', async (guild, user) => { +// const guildSetting = await guildSettings.findOne({ where: { guildID: guild.id } }); +// if (!guildSetting || !guildSetting.logChannelID) return; +// +// const logEmbed = new Discord.MessageEmbed() +// .setAuthor('AleeBot Logging', client.user.avatarURL()) +// .setDescription(`This user got unbanned from ${guild.name}`) +// .addField('User:', `${user.tag}`) +// .addField('User ID:', `${user.id}`) +// .setColor('#ff021b') +// .setTimestamp(); +// +// let banMessage = client.channels.cache.get(guildSetting.logChannelID); +// if (!banMessage) return; +// +// banMessage.send({ embeds: [logEmbed]}); +// }); client.on('guildCreate', (guild) => { log(`[i] New guild joined: ${guild.name} (${guild.id}). This guild has ${guild.memberCount} members!`.blue); diff --git a/commands/addquote.js b/commands/addquote.js index cedee4d..6eae015 100644 --- a/commands/addquote.js +++ b/commands/addquote.js @@ -85,7 +85,7 @@ module.exports.run = async (client, message) => { return; } } else if (msg.content.startsWith('http') && (msg.content.endsWith('.jpg') || msg.content.endsWith('.jpeg') || msg.content.endsWith('.png'))) { - newAuthorImage = message.content; + newAuthorImage = msg.content; } else { await dmChannel.send('Invalid input. Please provide an image URL or attach an image file.'); collector.stop(); @@ -157,7 +157,7 @@ module.exports.run = async (client, message) => { await dmChannel.send('Invalid file type. Please attach a .jpg or .png image.'); } } else if (imageResponse.first().content.startsWith('http') && (imageResponse.first().content.endsWith('.jpg') || imageResponse.first().content.endsWith('.jpeg') || imageResponse.first().content.endsWith('.png'))) { - newAuthorImage = message.content; + newAuthorImage = imageResponse.first().content; } else { await dmChannel.send('Invalid input. Please provide an image URL or attach an image file.'); } diff --git a/commands/quote.js b/commands/quote.js index 02699cd..f19675f 100644 --- a/commands/quote.js +++ b/commands/quote.js @@ -30,13 +30,12 @@ module.exports.run = async (client, message, args) => { const quote = await quoteDB.findOne({ where: { id: quoteID } }) - if (quote) { const quoteEmbed = new MessageEmbed() .setAuthor({ name: quote.author, iconURL: quote.authorImage }) .setDescription(quote.quote) .setColor('#1fd619') - .setFooter('- ' + quote.year); + .setFooter(`- ${quote.year}\nSubmitted by ${quote.submitter}`); await message.reply({ embeds: [quoteEmbed] }) } else { diff --git a/commands/setlogchannel.js b/commands/setlogchannel.js index c04e926..d989f8b 100644 --- a/commands/setlogchannel.js +++ b/commands/setlogchannel.js @@ -17,21 +17,30 @@ * along with this program. If not, see . * * *************************************/ -const guildDB = require ('../models/guild-settings') -module.exports.run = async (client, message) => { +const { guildSettings } = require ('../models/guild-settings') +module.exports.run = async (client, message, args) => { //This will be replaced in the future possibly if (!message.member.permissions.has('MANAGE_GUILD')) return message.reply('It looks like that you can\'t manage this server.'); - const channel = await message.mentions.channels.first().id; - const [ guild ] = await guildDB.findOrCreate({ where: { id: message.guild.id } } ) + + let channel; + + if (message.mentions.channels.first()) { + channel = message.mentions.channels.first().id; + } else if (args[0] && message.guild.channels.cache.has(args[0])) { + channel = args[0]; + } else { + return await message.reply('Please enter a valid channel ID.') + } + + const [ guild ] = await guildSettings.findOrCreate({ where: { guildID: message.guild.id } } ) if (!channel) { message.reply('No channel has been set, disabling the logging channel feature...'); - await guild.update({ channelId: null } ); + await guild.update({ logChannelID: null } ); } else { - await guild.update({ channelId: message.guild.id } ) ; + await guild.update({ logChannelID: channel } ); + await message.reply(`Logging channel has been set to <#${channel}>`); } - - await message.reply(`Logging channel has been set to <#${channel}>`); }; exports.conf = { diff --git a/models/guild-settings.js b/models/guild-settings.js index 2e4f8ef..8cc7478 100644 --- a/models/guild-settings.js +++ b/models/guild-settings.js @@ -3,22 +3,27 @@ const sequelize = require('../utils/sequelize'); const guildSettings = sequelize.define('guild-settings', { id: { - type: Sequelize.STRING, - primaryKey: true + type: Sequelize.INTEGER, + primaryKey: true, + autoIncrement: true, }, - logChannelID: { + guildID: { type: Sequelize.STRING, - allowNull: true + allowNull: false }, - autoRoleToggle: { - type: Sequelize.BOOLEAN, - allowNull: true - }, - autoRoleID: { + logChannelID: { type: Sequelize.STRING, allowNull: true } + // qotdChannelID: { + // type: Sequelize.STRING, + // allowNull: true + // }, + // qotdToggle: { + // type: Sequelize.BOOLEAN, + // allowNull: true + // } }) -module.exports = guildSettings +module.exports = { guildSettings } diff --git a/package.json b/package.json index b300082..404b4a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aleebot", - "version": "2.13.0b", + "version": "2.13.0", "description": "A chat bot for discord written in discord.js.", "main": "bot_discord.js", "scripts": { diff --git a/storage/settings.json b/storage/settings.json index b53fd84..4a6911c 100644 --- a/storage/settings.json +++ b/storage/settings.json @@ -1,4 +1,4 @@ { - "abVersion": "2.13.0 Beta", + "abVersion": "2.13.0", "prefix": "ab:" } diff --git a/sync-database.js b/sync-database.js index f7b9211..7a9271c 100644 --- a/sync-database.js +++ b/sync-database.js @@ -1,5 +1,5 @@ const { quote, pendingQuote } = require("./models/quote"); -const guildDB = require ('./models/guild-settings'); +const { guildSettings } = require ('./models/guild-settings'); quote.sync({alter: true}).then(() => { console.log('Quote database synced!') }); @@ -8,6 +8,6 @@ pendingQuote.sync({alter: true}).then(() => { console.log('Pending Quote database synced!') }); -guildDB.sync({alter: true}).then(() => { +guildSettings.sync({alter: true}).then(() => { console.log('Guild database synced!') }); diff --git a/web/astro.config.mjs b/web/astro.config.mjs index c0fd9ad..d32e23b 100644 --- a/web/astro.config.mjs +++ b/web/astro.config.mjs @@ -1,5 +1,5 @@ // @ts-check -import { defineConfig } from 'astro/config'; +import { defineConfig, envField } from 'astro/config'; import react from '@astrojs/react'; @@ -11,5 +11,11 @@ export default defineConfig({ adapter: node({ mode: 'standalone' - }) + }), + + env: { + schema: { + API_URL: envField.string({ context: 'client', access: 'public' }), + } + } }); diff --git a/web/src/components/Quotes.jsx b/web/src/components/Quotes.jsx index 831408d..1eb258a 100644 --- a/web/src/components/Quotes.jsx +++ b/web/src/components/Quotes.jsx @@ -1,12 +1,13 @@ import { useState, useEffect } from 'react'; import '../styles/Quote.css' +import { API_URL } from "astro:env/client"; export function PendingQuotes() { const [quotes, setQuotes] = useState([]); const fetchQuotes = async () => { try { - const response = await fetch('http://localhost:3000/api/pending-quotes'); + const response = await fetch(`${API_URL}/api/pending-quotes`); const data = await response.json(); setQuotes(data); } catch (error) { @@ -20,7 +21,7 @@ export function PendingQuotes() { const approveQuote = async (id) => { try { - const response = await fetch('http://localhost:3000/api/approve-quote', { + const response = await fetch(`${API_URL}/api/approve-quote`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -40,7 +41,7 @@ export function PendingQuotes() { const rejectQuote = async (id) => { try { - const response = await fetch('http://localhost:3000/api/reject-quote', { + const response = await fetch(`${API_URL}/api/reject-quote`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro index 8136402..f1dc6e7 100644 --- a/web/src/pages/index.astro +++ b/web/src/pages/index.astro @@ -28,9 +28,10 @@ import { PendingQuotes } from '../components/Quotes';