diff --git a/structure/interfaces/FilterSetting.js b/structure/interfaces/FilterSetting.js index 04b1bb1..f807e89 100644 --- a/structure/interfaces/FilterSetting.js +++ b/structure/interfaces/FilterSetting.js @@ -5,7 +5,7 @@ module.exports = class FilterSetting extends Setting { async _createAction(message, setting) { - const actionObject = { action: null, duration: null, points: null, force: false, prune: false }; + const actionObject = { action: null, duration: null, points: null, expiration: null, force: false, prune: false }; let response = await message.prompt(message.format('S_FILTER_ACTION_ADD_START', { valid: validInfractions.join('`, `') })); if (!response) return { error: true, msg: message.format('ERR_TIMEOUT') }; @@ -20,7 +20,7 @@ module.exports = class FilterSetting extends Setting { const infType = resolver.resolveInfraction(action); if (!infType || !validInfractions.includes(infType)) return { error: true, msg: message.format('S_FILTER_INVALID_INFRACTION', { valid: validInfractions.join('`, `') }) }; - actionObject.action = infType; + actionObject.type = infType; //Add a duration to the action if (['MUTE', 'BAN'].includes(infType)) { @@ -41,9 +41,10 @@ module.exports = class FilterSetting extends Setting { } const settings = message.guild._settings; - //Add points to action if modpoints are enabled + //Add points & expiration to action if modpoints are enabled if (settings.moderationPoints?.enabled) { + // Points response = await message.prompt(message.format('S_FILTER_ACTION_ADD_POINTS')); if (!response) return { error: true, msg: message.format('ERR_TIMEOUT') }; if (['cancel', 'abort', 'exit'].includes(action.toLowerCase())) return { @@ -68,6 +69,22 @@ module.exports = class FilterSetting extends Setting { } + // Expiration + response = await message.prompt(message.format('S_FILTER_ACTION_ADD_EXPIRATION')); + if (!response) return { error: true, msg: message.format('ERR_TIMEOUT') }; + if (['cancel', 'abort', 'exit'].includes(action.toLowerCase())) return { + error: true, + msg: message.format('ERR_CANCEL') + }; + + if (!['no', 'n'].includes(response.content.toLowerCase())) { + + const time = resolver.resolveTime(response.content); + if (!time) message.formattedRespond('S_FILTER_ACTION_ADD_EXPIRATION_FAIL'); + else actionObject.expiration = time; + + } + } //Should it force the action if automod is enabled @@ -171,11 +188,35 @@ module.exports = class FilterSetting extends Setting { if (prop === 'trigger') return this._editTrigger(message, setting, action); else if (prop === 'duration') return this._editDuration(message, setting, action); else if (prop === 'points') return this._editPoints(message, setting, action); + else if (prop === 'expiration') return this._editExpiration(message, setting, action); else if (prop === 'action') return this._editType(message, setting, action); else if (['force', 'prune'].includes(prop)) return this._editBool(message, setting, action, prop); } + async _editExpiration(message, setting, action) { + + if (!message.guild._settings.moderationPoints?.enabled) return { + error: true, + msg: message.format('S_FILTER_ACTION_EDIT_POINTS_DISABLED') + }; + + const response = await message.prompt(message.format('S_FILTER_ACTION_EDIT_EXPIRATION', {}), { time: 60 * 1000 }); + + if (!response) return { error: true, msg: message.format('ERR_TIMEOUT') }; + if (['cancel', 'abort', 'exit'].includes(response.content.toLowerCase())) return { + error: true, + msg: message.format('ERR_CANCEL') + }; + + const { resolver } = this.client; + + const time = resolver.resolveTime(response.content); + if (time === null) message.formattedRespond('S_FILTER_ACTION_ADD_EXPIRATION_FAIL'); + else action.expiration = time; + + } + async _editBool(message, setting, action, prop) { const response = await message.prompt(message.format('S_FILTER_ACTION_EDIT_BOOL', { prop }), { time: 120 * 1000 }); @@ -205,7 +246,7 @@ module.exports = class FilterSetting extends Setting { msg: message.format('S_FILTER_ACTION_EDIT_POINTS_DISABLED') }; - const response = await message.prompt(message.format('S_FILTER_ACTION_EDIT_POINTS', {}), { time: 120 * 1000 }); + const response = await message.prompt(message.format('S_FILTER_ACTION_EDIT_POINTS', {}), { time: 60 * 1000 }); if (!response) return { error: true, msg: message.format('ERR_TIMEOUT') }; if (['cancel', 'abort', 'exit'].includes(response.content.toLowerCase())) return { @@ -247,8 +288,8 @@ module.exports = class FilterSetting extends Setting { msg: message.format('S_FILTER_ACTION_EDIT_INVALID_TYPE') }; - action.action = response.content.toUpperCase(); - if (['BAN', 'MUTE'].includes(action.action) && !action.duration) return this._editDuration(message, setting, action); + action.type = response.content.toUpperCase(); + if (['BAN', 'MUTE'].includes(action.type) && !action.duration) return this._editDuration(message, setting, action); action.duration = null; return action; @@ -257,9 +298,9 @@ module.exports = class FilterSetting extends Setting { async _editDuration(message, setting, action) { - if (!['MUTE', 'BAN'].includes(action.action)) return { + if (!['MUTE', 'BAN'].includes(action.type)) return { error: true, - msg: message.format('S_FILTER_ACTION_EDIT_DURATION_ERR', { action: action.action }) + msg: message.format('S_FILTER_ACTION_EDIT_DURATION_ERR', { action: action.type }) }; const response = await message.prompt(message.format('S_FILTER_ACTION_EDIT_DURATION', {}), { time: 120 * 1000 }); @@ -301,7 +342,7 @@ module.exports = class FilterSetting extends Setting { const embed = { fields: actions.map((action) => { return { - name: `**[${actions.indexOf(action)}]** ${action.action}`, + name: `**[${actions.indexOf(action)}]** ${action.type}`, value: message.format('S_FILTER_ACTION_PROPERTIES', { duration: action.duration ? resolver.timeAgo(action.duration) : 'INF', points: action.points || message.format('ON_OFF_TOGGLE', { toggle: false }, true),