diff --git a/src/commands/_settings.js b/src/commands/_settings.js index cc6acb6..13a7c81 100644 --- a/src/commands/_settings.js +++ b/src/commands/_settings.js @@ -22,9 +22,10 @@ module.exports = class SettingsCommand extends Command { let attachments = [ ...message.attachments.values() ]; if (attachments.length >= 1) { - // load settings from json - let data = await (await fetch(attachments[0].url)).json(); + // load settings from json + this.client.log.info(`Downloading settings for "${guild.name}"`); + let data = await (await fetch(attachments[0].url)).json(); settings.colour = data.colour; settings.error_colour = data.error_colour; settings.locale = data.locale; @@ -33,22 +34,8 @@ module.exports = class SettingsCommand extends Command { await settings.save(); for (let c of data.categories) { - let permissions = [ - ...[ - { - id: guild.roles.everyone, - deny: ['VIEW_CHANNEL'] - } - ], - ...c.roles.map(r => { - return { - id: r, - allow: ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'ATTACH_FILES'] - }; - }) - ]; - if (c.id) { + // existing category let category = await this.client.db.models.Category.findOne({ where: { @@ -60,18 +47,44 @@ module.exports = class SettingsCommand extends Command { category.save(); let cat_channel = await this.client.channels.fetch(c.id); - await cat_channel.edit({ - name: c.name, // await cat_channel.setName(c.name); - permissionOverwrites: permissions // await cat_channel.overwritePermissions(permissions); - }, - `Tickets category updated by ${member.user.tag}` - ); + + if (cat_channel.name !== c.name) + await cat_channel.setName(c.name, `Tickets category updated by ${member.user.tag}`); + + for (let r of c.roles) { + await cat_channel.updateOverwrite(r, { + VIEW_CHANNEL: true, + READ_MESSAGE_HISTORY: true, + SEND_MESSAGES: true, + ATTACH_FILES: true + }, `Tickets category updated by ${member.user.tag}`); + } + } else { + // create a new category + const allowed_permissions = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES']; let cat_channel = await guild.channels.create(c.name, { type: 'category', reason: `Tickets category created by ${member.user.tag}`, - permissionOverwrites: permissions + permissionOverwrites: [ + ...[ + { + id: guild.roles.everyone, + deny: ['VIEW_CHANNEL'] + }, + { + id: this.client.user.id, + allow: allowed_permissions + } + ], + ...c.roles.map(r => { + return { + id: r, + allow: allowed_permissions + }; + }) + ] }); await this.client.db.models.Category.create({ id: cat_channel.id, @@ -79,11 +92,14 @@ module.exports = class SettingsCommand extends Command { guild: guild.id, roles: c.roles }); + } } - + this.client.log.success(`Updated guild settings for "${guild.name}"`); channel.send(i18n('commands.settings.response.updated')); + } else { + // upload settings as json to be modified let data = { categories: [], @@ -116,6 +132,7 @@ module.exports = class SettingsCommand extends Command { channel.send({ files: [attachment] }); + } } }; \ No newline at end of file diff --git a/src/database/index.js b/src/database/index.js index bf97e5c..09418ce 100644 --- a/src/database/index.js +++ b/src/database/index.js @@ -104,7 +104,7 @@ module.exports = async (log) => { unique: 'name_guild' }, guild: { - type: DataTypes.STRING, + type: DataTypes.CHAR(18), allowNull: false, references: { model: Guild, @@ -131,7 +131,7 @@ module.exports = async (log) => { allowNull: false, }, guild: { - type: DataTypes.STRING, + type: DataTypes.CHAR(18), allowNull: false, references: { model: Guild, @@ -139,13 +139,17 @@ module.exports = async (log) => { }, }, category: { - type: DataTypes.STRING, + type: DataTypes.CHAR(18), allowNull: false, references: { model: Category, key: 'id' }, }, + creator: { + type: DataTypes.CHAR(18), + allowNull: false, + }, }, { tableName: DB_TABLE_PREFIX + 'tickets' }); @@ -158,7 +162,7 @@ module.exports = async (log) => { allowNull: false, }, ticket: { - type: DataTypes.STRING, + type: DataTypes.CHAR(18), allowNull: false, references: { model: Ticket, @@ -192,7 +196,7 @@ module.exports = async (log) => { unique: 'id_ticket' }, ticket: { - type: DataTypes.STRING, + type: DataTypes.CHAR(18), allowNull: false, unique: 'id_ticket', references: { @@ -218,7 +222,7 @@ module.exports = async (log) => { unique: 'id_ticket' }, ticket: { - type: DataTypes.STRING, + type: DataTypes.CHAR(18), allowNull: false, unique: 'id_ticket', references: { @@ -239,7 +243,7 @@ module.exports = async (log) => { unique: 'id_ticket' }, ticket: { - type: DataTypes.STRING, + type: DataTypes.CHAR(18), allowNull: false, unique: 'id_ticket', references: { diff --git a/src/listeners/rateLimit.js b/src/listeners/rateLimit.js index f030e1f..28c04d7 100644 --- a/src/listeners/rateLimit.js +++ b/src/listeners/rateLimit.js @@ -1,7 +1,6 @@ module.exports = { event: 'rateLimit', execute: (client, limit) => { - client.log.warn('Rate-limited!'); - client.log.debug(limit); + client.log.warn('Rate-limited!', limit); } }; \ No newline at end of file