diff options
| author | Andrew Lee <andrew@alee14.me> | 2025-03-30 17:05:51 -0400 |
|---|---|---|
| committer | Andrew Lee <andrew@alee14.me> | 2025-03-30 17:07:09 -0400 |
| commit | 1662608835099ee3176d07d67c6a3c69f716f938 (patch) | |
| tree | 6a891bdc439c32e0c10369d91e55c9b4e444c65f /bot/src | |
| parent | 3c61c156137984cf61d3517d4d9633ca6de072f6 (diff) | |
| download | AleeBot-1662608835099ee3176d07d67c6a3c69f716f938.tar.gz AleeBot-1662608835099ee3176d07d67c6a3c69f716f938.tar.bz2 AleeBot-1662608835099ee3176d07d67c6a3c69f716f938.zip | |
Fixed issues; Generate bot invite; Added database migrations
Diffstat (limited to 'bot/src')
| -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 |
6 files changed, 106 insertions, 6 deletions
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}\`\`\``); } } |
