aboutsummaryrefslogtreecommitdiff
path: root/bot/src
diff options
context:
space:
mode:
authorAndrew Lee <andrew@alee14.me>2025-04-02 02:21:41 -0400
committerAndrew Lee <andrew@alee14.me>2025-04-02 02:21:41 -0400
commit10434adad478d21bbb834a5803125db9f54c9d6c (patch)
treee1159a26948d24c2a065dfd15f71b64970515930 /bot/src
parent657599acccf351c7c9366cec9f648b7496c89bdb (diff)
downloadAleeBot-10434adad478d21bbb834a5803125db9f54c9d6c.tar.gz
AleeBot-10434adad478d21bbb834a5803125db9f54c9d6c.tar.bz2
AleeBot-10434adad478d21bbb834a5803125db9f54c9d6c.zip
Added i18n (basic); Blacklist feature; Put error msg into a filebeta
Diffstat (limited to 'bot/src')
-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
15 files changed, 153 insertions, 8 deletions
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!');
+ });
}