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

Enable bulk actions by Jira filter #140

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3f764b4
add bulk emoji
chandler05 Dec 4, 2020
a0ae9b7
Add bulk command
chandler05 Dec 4, 2020
544d4a8
Formatting and messages
chandler05 Dec 4, 2020
6c0d3a0
Semicolon
chandler05 Dec 4, 2020
635731f
Await
chandler05 Dec 4, 2020
2dfc80d
Error
chandler05 Dec 4, 2020
9b36413
values
chandler05 Dec 5, 2020
6e6eeff
Update BulkCommand.ts
chandler05 Dec 5, 2020
37870ff
Change to arrays
chandler05 Dec 5, 2020
74580c3
spaces
chandler05 Dec 5, 2020
4e6bd21
Update BulkCommand.ts
chandler05 Dec 5, 2020
68ff39d
Merge branch 'master' into feature/bulk-actions
chandler05 Dec 5, 2020
9d04629
Merge branch 'master' into feature/bulk-actions
chandler05 Dec 6, 2020
63e0168
Rework system to work better
chandler05 Dec 6, 2020
da2fb91
Catch promise
chandler05 Dec 6, 2020
367a984
A-WAIT
chandler05 Dec 6, 2020
208f71e
Allow resolving through !jira bulk
chandler05 Dec 6, 2020
69a9820
Update src/events/request/RequestBulkRemoveEventHandler.ts
chandler05 Dec 7, 2020
9c7d8c3
Update src/commands/BulkCommand.ts
chandler05 Dec 7, 2020
27af05f
Fixes batch
chandler05 Dec 7, 2020
fc3b18c
merge branch
chandler05 Dec 7, 2020
93ef5d1
Add EmojiUtil
chandler05 Dec 7, 2020
bb6612f
Initialize properly, add deletion of messages, add to requests util
chandler05 Dec 7, 2020
a2cf642
Let to const
chandler05 Dec 7, 2020
acf0a4c
Remove bulk event handlers
chandler05 Dec 7, 2020
fed0a2b
Merge branch 'master' into feature/bulk-actions
chandler05 Dec 7, 2020
021c83c
Fix poll command not working
SPGoding Dec 7, 2020
ad442bd
Changes
chandler05 Dec 8, 2020
b139334
Merge branch 'master' into feature/bulk-actions
chandler05 May 4, 2021
3bdcbf4
Fix merge errors
chandler05 May 5, 2021
b21e1b2
Merge branch 'master' into feature/bulk-actions
chandler05 May 14, 2021
af6a76c
Refactor command to produce different results in different cases, sto…
chandler05 May 14, 2021
fa0fbb0
Fix some formatting
chandler05 May 14, 2021
a2f84c7
Changes
chandler05 May 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ request:
- ☑️
- ❌
- 💬
- 📁

ignorePrependResponseMessageEmoji: ✅
ignoreResolutionEmoji: 💬
bulkEmoji: 📁

resolveDelay: 10000
prependResponseMessage: whenResolved
Expand Down
3 changes: 3 additions & 0 deletions config/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ request:
# An emoji or emoji ID which, when used, doesn't trigger the response template message.
ignorePrependResponseMessageEmoji: <string>

# An emoji or emoji ID which indicates a request message to be added to a bulk action.
bulkEmoji: <string>

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

Expand Down
2 changes: 2 additions & 0 deletions src/BotConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class RequestConfig {
public suggestedEmoji: string[];
public ignorePrependResponseMessageEmoji: string;
public ignoreResolutionEmoji: string;
public bulkEmoji: string;
public resolveDelay: number;
public prependResponseMessage: PrependResponseMessageType;
public prependResponseMessageInLog: boolean;
Expand All @@ -49,6 +50,7 @@ export class RequestConfig {
this.suggestedEmoji = getOrDefault( 'request.suggestedEmoji', [] );
this.ignorePrependResponseMessageEmoji = config.get( 'request.ignorePrependResponseMessageEmoji' );
this.ignoreResolutionEmoji = config.get( 'request.ignoreResolutionEmoji' );
this.bulkEmoji = config.get( 'request.bulkEmoji' );

this.resolveDelay = config.get( 'request.resolveDelay' );
this.prependResponseMessage = getOrDefault( 'request.prependResponseMessage', PrependResponseMessageType.Never );
Expand Down
78 changes: 78 additions & 0 deletions src/commands/BulkCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Message, TextChannel } from 'discord.js';
import PrefixCommand from './PrefixCommand';
import MentionCommand from './MentionCommand';
import Command from './Command';
import DiscordUtil from '../util/DiscordUtil';
import BotConfig from '../BotConfig';

export default class BulkCommand extends PrefixCommand {
public readonly aliases = ['bulk', 'filter'];

public async run( message: Message, args: string ): Promise<boolean> {
if ( args.length ) {
return false;
}

let bulkMessages: Message[];

for ( let i = 0; i < BotConfig.request.internalChannels.length; i++ ) {
const internalChannelId = BotConfig.request.internalChannels[i];
try {
const internalChannel = await DiscordUtil.getChannel( internalChannelId );
if ( internalChannel instanceof TextChannel ) {
const channelMessages = internalChannel.messages.cache.values();
for await ( const channelMessage of channelMessages ) {
const reaction = channelMessage.reactions.cache.get( BotConfig.request.bulkEmoji );
if ( reaction.users.cache.get( message.author.id ) ) {
bulkMessages.push( channelMessage );
}
}
}
} catch ( err ) {
Command.logger.error( err );
return false;
}
}

let firstMentioned: string;
let ticketKeys: string[];

try {
for ( let j = 0; j < bulkMessages.length; j++ ) {
const bulkMessage = bulkMessages[j];
const ticket = this.getTickets( bulkMessage.toString() );
if ( firstMentioned == null ) {
firstMentioned = ticket[1];
}
ticket.forEach( key => ticketKeys.push( key ) );
const reaction = bulkMessage.reactions.cache.get( BotConfig.request.bulkEmoji );
await reaction.users.remove( message.author.id );
}
} catch ( err ) {
Command.logger.error( err );
return false;
}
const filter = `https://bugs.mojang.com/browse/${ firstMentioned }?jql=key%20in(${ ticketKeys.join( '%2C' ) })`;
try {
await message.channel.send( `${ message.author.toString() } ${ filter }` );
} catch {
return false;
}

return true;
chandler05 marked this conversation as resolved.
Show resolved Hide resolved
}

private getTickets( content: string ): string[] {
let ticketMatch: RegExpExecArray;
const regex = MentionCommand.getTicketIdRegex();
const ticketMatches: string[] = [];
while ( ( ticketMatch = regex.exec( content ) ) !== null ) {
ticketMatches.push( ticketMatch[1] );
}
return ticketMatches;
}
chandler05 marked this conversation as resolved.
Show resolved Hide resolved

public asString(): string {
return '!jira bulk';
}
}
2 changes: 2 additions & 0 deletions src/commands/CommandRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BugCommand from './BugCommand';
import BulkCommand from './BulkCommand';
import HelpCommand from './HelpCommand';
import PingCommand from './PingCommand';
import MooCommand from './MooCommand';
Expand All @@ -9,6 +10,7 @@ import ShutdownCommand from './ShutdownCommand';

export default class CommandRegistry {
public static BUG_COMMAND = new BugCommand();
public static BULK_COMMAND = new BulkCommand();
public static HELP_COMMAND = new HelpCommand();
public static MENTION_COMMAND = new MentionCommand();
public static MOO_COMMAND = new MooCommand();
Expand Down