From 777719d1b3ee8583ff68547bf4e2e1ad8d9c40ef Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 21 May 2021 21:15:54 +0100 Subject: [PATCH] Fix settings --- src/commands/add.js | 2 +- src/commands/blacklist.js | 2 +- src/commands/close.js | 2 +- src/commands/help.js | 2 +- src/commands/new.js | 2 +- src/commands/panel.js | 2 +- src/commands/remove.js | 2 +- src/commands/settings.js | 2 +- src/commands/stats.js | 2 +- src/commands/survey.js | 2 +- src/commands/tag.js | 2 +- src/commands/topic.js | 2 +- src/listeners/message.js | 2 +- src/listeners/messageDelete.js | 2 +- src/listeners/messageReactionAdd.js | 2 +- src/listeners/messageReactionRemove.js | 2 +- src/listeners/messageUpdate.js | 2 +- src/modules/commands/command.js | 2 +- src/modules/commands/manager.js | 2 +- src/modules/tickets/manager.js | 4 ++-- src/structures/guild.js | 5 +++-- 21 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/commands/add.js b/src/commands/add.js index 51e1331..012cda6 100644 --- a/src/commands/add.js +++ b/src/commands/add.js @@ -34,7 +34,7 @@ module.exports = class AddCommand extends Command { * @returns {Promise} */ async execute(message, args) { - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const ticket = message.mentions.channels.first() ?? message.channel; diff --git a/src/commands/blacklist.js b/src/commands/blacklist.js index 1f5f481..a409b2b 100644 --- a/src/commands/blacklist.js +++ b/src/commands/blacklist.js @@ -31,7 +31,7 @@ module.exports = class BlacklistCommand extends Command { * @returns {Promise} */ async execute(message, args) { - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const member = message.mentions.members.first(); diff --git a/src/commands/close.js b/src/commands/close.js index 4e794f1..984d85b 100644 --- a/src/commands/close.js +++ b/src/commands/close.js @@ -59,7 +59,7 @@ module.exports = class CloseCommand extends Command { const arg_reason = this.args[1].name; const arg_time = this.args[2].name; - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); if (args[arg_time]) { diff --git a/src/commands/help.js b/src/commands/help.js index 7343641..325521e 100644 --- a/src/commands/help.js +++ b/src/commands/help.js @@ -31,7 +31,7 @@ module.exports = class HelpCommand extends Command { * @returns {Promise} */ async execute(message, args) { - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const cmd = this.manager.commands.find(command => command.aliases.includes(args.toLowerCase())); diff --git a/src/commands/new.js b/src/commands/new.js index eb71fd1..7fc7080 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -35,7 +35,7 @@ module.exports = class NewCommand extends Command { * @returns {Promise} */ async execute(message, args) { - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const editOrSend = async (msg, content) => { diff --git a/src/commands/panel.js b/src/commands/panel.js index 6da3d90..7097b33 100644 --- a/src/commands/panel.js +++ b/src/commands/panel.js @@ -69,7 +69,7 @@ module.exports = class PanelCommand extends Command { const arg_emoji = this.args[2].name; const arg_categories = this.args[3].name; - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); if (!args[arg_emoji]) diff --git a/src/commands/remove.js b/src/commands/remove.js index 18b0c3f..5a1920b 100644 --- a/src/commands/remove.js +++ b/src/commands/remove.js @@ -34,7 +34,7 @@ module.exports = class RemoveCommand extends Command { * @returns {Promise} */ async execute(message, args) { - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const ticket = message.mentions.channels.first() ?? message.channel; diff --git a/src/commands/settings.js b/src/commands/settings.js index 3333317..fb48f22 100644 --- a/src/commands/settings.js +++ b/src/commands/settings.js @@ -29,7 +29,7 @@ module.exports = class SettingsCommand extends Command { * @returns {Promise} */ async execute(message) { - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const attachments = [...message.attachments.values()]; diff --git a/src/commands/stats.js b/src/commands/stats.js index 45541d3..3af6545 100644 --- a/src/commands/stats.js +++ b/src/commands/stats.js @@ -27,7 +27,7 @@ module.exports = class StatsCommand extends Command { * @returns {Promise} */ async execute(message) { - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const messages = await this.client.db.models.Message.findAndCountAll(); diff --git a/src/commands/survey.js b/src/commands/survey.js index 117f340..a3345ea 100644 --- a/src/commands/survey.js +++ b/src/commands/survey.js @@ -34,7 +34,7 @@ module.exports = class SurveyCommand extends Command { * @returns {Promise} */ async execute(message, args) { - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const survey = await this.client.db.models.Survey.findOne({ diff --git a/src/commands/tag.js b/src/commands/tag.js index cae8b09..9bafeae 100644 --- a/src/commands/tag.js +++ b/src/commands/tag.js @@ -35,7 +35,7 @@ module.exports = class TagCommand extends Command { * @returns {Promise} */ async execute(message, args) { - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const t_row = await this.client.db.models.Ticket.findOne({ diff --git a/src/commands/topic.js b/src/commands/topic.js index 39108a9..403b3d9 100644 --- a/src/commands/topic.js +++ b/src/commands/topic.js @@ -28,7 +28,7 @@ module.exports = class TopicCommand extends Command { * @returns {Promise} */ async execute(message, args) { - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const t_row = await this.client.db.models.Ticket.findOne({ diff --git a/src/listeners/message.js b/src/listeners/message.js index d00e76a..2f2973a 100644 --- a/src/listeners/message.js +++ b/src/listeners/message.js @@ -13,7 +13,7 @@ module.exports = class MessageEventListener extends EventListener { async execute(message) { if (!message.guild) return; - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const t_row = await this.client.db.models.Ticket.findOne({ diff --git a/src/listeners/messageDelete.js b/src/listeners/messageDelete.js index 2a77660..d43b4bf 100644 --- a/src/listeners/messageDelete.js +++ b/src/listeners/messageDelete.js @@ -10,7 +10,7 @@ module.exports = class MessageDeleteEventListener extends EventListener { async execute(message) { if (!message.guild) return; - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); if (settings.log_messages && !message.system) this.client.tickets.archives.deleteMessage(message); // mark the message as deleted in the database (if it exists) } diff --git a/src/listeners/messageReactionAdd.js b/src/listeners/messageReactionAdd.js index bcb6ac4..6c02725 100644 --- a/src/listeners/messageReactionAdd.js +++ b/src/listeners/messageReactionAdd.js @@ -33,7 +33,7 @@ module.exports = class MessageReactionAddEventListener extends EventListener { const guild = r.message.guild; if (!guild) return; - const settings = await guild.settings; + const settings = await guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const channel = r.message.channel; diff --git a/src/listeners/messageReactionRemove.js b/src/listeners/messageReactionRemove.js index 68dcbac..159fe03 100644 --- a/src/listeners/messageReactionRemove.js +++ b/src/listeners/messageReactionRemove.js @@ -32,7 +32,7 @@ module.exports = class MessageReactionRemoveEventListener extends EventListener const guild = r.message.guild; if (!guild) return; - const settings = await guild.settings; + const settings = await guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const channel = r.message.channel; diff --git a/src/listeners/messageUpdate.js b/src/listeners/messageUpdate.js index f4a6a5e..f501f49 100644 --- a/src/listeners/messageUpdate.js +++ b/src/listeners/messageUpdate.js @@ -18,7 +18,7 @@ module.exports = class MessageUpdateEventListener extends EventListener { if (!newm.guild) return; - const settings = await newm.guild.settings; + const settings = await newm.guild.getSettings(); if (settings.log_messages && !newm.system) this.client.tickets.archives.updateMessage(newm); // update the message in the database } diff --git a/src/modules/commands/command.js b/src/modules/commands/command.js index 500f75e..0dc118a 100644 --- a/src/modules/commands/command.js +++ b/src/modules/commands/command.js @@ -120,7 +120,7 @@ module.exports = class Command { * @returns {Promise} */ async sendUsage(channel, alias) { - const settings = await channel.guild.settings; + const settings = await channel.guild.getSettings(); if (!alias) alias = this.name; const prefix = settings.command_prefix; diff --git a/src/modules/commands/manager.js b/src/modules/commands/manager.js index caaf68c..cb07a29 100644 --- a/src/modules/commands/manager.js +++ b/src/modules/commands/manager.js @@ -69,7 +69,7 @@ module.exports = class CommandManager { async handle(message) { if (message.author.bot) return; // ignore self and other bots - const settings = await message.guild.settings; + const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); let is_blacklisted = false; diff --git a/src/modules/tickets/manager.js b/src/modules/tickets/manager.js index ca49516..851ebc8 100644 --- a/src/modules/tickets/manager.js +++ b/src/modules/tickets/manager.js @@ -80,7 +80,7 @@ module.exports = class TicketManager extends EventEmitter { }); (async () => { - const settings = await guild.settings; + const settings = await guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); topic = t_row.topic @@ -218,7 +218,7 @@ module.exports = class TicketManager extends EventEmitter { this.emit('beforeClose', ticket_id); const guild = this.client.guilds.cache.get(t_row.guild); - const settings = await guild.settings; + const settings = await guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); const channel = await this.client.channels.fetch(t_row.id); diff --git a/src/structures/guild.js b/src/structures/guild.js index 68266e1..1b32fb3 100644 --- a/src/structures/guild.js +++ b/src/structures/guild.js @@ -11,14 +11,15 @@ Structures.extend('Guild', Guild => { return await row.destroy(); } - get settings() { + async getSettings() { const data = { id: this.id }; - return this.client.db.models.Guild.findOrCreate({ + const [settings] = await this.client.db.models.Guild.findOrCreate({ defaults: data, where: data }); + return settings; } }; }); \ No newline at end of file