diff options
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/.sequelizerc | 8 | ||||
| -rw-r--r-- | bot/bun.lockb | bin | 134763 -> 159191 bytes | |||
| -rw-r--r-- | bot/package.json | 4 | ||||
| -rw-r--r-- | bot/src/commands/about.js | 18 | ||||
| -rw-r--r-- | bot/src/db/config/config.json | 20 | ||||
| -rw-r--r-- | bot/src/db/migrations/20250330201535-update-guild-settings.js | 31 | ||||
| -rw-r--r-- | bot/src/db/migrations/20250330202144-command-usages.js | 31 | ||||
| -rw-r--r-- | bot/src/events/InteractionCreate.js | 7 | ||||
| -rw-r--r-- | bot/src/plugins/chatbot.js | 5 |
9 files changed, 117 insertions, 7 deletions
diff --git a/bot/.sequelizerc b/bot/.sequelizerc new file mode 100644 index 0000000..88c41dd --- /dev/null +++ b/bot/.sequelizerc @@ -0,0 +1,8 @@ +const path = require('path'); + +module.exports = { + 'config': path.resolve('src/db/config', 'config.json'), + 'models-path': path.resolve('src', 'models'), + 'seeders-path': path.resolve('src/db', 'seeders'), + 'migrations-path': path.resolve('src/db', 'migrations') +}; diff --git a/bot/bun.lockb b/bot/bun.lockb Binary files differindex 070f3d3..faf6f87 100644 --- a/bot/bun.lockb +++ b/bot/bun.lockb diff --git a/bot/package.json b/bot/package.json index cdfb6a3..18ea6bb 100644 --- a/bot/package.json +++ b/bot/package.json @@ -9,7 +9,8 @@ "start": "node src/bot.js", "dev": "nodemon src/bot.js", "deploy": "node deploy-command.js", - "lint": "eslint ." + "lint": "eslint .", + "migrate": "sequelize-cli db:migrate" }, "dependencies": { "bcrypt": "^5.1.1", @@ -20,6 +21,7 @@ "node-cron": "^3.0.3", "ollama": "^0.5.14", "sequelize": "^6.37.6", + "sequelize-cli": "^6.6.2", "sqlite3": "^5.1.7" }, "devDependencies": { diff --git a/bot/src/commands/about.js b/bot/src/commands/about.js index 177ac47..ac78291 100644 --- a/bot/src/commands/about.js +++ b/bot/src/commands/about.js @@ -3,7 +3,9 @@ import { ButtonBuilder, EmbedBuilder, SlashCommandBuilder, - ButtonStyle + ButtonStyle, + PermissionFlagsBits, + OAuth2Scopes } from 'discord.js'; import { readFileSync } from 'node:fs'; import { abEmbedColour } from '../storage/consts.js'; @@ -15,6 +17,18 @@ export default { .setName('about') .setDescription('Information about this bot.'), async execute(interaction) { + const botInvite = interaction.client.generateInvite({ + permissions: [ + PermissionFlagsBits.EmbedLinks, + PermissionFlagsBits.SendMessages, + PermissionFlagsBits.ManageMessages, + PermissionFlagsBits.ViewAuditLog, + PermissionFlagsBits.ViewChannel, + PermissionFlagsBits.AddReactions + ], + scopes: [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands] + }); + const aboutEmbed = new EmbedBuilder() .setAuthor({ name: `AleeBot ${version}`, iconURL: interaction.client.user.avatarURL() }) .addFields( @@ -38,7 +52,7 @@ export default { new ButtonBuilder() .setStyle(ButtonStyle.Link) .setLabel('Invite AleeBot') - .setURL(`https://discord.com/oauth2/authorize?client_id=${interaction.client.user.id}`), + .setURL(botInvite), new ButtonBuilder() .setStyle(ButtonStyle.Link) .setLabel('Join Andrew Lee Projects') diff --git a/bot/src/db/config/config.json b/bot/src/db/config/config.json new file mode 100644 index 0000000..6efe0e6 --- /dev/null +++ b/bot/src/db/config/config.json @@ -0,0 +1,20 @@ +{ + "development": { + "host": "localhost", + "dialect": "sqlite", + "logging": false, + "storage": "database.db" + }, + "test": { + "host": "localhost", + "dialect": "sqlite", + "logging": false, + "storage": "database.db" + }, + "production": { + "host": "localhost", + "dialect": "sqlite", + "logging": false, + "storage": "database.db" + } +} diff --git a/bot/src/db/migrations/20250330201535-update-guild-settings.js b/bot/src/db/migrations/20250330201535-update-guild-settings.js new file mode 100644 index 0000000..1d4a4d3 --- /dev/null +++ b/bot/src/db/migrations/20250330201535-update-guild-settings.js @@ -0,0 +1,31 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +export const up = async (queryInterface, Sequelize) => { + await queryInterface.addColumn('guild-settings', 'suggestionsChannelID', { + type: Sequelize.STRING, + allowNull: true + }); + + await queryInterface.addColumn('guild-settings', 'qotdChannelID', { + type: Sequelize.STRING, + allowNull: true + }); + + await queryInterface.addColumn('guild-settings', 'qotdToggle', { + type: Sequelize.BOOLEAN, + allowNull: true + }); + + await queryInterface.addColumn('guild-settings', 'ollamaEnabled', { + type: Sequelize.BOOLEAN, + allowNull: true + }); +}; + +export const down = async (queryInterface) => { + await queryInterface.removeColumn('guild-settings', 'suggestionsChannelID'); + await queryInterface.removeColumn('guild-settings', 'qotdChannelID'); + await queryInterface.removeColumn('guild-settings', 'qotdToggle'); + await queryInterface.removeColumn('guild-settings', 'ollamaEnabled'); +}; diff --git a/bot/src/db/migrations/20250330202144-command-usages.js b/bot/src/db/migrations/20250330202144-command-usages.js new file mode 100644 index 0000000..095f817 --- /dev/null +++ b/bot/src/db/migrations/20250330202144-command-usages.js @@ -0,0 +1,31 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +export const up = async (queryInterface, Sequelize) => { + return await queryInterface.createTable('command-usages', { + id: { + type: Sequelize.INTEGER, + autoIncrement: true, + primaryKey: true + }, + command: { + type: Sequelize.STRING, + allowNull: false + }, + userID: { + type: Sequelize.STRING, + allowNull: false + }, + guildID: { + type: Sequelize.STRING, + allowNull: true + }, + createdAt: { + type: Sequelize.DATE + } + }); +}; + +export const down = async (queryInterface) => { + return await queryInterface.dropTable('command-usages'); +}; diff --git a/bot/src/events/InteractionCreate.js b/bot/src/events/InteractionCreate.js index 5143594..976b995 100644 --- a/bot/src/events/InteractionCreate.js +++ b/bot/src/events/InteractionCreate.js @@ -15,7 +15,12 @@ export default { if (!command) return; try { - console.log(`[i] ${interaction.user.username} has executed ${command.data.name} at ${interaction.guild.name}`); + if (interaction.guild) { + console.log(`[i] ${interaction.user.username} has executed ${command.data.name} at ${interaction.guild.name}`); + } else { + console.log(`[i] ${interaction.user.username} has executed ${command.data.name} in DMs`); + } + await Analytics(command, interaction); await command.execute(interaction); } catch (e) { diff --git a/bot/src/plugins/chatbot.js b/bot/src/plugins/chatbot.js index efd2ff5..705f267 100644 --- a/bot/src/plugins/chatbot.js +++ b/bot/src/plugins/chatbot.js @@ -9,10 +9,9 @@ export async function ChatBot(msg, args) { if (!guildSetting.ollamaEnabled) return; if (!ollamaGlobal) return msg.reply('Sorry, the LLM chatbot feature has been turned off.'); + const loadingMessage = await msg.reply('Thinking...'); try { - const loadingMessage = await msg.reply('Thinking...'); - const response = await ollama.chat({ model: process.env.OLLAMA_MODEL, messages: [{ role: 'user', content: args }], @@ -29,6 +28,6 @@ export async function ChatBot(msg, args) { } catch (err) { console.error(err); - await msg.reply(`Something went wrong. [Submit an issue at the AleeBot repository.](<https://github.com/Alee14/AleeBot/issues>)\nMessage:\n\`\`\`${err.stack}\`\`\``); + await loadingMessage.edit(`Something went wrong. [Submit an issue at the AleeBot repository.](<https://github.com/Alee14/AleeBot/issues>)\nMessage:\n\`\`\`${err.stack}\`\`\``); } } |
