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 @@ -36,6 +36,13 @@ request:
ignorePrependResponseMessageEmoji: ✅
ignoreResolutionEmoji: 💬

normalNotificationsRole: 'Normal Request Notifications'
someNotificationsRole: 'Special Request Notifications'
oldNotificationsRole: 'Three Day Old Request Notifications'
oldNotificationsTimeDifference: 259200000 # 3 days
longNotificationsRole: 'One Week Old Request Notifications'
longNotificationsTimeDifference: 604800000 # 1 week

resolveDelay: 10000
prependResponseMessage: whenResolved
prependResponseMessageInLog: false
Expand Down
29 changes: 29 additions & 0 deletions config/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,35 @@ roleGroups:
Other Pronoun
(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.
Default is no time requirement.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Select a reaction on this message if you want to be notified in DMs when requests are resolved after a certain amount of time.
Default is no time requirement.
Select a reaction on this message if you want to only be notified about requests that are at least __ days old when they are resolved.
No reaction means there is no time requirement.

I think the prompt I wrote above might be more clear. The prompt should tell the reader that the unit of time is days, and I think "no reaction" is clearer than "default".

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that the description of each role/emoji specifies the amount of time that each emoji means, so specifying the unit of time in the prompt isn't as necessary as I had originally thought.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the "no reaction" message you suggested

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: ':three:'
- id: #TODO
desc: Be notified of your resolved requests that are resolved at least one week after creation.
emoji: ':seven:'



filterFeeds:
- jql: project = MC AND resolved > -1m AND resolution = Fixed AND fixVersion in unreleasedVersions()
Expand Down
22 changes: 22 additions & 0 deletions config/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@ request:
# An emoji or emoji ID which, when used, doesn't trigger the response template message.
ignorePrependResponseMessageEmoji: <string>

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

# The name of the role that signifies users that get some of the notifications from their resolved requests.
# This does not include the ignorePrependResponseMessageEmoji resolution.
someNotificationsRole: <string>

# The name 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 name of the role that signifies users that get all notifications from their resolved requests regardless of the time it took to resolve.
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 @@ -25,6 +25,12 @@ export class RequestConfig {
public suggestedEmoji: string[];
public ignorePrependResponseMessageEmoji: string;
public ignoreResolutionEmoji: string;
public normalNotificationsRole: string;
public someNotificationsRole: string;
public oldNotificationsRole: string;
public oldNotificationsTimeDifference: number;
public longNotificationsRole: string;
public longNotificationsTimeDifference: number;
public resolveDelay: number;
public prependResponseMessage: PrependResponseMessageType;
public prependResponseMessageInLog: boolean;
Expand All @@ -46,6 +52,13 @@ export class RequestConfig {
this.ignorePrependResponseMessageEmoji = config.get( 'request.ignorePrependResponseMessageEmoji' );
this.ignoreResolutionEmoji = config.get( 'request.ignoreResolutionEmoji' );

this.normalNotificationsRole = config.get( 'request.normalNotificationsRole' );
this.someNotificationsRole = config.get( 'request.someNotificationsRole' );
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.prependResponseMessage = getOrDefault( 'request.prependResponseMessage', PrependResponseMessageType.Never );
this.prependResponseMessageInLog = getOrDefault( 'request.prependResponseMessageInLog', false );
Expand Down
78 changes: 78 additions & 0 deletions src/tasks/ResolveRequestMessageTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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.someNotificationsRole ) && 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