Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify users of their resolved requests depending on a role selection #133

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions config/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 23 additions & 1 deletion config/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,32 @@ request:

# An emoji or emoji ID which, when used, doesn't trigger the response template message.
ignorePrependResponseMessageEmoji: <string>

# An emoji or emoji ID which, when used, doesn't resolve the request.
ignoreResolutionEmoji: <string>

# The ID of the role that signifies users that get notifications from some of their resolved requests.
# This includes only the ignorePrependResponseMessageEmoji resolution.
normalNotificationsRole: <string>

# 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: <string>

# The ID of the role that signifies users that get all notifications from their resolved requests from a certain time period before.
oldNotificationsRole: <string>

# 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: <number>

# The ID of the role that signifies users that get all notifications from their resolved requests from a certain, longer, time period before.
longNotificationsRole: <string>

# 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: <number>

# The amount of time in milliseconds between a volunteer reacts to the message and the bot deletes its message.
resolveDelay: <number>

Expand Down
13 changes: 13 additions & 0 deletions src/BotConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );
Expand Down
78 changes: 78 additions & 0 deletions src/tasks/ResolveRequestMessageTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down