aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.parlance.json11
-rw-r--r--bot/package.json2
-rw-r--r--bot/src/api/routes/blacklist.js47
-rw-r--r--bot/src/bot.js2
-rw-r--r--bot/src/commands/quote.js4
-rw-r--r--bot/src/commands/settings.js2
-rw-r--r--bot/src/commands/suggest.js4
-rw-r--r--bot/src/db/models/blacklist.js30
-rw-r--r--bot/src/db/models/guild-settings.js1
-rw-r--r--bot/src/db/models/user-settings.js18
-rw-r--r--bot/src/events/InteractionCreate.js5
-rw-r--r--bot/src/plugins/chatbot.js3
-rw-r--r--bot/src/storage/functions.js18
-rw-r--r--bot/src/translations/en/translation.json3
-rw-r--r--bot/src/translations/fr/translation.json3
-rw-r--r--bot/src/utils/i18n.js12
-rw-r--r--bot/src/utils/sync.js9
-rw-r--r--bot/yarn.lock24
18 files changed, 190 insertions, 8 deletions
diff --git a/.parlance.json b/.parlance.json
new file mode 100644
index 0000000..5a1f41c
--- /dev/null
+++ b/.parlance.json
@@ -0,0 +1,11 @@
+{
+ "name": "AleeBot",
+ "subprojects": [
+ {
+ "name": "AleeBot",
+ "type": "i18next",
+ "path": "/bot/src/translations/{lang}/translation.json",
+ "baseLang": "en"
+ }
+ ]
+}
diff --git a/bot/package.json b/bot/package.json
index ac40765..b19ac99 100644
--- a/bot/package.json
+++ b/bot/package.json
@@ -17,6 +17,8 @@
"cors": "^2.8.5",
"discord.js": "^14.18.0",
"express": "^4.21.2",
+ "i18next": "^24.2.3",
+ "i18next-fs-backend": "^2.6.0",
"jsonwebtoken": "^9.0.2",
"node-cron": "^3.0.3",
"ollama": "^0.5.14",
diff --git a/bot/src/api/routes/blacklist.js b/bot/src/api/routes/blacklist.js
new file mode 100644
index 0000000..ffcd60b
--- /dev/null
+++ b/bot/src/api/routes/blacklist.js
@@ -0,0 +1,47 @@
+import { Router } from 'express';
+
+export function authRouter() {
+ const router = Router();
+
+ router.post('/blacklist/guild/add', async (req, res) => {
+ const { guildID } = req.body;
+ try {
+ res.status(200).send({ message: 'Added to the blacklist' });
+ } catch (error) {
+ console.error('Something went wrong:', error);
+ res.status(500).send({ message: 'Internal Server Error' });
+ }
+ });
+
+ router.post('/blacklist/user/add', async (req, res) => {
+ const { userID } = req.body;
+ try {
+ res.status(200).send({ message: 'Added to the blacklist' });
+ } catch (error) {
+ console.error('Something went wrong:', error);
+ res.status(500).send({ message: 'Internal Server Error' });
+ }
+ });
+
+ router.post('/blacklist/guild/remove', async (req, res) => {
+ const { guildID } = req.body;
+ try {
+ res.status(200).send({ message: 'Removed from the blacklist' });
+ } catch (error) {
+ console.error('Something went wrong:', error);
+ res.status(500).send({ message: 'Internal Server Error' });
+ }
+ });
+
+ router.post('/blacklist/user/remove', async (req, res) => {
+ const { userID } = req.body;
+ try {
+ res.status(200).send({ message: 'Removed from the blacklist' });
+ } catch (error) {
+ console.error('Something went wrong:', error);
+ res.status(500).send({ message: 'Internal Server Error' });
+ }
+ });
+
+ return router;
+}
diff --git a/bot/src/bot.js b/bot/src/bot.js
index c301234..bba8eaf 100644
--- a/bot/src/bot.js
+++ b/bot/src/bot.js
@@ -3,7 +3,7 @@ import 'dotenv/config';
import { init } from './init.js';
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildBans] });
-init(client);
+void init(client);
client.login(process.env.TOKEN).then(() => {
console.log('[>] Successfully authenticated.');
diff --git a/bot/src/commands/quote.js b/bot/src/commands/quote.js
index 79f05de..6d30847 100644
--- a/bot/src/commands/quote.js
+++ b/bot/src/commands/quote.js
@@ -8,6 +8,7 @@ import {
} from 'discord.js';
import { pendingQuote, quote as quoteDB } from '../db/models/quote.js';
import { abEmbedColour } from '../storage/consts.js';
+import { blacklistCheck } from '../storage/functions.js';
// import { setTimeout as wait } from 'node:timers/promises';
//
// let setupMessage = 'Welcome to the AleeBot Quote Setup!\n';
@@ -35,6 +36,9 @@ export default {
.setDescription('Got a quote? Add it here!')),
async execute(interaction) {
if (interaction.options.getSubcommand() === 'add') {
+ const isBlacklisted = await blacklistCheck(interaction);
+ if (isBlacklisted) return;
+
const modal = new ModalBuilder()
.setCustomId(`newQuote-${interaction.user.id}`)
.setTitle('New Quote for AleeBot');
diff --git a/bot/src/commands/settings.js b/bot/src/commands/settings.js
index 872bbd7..a6da979 100644
--- a/bot/src/commands/settings.js
+++ b/bot/src/commands/settings.js
@@ -38,7 +38,7 @@ export default {
.addBooleanOption(option =>
option
.setName('llmtoggle')
- .setDescription('Toggle LLM Chatbot.')))
+ .setDescription('Toggle LLM (Ollama) Chatbot.')))
.addSubcommand(subcommand =>
subcommand
.setName('clear')
diff --git a/bot/src/commands/suggest.js b/bot/src/commands/suggest.js
index e841c15..77478b1 100644
--- a/bot/src/commands/suggest.js
+++ b/bot/src/commands/suggest.js
@@ -9,6 +9,7 @@ import {
} from 'discord.js';
import { abEmbedColour, featureSuggestChannel } from '../storage/consts.js';
import { guildSettings } from '../db/models/guild-settings.js';
+import { blacklistCheck } from '../storage/functions.js';
export default {
data: new SlashCommandBuilder()
@@ -24,6 +25,9 @@ export default {
.setDescription('Suggest something for this server.')),
async execute(interaction) {
if (interaction.options.getSubcommand() === 'feature') {
+ const isBlacklisted = await blacklistCheck(interaction);
+ if (isBlacklisted) return;
+
const modal = new ModalBuilder()
.setCustomId(`suggest-${interaction.user.id}`)
.setTitle('Suggest a feature for AleeBot');
diff --git a/bot/src/db/models/blacklist.js b/bot/src/db/models/blacklist.js
new file mode 100644
index 0000000..1542f91
--- /dev/null
+++ b/bot/src/db/models/blacklist.js
@@ -0,0 +1,30 @@
+import { INTEGER, STRING } from 'sequelize';
+import { sequelize } from '../../utils/sequelize.js';
+
+export const blacklistUser = sequelize.define('blacklist-users', {
+ id: {
+ type: INTEGER,
+ primaryKey: true,
+ autoIncrement: true,
+ },
+ userID: {
+ type: STRING,
+ allowNull: false
+ }
+}, {
+ updatedAt: false,
+});
+
+export const blacklistGuild = sequelize.define('blacklist-guilds', {
+ id: {
+ type: INTEGER,
+ primaryKey: true,
+ autoIncrement: true,
+ },
+ guildID: {
+ type: STRING,
+ allowNull: false
+ }
+}, {
+ updatedAt: false,
+});
diff --git a/bot/src/db/models/guild-settings.js b/bot/src/db/models/guild-settings.js
index 09cddd2..79f8fd6 100644
--- a/bot/src/db/models/guild-settings.js
+++ b/bot/src/db/models/guild-settings.js
@@ -1,6 +1,7 @@
import { INTEGER, STRING, BOOLEAN } from 'sequelize';
import { sequelize } from '../../utils/sequelize.js';
+// potentially rename the table to settings-guilds to stay consistent
export const guildSettings = sequelize.define('guild-settings', {
id: {
type: INTEGER,
diff --git a/bot/src/db/models/user-settings.js b/bot/src/db/models/user-settings.js
new file mode 100644
index 0000000..edaff16
--- /dev/null
+++ b/bot/src/db/models/user-settings.js
@@ -0,0 +1,18 @@
+import { INTEGER, STRING } from 'sequelize';
+import { sequelize } from '../../utils/sequelize.js';
+
+export const userSettings = sequelize.define('user-settings', {
+ id: {
+ type: INTEGER,
+ primaryKey: true,
+ autoIncrement: true,
+ },
+ userID: {
+ type: STRING,
+ allowNull: false
+ },
+ language: {
+ type: STRING,
+ allowNull: true
+ }
+});
diff --git a/bot/src/events/InteractionCreate.js b/bot/src/events/InteractionCreate.js
index 976b995..387c775 100644
--- a/bot/src/events/InteractionCreate.js
+++ b/bot/src/events/InteractionCreate.js
@@ -1,9 +1,6 @@
import { Events, MessageFlags } from 'discord.js';
import { Analytics } from '../plugins/analytics.js';
-
-function error(e) {
- return `Something went wrong. [Submit an issue at the AleeBot repository.](<https://github.com/Alee14/AleeBot/issues>)\nMessage:\n\`\`\`js\n${e.stack}\`\`\``;
-}
+import { error } from '../storage/functions.js';
export default {
name: Events.InteractionCreate,
diff --git a/bot/src/plugins/chatbot.js b/bot/src/plugins/chatbot.js
index a799738..f60b045 100644
--- a/bot/src/plugins/chatbot.js
+++ b/bot/src/plugins/chatbot.js
@@ -1,6 +1,7 @@
import { ollamaGlobal } from '../storage/consts.js';
import { ollama } from '../utils/ollama.js';
import { AttachmentBuilder } from 'discord.js';
+import { error } from '../storage/functions.js';
import { guildSettings } from '../db/models/guild-settings.js';
import 'dotenv/config';
@@ -28,6 +29,6 @@ export async function ChatBot(msg, args) {
} catch (err) {
console.error(err);
- await loadingMessage.edit(`Something went wrong. [Submit an issue at the AleeBot repository.](<https://github.com/Alee14/AleeBot/issues>)\nMessage:\n\`\`\`${err.stack}\`\`\``);
+ await loadingMessage.edit(error(err.stack));
}
}
diff --git a/bot/src/storage/functions.js b/bot/src/storage/functions.js
new file mode 100644
index 0000000..c689659
--- /dev/null
+++ b/bot/src/storage/functions.js
@@ -0,0 +1,18 @@
+import { blacklistGuild, blacklistUser } from '../db/models/blacklist.js';
+import { MessageFlags } from 'discord.js';
+
+export function error(e) {
+ return `**Something went wrong. [Submit an issue at the AleeBot repository.](<https://github.com/Alee14/AleeBot/issues>)**\nMessage:\n\`\`\`js\n${e.stack}\`\`\``;
+}
+
+export async function blacklistCheck(interaction) {
+ const blacklistedUser = await blacklistUser.findOne({ where: { userID: interaction.user.id } });
+ const blacklistedGuild = await blacklistGuild.findOne({ where: { guildID: interaction.guild.id } });
+
+ if (blacklistedUser || blacklistedGuild) {
+ await interaction.reply({ content: blacklistedUser ? 'You are banned from using this command.' : 'This server is banned from using this command.', flags: MessageFlags.Ephemeral });
+ return true;
+ }
+
+ return false;
+}
diff --git a/bot/src/translations/en/translation.json b/bot/src/translations/en/translation.json
new file mode 100644
index 0000000..f96bd45
--- /dev/null
+++ b/bot/src/translations/en/translation.json
@@ -0,0 +1,3 @@
+{
+ "ABOUT_TITLE": "AleeBot Beta (en)"
+}
diff --git a/bot/src/translations/fr/translation.json b/bot/src/translations/fr/translation.json
new file mode 100644
index 0000000..03181c8
--- /dev/null
+++ b/bot/src/translations/fr/translation.json
@@ -0,0 +1,3 @@
+{
+ "ABOUT_TITLE": "AleeBot Beta (fr)"
+}
diff --git a/bot/src/utils/i18n.js b/bot/src/utils/i18n.js
index 2b4a4be..9b03994 100644
--- a/bot/src/utils/i18n.js
+++ b/bot/src/utils/i18n.js
@@ -1 +1,11 @@
-// Feature for AleeBot 4.1
+import i18next from 'i18next';
+import fsBackend from 'i18next-fs-backend';
+const fallbackLanguage = 'en';
+
+i18next.use(fsBackend).init({
+ debug: true,
+ fallbackLng: fallbackLanguage,
+ backend: {
+ loadPath: './src/translations/{{lng}}/{{ns}}.json'
+ }
+});
diff --git a/bot/src/utils/sync.js b/bot/src/utils/sync.js
index 9e11971..894015f 100644
--- a/bot/src/utils/sync.js
+++ b/bot/src/utils/sync.js
@@ -1,6 +1,7 @@
import { quote, pendingQuote } from '../db/models/quote.js';
import { guildSettings } from '../db/models/guild-settings.js';
import { commandUsages } from '../db/models/command-usages.js';
+import { blacklistGuild, blacklistUser } from '../db/models/blacklist.js';
export function syncDB() {
quote.sync().then(() => {
@@ -18,4 +19,12 @@ export function syncDB() {
commandUsages.sync().then(() => {
console.log('[>] Command usage database synced!');
});
+
+ blacklistUser.sync().then(() => {
+ console.log('[>] Blacklist user database synced!');
+ });
+
+ blacklistGuild.sync().then(() => {
+ console.log('[>] Blacklist guild database synced!');
+ });
}
diff --git a/bot/yarn.lock b/bot/yarn.lock
index 6f790bb..32787fa 100644
--- a/bot/yarn.lock
+++ b/bot/yarn.lock
@@ -2,6 +2,13 @@
# yarn lockfile v1
+"@babel/runtime@^7.26.10":
+ version "7.27.0"
+ resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.27.0.tgz#fbee7cf97c709518ecc1f590984481d5460d4762"
+ integrity sha512-VtPOkrdPHZsKc/clNqyi9WUA8TINkZ4cGk63UUE3u4pmB2k+ZMQRDuIOagv8UVd6j7k0T3+RRIb7beKTebNbcw==
+ dependencies:
+ regenerator-runtime "^0.14.0"
+
"@discordjs/builders@^1.10.1":
version "1.10.1"
resolved "https://registry.yarnpkg.com/@discordjs/builders/-/builders-1.10.1.tgz#f30b5d74f8ebaae47c7c70eaf0f8df45eadf9f47"
@@ -1427,6 +1434,18 @@ humanize-ms@^1.2.1:
dependencies:
ms "^2.0.0"
+i18next-fs-backend@^2.6.0:
+ version "2.6.0"
+ resolved "https://registry.yarnpkg.com/i18next-fs-backend/-/i18next-fs-backend-2.6.0.tgz#7b6b54c5ffc2a5073e47eda0673c002376fa1a3c"
+ integrity sha512-3ZlhNoF9yxnM8pa8bWp5120/Ob6t4lVl1l/tbLmkml/ei3ud8IWySCHt2lrY5xWRlSU5D9IV2sm5bEbGuTqwTw==
+
+i18next@^24.2.3:
+ version "24.2.3"
+ resolved "https://registry.yarnpkg.com/i18next/-/i18next-24.2.3.tgz#3a05f72615cbd7c00d7e348667e2aabef1df753b"
+ integrity sha512-lfbf80OzkocvX7nmZtu7nSTNbrTYR52sLWxPtlXX1zAhVw8WEnFk4puUkCR4B1dNQwbSpEHHHemcZu//7EcB7A==
+ dependencies:
+ "@babel/runtime" "^7.26.10"
+
iconv-lite@0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
@@ -2329,6 +2348,11 @@ readdirp@~3.6.0:
dependencies:
picomatch "^2.2.1"
+regenerator-runtime@^0.14.0:
+ version "0.14.1"
+ resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz#356ade10263f685dda125100cd862c1db895327f"
+ integrity sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==
+
require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"