diff --git a/config/default.js b/config/default.js index a291ebb..cf3ead1 100644 --- a/config/default.js +++ b/config/default.js @@ -109,28 +109,42 @@ module.exports = { }, support: { category: '740654285154549901', - automaticDeletion: 3600000, types: { 'minez': { description: "Support for MineZ: Stuck in a block; Broken dungeons; Death due to cheaters, bugs, and broken dungeons.", - roles: ['618856455206076417'] + roles: [{ id: '618856455206076417', ping: true }], + logRoom: '748963030888349736', + autoClose: { + warning: ONE_DAY_IN_MS, + closing: 2 * ONE_DAY_IN_MS + } }, 'abuse': { description: "Open a private chat with the leadership team to report staff abuse.", - roles: ['440505209580683274', '441611057878794240'], + roles: [ + { id: '440505209580683274', ping: true }, + { id: '441611057878794240', ping: true } + ], + logRoom: '748963030888349736', + autoClose: { + warning: ONE_DAY_IN_MS, + closing: 2 * ONE_DAY_IN_MS + } + }, + 'bug': { + description: "Open a support channel to report a bug to the development team.", + roles: [ + { id: '223821346763833344', ping: false }, + { id: '815871997871128576', ping: true } + ], logRoom: '748963030888349736' } - }, - autoClose: { - warning: ONE_DAY_IN_MS, - closing: 2 * ONE_DAY_IN_MS } }, nitro: { channel: '585535847110017028', manualUpgradeStaffer: 'Navarr' }, - supportCategory: 'Support', messageRemoveDelay: 60000, pingspam: { threshold: 5, diff --git a/src/Command/Support.js b/src/Command/Support.js index 9d99694..5d884a3 100644 --- a/src/Command/Support.js +++ b/src/Command/Support.js @@ -52,7 +52,8 @@ module.exports = Command.extend({ return message.channel.send(this.i18n.__mf(messages.notASupportRoom)); } - if (!RoleDeterminer.hasOneOfRoles(message.member, this.config.support.types[typeKey].roles)) { + const roleIds = this.config.support.types[typeKey].roles.map(role => role.id); + if (!RoleDeterminer.hasOneOfRoles(message.member, roleIds)) { return message.channel.send(this.i18n.__mf(messages.noPermission)); } @@ -108,8 +109,8 @@ module.exports = Command.extend({ VIEW_CHANNEL: true })) .then(async channel => { - for (const supportRoleId of type.roles) { - await channel.updateOverwrite(supportRoleId, { + for (const supportRole of type.roles) { + await channel.updateOverwrite(supportRole.id, { ADD_REACTIONS: true, ATTACH_FILES: true, EMBED_LINKS: true, @@ -124,8 +125,9 @@ module.exports = Command.extend({ }) .catch(() => { /* If something went wrong with room creation, we delete it (if it was created) and notify the user */ - supportChannel.delete().catch(() => { - }); + if (supportChannel) { + supportChannel.delete().catch(() => {}); + } return message.channel.send(this.i18n.__mf(messages.roomCreationError)); }); @@ -136,19 +138,20 @@ module.exports = Command.extend({ })); /* Add the collector to deal with post-creation events */ - this.addCollector(supportChannel, message.member, welcomeMessage); + this.addCollector(supportChannel, type, message.member, welcomeMessage); await supportChannel.send(this.i18n.__mf(messages.supportRules)); return message.channel.send(this.i18n.__mf(messages.roomCreated, {type: typeKey})); }, - addCollector: function (supportChannel, creator, welcomeMessage) { + addCollector: function (supportChannel, supportType, creator, welcomeMessage) { const collectorFilter = (message) => message.member.id === creator.id; - - const automaticDelete = this.config.support.automaticDeletion; + let collector; - if (automaticDelete < 0) { + if (!supportType.autoClose || !supportType.autoClose.closing + || supportType.autoClose.closing < 0) { collector = supportChannel.createMessageCollector(collectorFilter); } else { + const automaticDelete = supportType.autoClose.closing; collector = supportChannel.createMessageCollector(collectorFilter, {time: automaticDelete}); collector.on('end', async (_, reason) => { @@ -161,7 +164,8 @@ module.exports = Command.extend({ collector.once('collect', (message) => { const supportType = parseRoomType(supportChannel.name); const supportRoles = this.config.support.types[supportType].roles - .map(supportRole => `<@&${supportRole}>`) + .filter(supportRole => supportRole.ping) + .map(supportRole => `<@&${supportRole.id}>`) .join(', '); message.channel.send(this.i18n.__mf(messages.supportMessageReceived, {roles: supportRoles})); diff --git a/src/Helper/SupportRoomConverter.js b/src/Helper/SupportRoomConverter.js index a13bbdb..28ae9dd 100644 --- a/src/Helper/SupportRoomConverter.js +++ b/src/Helper/SupportRoomConverter.js @@ -50,15 +50,15 @@ const convertRoom = async (message, tokens, i18n) => { } /* Remove old support roles and add new ones */ - for (const supportRoleId of oldType.roles) { - await supportRoom.permissionOverwrites.get(supportRoleId) + for (const supportRole of oldType.roles) { + await supportRoom.permissionOverwrites.get(supportRole.id) .delete('Support room type conversion') .catch((e) => { console.log(e) }); } - for (const supportRoleId of newType.roles) { - await supportRoom.updateOverwrite(supportRoleId, { + for (const supportRole of newType.roles) { + await supportRoom.updateOverwrite(supportRole.id, { ADD_REACTIONS: true, ATTACH_FILES: true, EMBED_LINKS: true, diff --git a/src/Utility/SupportCloser.js b/src/Utility/SupportCloser.js index fb2b365..134be8e 100644 --- a/src/Utility/SupportCloser.js +++ b/src/Utility/SupportCloser.js @@ -1,5 +1,6 @@ const BotModule = require('../BotModule'); const archiveRoom = require('../Helper/SupportRoomArchiver'); +const parseRoomType = require('../Helper/SupportRoomTypeParser'); const messages = { 'warning': 'It appears that there was no activity in this room for a while. If no more activity takes place, I will automatically close this channel.' @@ -36,8 +37,10 @@ module.exports = BotModule.extend({ const now = this.moment(); /* Check if we should send a warning notice */ + const typeKey = parseRoomType(supportRoom.name); let messageTimestamp = this.moment(lastMessage.createdTimestamp); - if (now.isAfter(messageTimestamp.add(this.config.support.autoClose.warning, 'ms')) + if (this.config.support.types[typeKey].autoClose && this.config.support.types[typeKey].autoClose.warning + && now.isAfter(messageTimestamp.add(this.config.support.types[typeKey].autoClose.warning, 'ms')) && lastMessage.content !== messages.warning) { supportRoom.send(this.i18n.__mf(messages.warning, {timeInactivity: 0, timeToClose: 0})); return; @@ -46,7 +49,8 @@ module.exports = BotModule.extend({ /* Check if we should close the channel (moment mutates the timestamp, hence the re-init) */ messageTimestamp = this.moment(lastMessage.createdTimestamp); if (lastMessage.content === messages.warning - && now.isAfter(messageTimestamp.add(this.config.support.autoClose.closing, 'ms'))) { + && this.config.support.types[typeKey].autoClose && this.config.support.types[typeKey].autoClose.closing + && now.isAfter(messageTimestamp.add(this.config.support.types[typeKey].autoClose.closing, 'ms'))) { await archiveRoom(lastMessage, this.i18n, this.discordClient); } }); diff --git a/src/Utility/TrickcordTreat.js b/src/Utility/TrickcordTreat.js index 3aef5ad..eae07c8 100644 --- a/src/Utility/TrickcordTreat.js +++ b/src/Utility/TrickcordTreat.js @@ -28,8 +28,6 @@ module.exports = BotModule.extend({ this.timeout = typeof this.config.trickcordTreatDeleteTime != 'undefined' ? this.config.trickcordTreatDeleteTime : ONE_MINUTE_IN_MS; - - console.log(this.config.trickcordTreatRoom); }, /**