From d37cc8c56cbf8c9ffe7023c671abe0d579ea875d Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 30 Mar 2025 17:21:29 -0400 Subject: Moved models to the db folder --- bot/src/api/routes/quotes.js | 2 +- bot/src/api/routes/settings.js | 2 +- bot/src/commands/quote.js | 2 +- bot/src/commands/settings.js | 2 +- bot/src/commands/stats.js | 4 +-- bot/src/commands/suggest.js | 2 +- bot/src/db/models/command-usages.js | 26 +++++++++++++++ bot/src/db/models/guild-settings.js | 35 ++++++++++++++++++++ bot/src/db/models/quote.js | 64 +++++++++++++++++++++++++++++++++++++ bot/src/events/GuildBanAdd.js | 2 +- bot/src/events/GuildBanRemove.js | 2 +- bot/src/events/GuildCreate.js | 2 +- bot/src/events/GuildDelete.js | 2 +- bot/src/events/GuildMemberAdd.js | 2 +- bot/src/events/GuildMemberRemove.js | 2 +- bot/src/events/GuildMemberUpdate.js | 3 +- bot/src/events/MessageBulkDelete.js | 2 +- bot/src/events/MessageDelete.js | 2 +- bot/src/events/MessageUpdate.js | 2 +- bot/src/models/command-usages.js | 26 --------------- bot/src/models/guild-settings.js | 35 -------------------- bot/src/models/quote.js | 64 ------------------------------------- bot/src/plugins/analytics.js | 2 +- bot/src/plugins/chatbot.js | 2 +- bot/src/plugins/qotd.js | 4 +-- bot/src/utils/sync.js | 6 ++-- 26 files changed, 149 insertions(+), 150 deletions(-) create mode 100644 bot/src/db/models/command-usages.js create mode 100644 bot/src/db/models/guild-settings.js create mode 100644 bot/src/db/models/quote.js delete mode 100644 bot/src/models/command-usages.js delete mode 100644 bot/src/models/guild-settings.js delete mode 100644 bot/src/models/quote.js (limited to 'bot/src') diff --git a/bot/src/api/routes/quotes.js b/bot/src/api/routes/quotes.js index 1b89f67..af61174 100644 --- a/bot/src/api/routes/quotes.js +++ b/bot/src/api/routes/quotes.js @@ -1,5 +1,5 @@ import { Router } from 'express'; -import { pendingQuote, quote as newQuote } from '../../models/quote.js'; +import { pendingQuote, quote as newQuote } from '../../db/models/quote.js'; import { verifyToken } from './auth.js'; export function quoteRouter(client) { diff --git a/bot/src/api/routes/settings.js b/bot/src/api/routes/settings.js index 3722fd2..516d8c9 100644 --- a/bot/src/api/routes/settings.js +++ b/bot/src/api/routes/settings.js @@ -1,6 +1,6 @@ import { ChannelType } from 'discord.js'; import { Router } from 'express'; -import { guildSettings } from '../../models/guild-settings.js'; +import { guildSettings } from '../../db/models/guild-settings.js'; import { verifyToken } from './auth.js'; export function settingsRouter(client) { diff --git a/bot/src/commands/quote.js b/bot/src/commands/quote.js index 9c409f9..3bc71d3 100644 --- a/bot/src/commands/quote.js +++ b/bot/src/commands/quote.js @@ -6,7 +6,7 @@ import { TextInputBuilder, TextInputStyle, ActionRowBuilder } from 'discord.js'; -import { pendingQuote, quote as quoteDB } from '../models/quote.js'; +import { pendingQuote, quote as quoteDB } from '../db/models/quote.js'; import { abEmbedColour } from '../storage/consts.js'; // import { setTimeout as wait } from 'node:timers/promises'; // diff --git a/bot/src/commands/settings.js b/bot/src/commands/settings.js index cb06c99..36fe4d9 100644 --- a/bot/src/commands/settings.js +++ b/bot/src/commands/settings.js @@ -1,5 +1,5 @@ import { PermissionFlagsBits, SlashCommandBuilder, MessageFlags, EmbedBuilder } from 'discord.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; import { abEmbedColour } from '../storage/consts.js'; export default { data: new SlashCommandBuilder() diff --git a/bot/src/commands/stats.js b/bot/src/commands/stats.js index 6924874..a961245 100644 --- a/bot/src/commands/stats.js +++ b/bot/src/commands/stats.js @@ -1,7 +1,7 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; -import { commandUsages } from '../models/command-usages.js'; +import { commandUsages } from '../db/models/command-usages.js'; import { abEmbedColour } from '../storage/consts.js'; -import { quote } from '../models/quote.js'; +import { quote } from '../db/models/quote.js'; export default { data: new SlashCommandBuilder() diff --git a/bot/src/commands/suggest.js b/bot/src/commands/suggest.js index 6c3209f..7c4b75a 100644 --- a/bot/src/commands/suggest.js +++ b/bot/src/commands/suggest.js @@ -8,7 +8,7 @@ import { EmbedBuilder } from 'discord.js'; import { abEmbedColour, featureSuggestChannel } from '../storage/consts.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; export default { data: new SlashCommandBuilder() diff --git a/bot/src/db/models/command-usages.js b/bot/src/db/models/command-usages.js new file mode 100644 index 0000000..21b4c86 --- /dev/null +++ b/bot/src/db/models/command-usages.js @@ -0,0 +1,26 @@ +import { INTEGER, STRING } from 'sequelize'; +import { sequelize } from '../../utils/sequelize.js'; + +export const commandUsages = sequelize.define('command-usages', { + id: { + type: INTEGER, + autoIncrement: true, + primaryKey: true + }, + command: { + type: STRING, + allowNull: false + }, + userID: { + type: STRING, + allowNull: false + }, + guildID: { + type: STRING, + allowNull: true + } + +}, { + updatedAt: false, +}); + diff --git a/bot/src/db/models/guild-settings.js b/bot/src/db/models/guild-settings.js new file mode 100644 index 0000000..c6bcaa4 --- /dev/null +++ b/bot/src/db/models/guild-settings.js @@ -0,0 +1,35 @@ +import { INTEGER, STRING, BOOLEAN } from 'sequelize'; +import { sequelize } from '../../utils/sequelize.js'; + +export const guildSettings = sequelize.define('guild-settings', { + id: { + type: INTEGER, + primaryKey: true, + autoIncrement: true, + }, + guildID: { + type: STRING, + allowNull: false + }, + logChannelID: { + type: STRING, + allowNull: true + }, + suggestionsChannelID: { + type: STRING, + allowNull: true + }, + qotdChannelID: { + type: STRING, + allowNull: true + }, + qotdToggle: { + type: BOOLEAN, + allowNull: true + }, + ollamaEnabled: { + type: BOOLEAN, + allowNull: true + }, + +}); diff --git a/bot/src/db/models/quote.js b/bot/src/db/models/quote.js new file mode 100644 index 0000000..3ff705d --- /dev/null +++ b/bot/src/db/models/quote.js @@ -0,0 +1,64 @@ +import { INTEGER, STRING, TEXT } from 'sequelize'; +import { sequelize } from '../../utils/sequelize.js'; + +export const quote = sequelize.define('quotes', { + id: { + type: INTEGER, + autoIncrement: true, + primaryKey: true + }, + author: { + type: STRING, + allowNull: false + }, + authorImage: { + type: STRING, + allowNull: false + }, + quote: { + type: TEXT, + allowNull: false + }, + year: { + type: STRING, + allowNull: false + }, + submitter: { + type: STRING, + allowNull: false + } + +}); + +export const pendingQuote = sequelize.define('pending-quotes', { + id: { + type: INTEGER, + autoIncrement: true, + primaryKey: true + }, + author: { + type: STRING, + allowNull: false + }, + authorImage: { + type: STRING, + allowNull: false + }, + quote: { + type: TEXT, + allowNull: false + }, + year: { + type: STRING, + allowNull: false + }, + submitterAuthor: { + type: STRING, + allowNull: false + }, + submitterID: { + type: STRING, + allowNull: false + } + +}); diff --git a/bot/src/events/GuildBanAdd.js b/bot/src/events/GuildBanAdd.js index 85f365e..4e876a9 100644 --- a/bot/src/events/GuildBanAdd.js +++ b/bot/src/events/GuildBanAdd.js @@ -1,5 +1,5 @@ import { EmbedBuilder, Events, AuditLogEvent } from 'discord.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; export default { name: Events.GuildBanAdd, diff --git a/bot/src/events/GuildBanRemove.js b/bot/src/events/GuildBanRemove.js index 8873054..b1d2e74 100644 --- a/bot/src/events/GuildBanRemove.js +++ b/bot/src/events/GuildBanRemove.js @@ -1,5 +1,5 @@ import { EmbedBuilder, Events } from 'discord.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; export default { name: Events.GuildBanRemove, diff --git a/bot/src/events/GuildCreate.js b/bot/src/events/GuildCreate.js index b5c64a5..702da52 100644 --- a/bot/src/events/GuildCreate.js +++ b/bot/src/events/GuildCreate.js @@ -1,6 +1,6 @@ import { EmbedBuilder, Events } from 'discord.js'; import { abEmbedColour } from '../storage/consts.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; export default { name: Events.GuildCreate, diff --git a/bot/src/events/GuildDelete.js b/bot/src/events/GuildDelete.js index 51ac448..79a9e68 100644 --- a/bot/src/events/GuildDelete.js +++ b/bot/src/events/GuildDelete.js @@ -1,6 +1,6 @@ import { EmbedBuilder, Events } from 'discord.js'; import { abEmbedColour } from '../storage/consts.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; export default { name: Events.GuildDelete, diff --git a/bot/src/events/GuildMemberAdd.js b/bot/src/events/GuildMemberAdd.js index d346473..760b785 100644 --- a/bot/src/events/GuildMemberAdd.js +++ b/bot/src/events/GuildMemberAdd.js @@ -1,5 +1,5 @@ import { EmbedBuilder, Events } from 'discord.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; import { autoRole, serverWhitelist, roleWhitelist } from '../storage/consts.js'; export default { diff --git a/bot/src/events/GuildMemberRemove.js b/bot/src/events/GuildMemberRemove.js index 0ae96db..e89c2c4 100644 --- a/bot/src/events/GuildMemberRemove.js +++ b/bot/src/events/GuildMemberRemove.js @@ -1,5 +1,5 @@ import { EmbedBuilder, Events } from 'discord.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; export default { name: Events.GuildMemberRemove, diff --git a/bot/src/events/GuildMemberUpdate.js b/bot/src/events/GuildMemberUpdate.js index 1fec4fe..74b8034 100644 --- a/bot/src/events/GuildMemberUpdate.js +++ b/bot/src/events/GuildMemberUpdate.js @@ -1,5 +1,5 @@ import { EmbedBuilder, Events } from 'discord.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; export default { name: Events.GuildMemberUpdate, @@ -7,7 +7,6 @@ export default { try { const guildSetting = await guildSettings.findOne({ where: { guildID: member.guild.id } }); if (!guildSetting || !guildSetting.logChannelID) return; - if (!member.nickname || member.nickname === newMember.nickname) return; const logEmbed = new EmbedBuilder() .setAuthor({ name: 'AleeBot Logging', iconURL: member.client.user.avatarURL() }) diff --git a/bot/src/events/MessageBulkDelete.js b/bot/src/events/MessageBulkDelete.js index 5a9445e..583c6d2 100644 --- a/bot/src/events/MessageBulkDelete.js +++ b/bot/src/events/MessageBulkDelete.js @@ -1,5 +1,5 @@ import { EmbedBuilder, Events, AttachmentBuilder } from 'discord.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; export default { name: Events.MessageBulkDelete, diff --git a/bot/src/events/MessageDelete.js b/bot/src/events/MessageDelete.js index 1823c09..7c1af1c 100644 --- a/bot/src/events/MessageDelete.js +++ b/bot/src/events/MessageDelete.js @@ -1,5 +1,5 @@ import {AttachmentBuilder, EmbedBuilder, Events} from 'discord.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; export default { name: Events.MessageDelete, diff --git a/bot/src/events/MessageUpdate.js b/bot/src/events/MessageUpdate.js index 5bbee20..00c605a 100644 --- a/bot/src/events/MessageUpdate.js +++ b/bot/src/events/MessageUpdate.js @@ -1,5 +1,5 @@ import { EmbedBuilder, Events, AttachmentBuilder } from 'discord.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; export default { name: Events.MessageUpdate, diff --git a/bot/src/models/command-usages.js b/bot/src/models/command-usages.js deleted file mode 100644 index a9dafa4..0000000 --- a/bot/src/models/command-usages.js +++ /dev/null @@ -1,26 +0,0 @@ -import { INTEGER, STRING } from 'sequelize'; -import { sequelize } from '../utils/sequelize.js'; - -export const commandUsages = sequelize.define('command-usages', { - id: { - type: INTEGER, - autoIncrement: true, - primaryKey: true - }, - command: { - type: STRING, - allowNull: false - }, - userID: { - type: STRING, - allowNull: false - }, - guildID: { - type: STRING, - allowNull: true - } - -}, { - updatedAt: false, -}); - diff --git a/bot/src/models/guild-settings.js b/bot/src/models/guild-settings.js deleted file mode 100644 index bb4d30b..0000000 --- a/bot/src/models/guild-settings.js +++ /dev/null @@ -1,35 +0,0 @@ -import { INTEGER, STRING, BOOLEAN } from 'sequelize'; -import { sequelize } from '../utils/sequelize.js'; - -export const guildSettings = sequelize.define('guild-settings', { - id: { - type: INTEGER, - primaryKey: true, - autoIncrement: true, - }, - guildID: { - type: STRING, - allowNull: false - }, - logChannelID: { - type: STRING, - allowNull: true - }, - suggestionsChannelID: { - type: STRING, - allowNull: true - }, - qotdChannelID: { - type: STRING, - allowNull: true - }, - qotdToggle: { - type: BOOLEAN, - allowNull: true - }, - ollamaEnabled: { - type: BOOLEAN, - allowNull: true - }, - -}); diff --git a/bot/src/models/quote.js b/bot/src/models/quote.js deleted file mode 100644 index 9d0ad00..0000000 --- a/bot/src/models/quote.js +++ /dev/null @@ -1,64 +0,0 @@ -import { INTEGER, STRING, TEXT } from 'sequelize'; -import { sequelize } from '../utils/sequelize.js'; - -export const quote = sequelize.define('quotes', { - id: { - type: INTEGER, - autoIncrement: true, - primaryKey: true - }, - author: { - type: STRING, - allowNull: false - }, - authorImage: { - type: STRING, - allowNull: false - }, - quote: { - type: TEXT, - allowNull: false - }, - year: { - type: STRING, - allowNull: false - }, - submitter: { - type: STRING, - allowNull: false - } - -}); - -export const pendingQuote = sequelize.define('pending-quotes', { - id: { - type: INTEGER, - autoIncrement: true, - primaryKey: true - }, - author: { - type: STRING, - allowNull: false - }, - authorImage: { - type: STRING, - allowNull: false - }, - quote: { - type: TEXT, - allowNull: false - }, - year: { - type: STRING, - allowNull: false - }, - submitterAuthor: { - type: STRING, - allowNull: false - }, - submitterID: { - type: STRING, - allowNull: false - } - -}); diff --git a/bot/src/plugins/analytics.js b/bot/src/plugins/analytics.js index 137207f..8ed968b 100644 --- a/bot/src/plugins/analytics.js +++ b/bot/src/plugins/analytics.js @@ -1,4 +1,4 @@ -import { commandUsages } from '../models/command-usages.js'; +import { commandUsages } from '../db/models/command-usages.js'; import { enableAnalytics } from '../storage/consts.js'; export async function Analytics(command, interaction) { diff --git a/bot/src/plugins/chatbot.js b/bot/src/plugins/chatbot.js index 705f267..a799738 100644 --- a/bot/src/plugins/chatbot.js +++ b/bot/src/plugins/chatbot.js @@ -1,7 +1,7 @@ import { ollamaGlobal } from '../storage/consts.js'; import { ollama } from '../utils/ollama.js'; import { AttachmentBuilder } from 'discord.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { guildSettings } from '../db/models/guild-settings.js'; import 'dotenv/config'; export async function ChatBot(msg, args) { diff --git a/bot/src/plugins/qotd.js b/bot/src/plugins/qotd.js index 16ae507..73882be 100644 --- a/bot/src/plugins/qotd.js +++ b/bot/src/plugins/qotd.js @@ -1,7 +1,7 @@ import { EmbedBuilder } from 'discord.js'; import { abEmbedColour } from '../storage/consts.js'; -import { quote as quoteDB } from '../models/quote.js'; -import { guildSettings } from '../models/guild-settings.js'; +import { quote as quoteDB } from '../db/models/quote.js'; +import { guildSettings } from '../db/models/guild-settings.js'; import { schedule } from 'node-cron'; export function QuoteOfTheDay(client) { diff --git a/bot/src/utils/sync.js b/bot/src/utils/sync.js index fa3d8c9..9e11971 100644 --- a/bot/src/utils/sync.js +++ b/bot/src/utils/sync.js @@ -1,6 +1,6 @@ -import { quote, pendingQuote } from '../models/quote.js'; -import { guildSettings } from '../models/guild-settings.js'; -import { commandUsages } from '../models/command-usages.js'; +import { quote, pendingQuote } from '../db/models/quote.js'; +import { guildSettings } from '../db/models/guild-settings.js'; +import { commandUsages } from '../db/models/command-usages.js'; export function syncDB() { quote.sync().then(() => { -- cgit v1.2.3