diff --git a/config/default.yml b/config/default.yml index 27241077..8b31ba44 100644 --- a/config/default.yml +++ b/config/default.yml @@ -42,6 +42,13 @@ request: ignorePrependResponseMessageEmoji: ✅ ignoreResolutionEmoji: 💬 + normalNotificationsRole: #TODO + speicalNotificationsRole: #TODO + oldNotificationsRole: #TODO + oldNotificationsTimeDifference: 259200000 # 3 days + longNotificationsRole: #TODO + longNotificationsTimeDifference: 604800000 # 1 week + resolveDelay: 10000 progressMessageAddDelay: 10000 prependResponseMessage: whenResolved diff --git a/config/main.yml b/config/main.yml index ad90cf11..6aebbee1 100644 --- a/config/main.yml +++ b/config/main.yml @@ -77,6 +77,35 @@ roleGroups: title: Other Pronoun desc: (please indicate in your nickname) emoji: '🇴' + - prompt: |- + Request Notifications (1/2) + Select reaction(s) on this message to be notified in DMs when specific requests are resolved. + channel: '648479533246316555' + message: #TODO + radio: false + roles: + - id: #TODO + desc: Be notified of your resolved requests that are resolved as ✅. + emoji: '✅' + - id: #TODO + desc: Be notified of your resolved requests that are not resolved as ✅. + emoji: '☑️' + - prompt: |- + Request Notifications (2/2) + Select a reaction on this message if you want to be notified in DMs when requests are resolved after a certain amount of time. + No reaction means no time requirement. + channel: '648479533246316555' + message: #TODO + radio: true + roles: + - id: #TODO + desc: Be notified of your resolved requests that are resolved at least three days after creation. + emoji: '3️⃣' + - id: #TODO + desc: Be notified of your resolved requests that are resolved at least one week after creation. + emoji: '7️⃣' + + filterFeeds: - jql: project = MC AND resolved > lastRun AND resolution = Fixed AND fixVersion in unreleasedVersions() diff --git a/config/template.yml b/config/template.yml index 7b15a99c..4892b187 100644 --- a/config/template.yml +++ b/config/template.yml @@ -115,10 +115,32 @@ request: # An emoji or emoji ID which, when used, doesn't trigger the response template message. ignorePrependResponseMessageEmoji: - + # An emoji or emoji ID which, when used, doesn't resolve the request. ignoreResolutionEmoji: + # The ID of the role that signifies users that get notifications from some of their resolved requests. + # This includes only the ignorePrependResponseMessageEmoji resolution. + normalNotificationsRole: + + # The ID of the role that signifies users that get some of the notifications from their resolved requests. + # This does not include the ignorePrependResponseMessageEmoji resolution. + specialNotificationsRole: + + # The ID of the role that signifies users that get all notifications from their resolved requests from a certain time period before. + oldNotificationsRole: + + # The amount of time in milliseconds that needs to occur after creating a request before a user will get a notification for their report. + # Only applies to the oldNotificationsRole. + oldNotificationsTimeDifference: + + # The ID of the role that signifies users that get all notifications from their resolved requests from a certain, longer, time period before. + longNotificationsRole: + + # The amount of time in milliseconds that needs to occur after creating a request before a user will get a notification for their report. + # Only applies to the longNotificationsRole. + longNotificationsTimeDifference: + # The amount of time in milliseconds between a volunteer reacts to the message and the bot deletes its message. resolveDelay: diff --git a/src/BotConfig.ts b/src/BotConfig.ts index 66f3b11c..b00acab2 100644 --- a/src/BotConfig.ts +++ b/src/BotConfig.ts @@ -29,6 +29,12 @@ export class RequestConfig { public suggestedEmoji: string[]; public ignorePrependResponseMessageEmoji: string; public ignoreResolutionEmoji: string; + public normalNotificationsRole: string; + public specialNotificationsRole: string; + public oldNotificationsRole: string; + public oldNotificationsTimeDifference: number; + public longNotificationsRole: string; + public longNotificationsTimeDifference: number; public resolveDelay: number; public progressMessageAddDelay: number; public prependResponseMessage: PrependResponseMessageType; @@ -55,6 +61,13 @@ export class RequestConfig { this.ignorePrependResponseMessageEmoji = config.get( 'request.ignorePrependResponseMessageEmoji' ); this.ignoreResolutionEmoji = config.get( 'request.ignoreResolutionEmoji' ); + this.normalNotificationsRole = config.get( 'request.normalNotificationsRole' ); + this.specialNotificationsRole = config.get( 'request.specialNotificationsRole' ); + this.oldNotificationsRole = config.get( 'request.oldNotificationsRole' ); + this.oldNotificationsTimeDifference = config.get( 'request.oldNotificationsTimeDifference' ); + this.longNotificationsRole = config.get( 'request.longNotificationsRole' ); + this.longNotificationsTimeDifference = config.get( 'request.longNotificationsTimeDifference' ); + this.resolveDelay = config.get( 'request.resolveDelay' ); this.progressMessageAddDelay = config.get( 'request.progressMessageAddDelay' ); this.prependResponseMessage = getOrDefault( 'request.prependResponseMessage', PrependResponseMessageType.Never ); diff --git a/src/tasks/ResolveRequestMessageTask.ts b/src/tasks/ResolveRequestMessageTask.ts index e6edbc31..022a7309 100644 --- a/src/tasks/ResolveRequestMessageTask.ts +++ b/src/tasks/ResolveRequestMessageTask.ts @@ -44,6 +44,84 @@ export default class ResolveRequestMessageTask extends MessageTask { ResolveRequestMessageTask.logger.error( error ); } + if ( origin.author ) { + const response = BotConfig.request.prependResponseMessageInLog ? + RequestsUtil.getResponseMessage( origin ) : ''; + + const log = new MessageEmbed() + .setColor( 'GREEN' ) + .setAuthor( origin.author.tag, origin.author.avatarURL() ) + .setDescription( origin.content ) + .addField( 'Channel', origin.channel.toString(), true ) + .addField( 'Message', `[Here](${ origin.url })`, true ) + .setFooter( `${ this.user.tag } resolved as ${ this.emoji }`, this.user.avatarURL() ) + .setTimestamp( new Date() ); + + if ( origin.member.roles.cache.has( BotConfig.request.normalNotificationsRole ) && this.emoji === BotConfig.request.ignorePrependResponseMessageEmoji ) { + if ( origin.member.roles.cache.has( BotConfig.request.oldNotificationsRole ) ) { + const curTime = new Date(); + const createdTime = origin.createdAt; + const timeDifference = Math.abs( curTime.getTime() - createdTime.getTime() ); + if ( timeDifference >= BotConfig.request.oldNotificationsTimeDifference ) { + try { + await origin.author.send( response, log ); + } catch ( error ) { + ResolveRequestMessageTask.logger.error( error ); + } + } + } else if ( origin.member.roles.cache.has( BotConfig.request.longNotificationsRole ) ) { + const curTime = new Date(); + const createdTime = origin.createdAt; + const timeDifference = Math.abs( curTime.getTime() - createdTime.getTime() ); + if ( timeDifference >= BotConfig.request.longNotificationsTimeDifference ) { + try { + await origin.author.send( response, log ); + } catch ( error ) { + ResolveRequestMessageTask.logger.error( error ); + } + } + } else { + try { + await origin.author.send( response, log ); + } catch ( error ) { + ResolveRequestMessageTask.logger.error( error ); + } + } + } + + if ( origin.member.roles.cache.has( BotConfig.request.specialNotificationsRole ) && this.emoji !== BotConfig.request.ignorePrependResponseMessageEmoji ) { + if ( origin.member.roles.cache.has( BotConfig.request.oldNotificationsRole ) ) { + const curTime = new Date(); + const createdTime = origin.createdAt; + const timeDifference = Math.abs( curTime.getTime() - createdTime.getTime() ); + if ( timeDifference >= BotConfig.request.oldNotificationsTimeDifference ) { + try { + await origin.author.send( response, log ); + } catch ( error ) { + ResolveRequestMessageTask.logger.error( error ); + } + } + } else if ( origin.member.roles.cache.has( BotConfig.request.longNotificationsRole ) ) { + const curTime = new Date(); + const createdTime = origin.createdAt; + const timeDifference = Math.abs( curTime.getTime() - createdTime.getTime() ); + if ( timeDifference >= BotConfig.request.longNotificationsTimeDifference ) { + try { + await origin.author.send( response, log ); + } catch ( error ) { + ResolveRequestMessageTask.logger.error( error ); + } + } + } else { + try { + await origin.author.send( response, log ); + } catch ( error ) { + ResolveRequestMessageTask.logger.error( error ); + } + } + } + } + if ( BotConfig.request.logChannel ) { const logChannel = await DiscordUtil.getChannel( BotConfig.request.logChannel ); if ( logChannel && logChannel instanceof TextChannel ) {