-
Notifications
You must be signed in to change notification settings - Fork 13
Enable bulk actions by Jira filter #140
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
Draft
chandler05
wants to merge
34
commits into
master
Choose a base branch
from
feature/bulk-actions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+190
−44
Draft
Changes from 12 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
3f764b4
add bulk emoji
chandler05 a0ae9b7
Add bulk command
chandler05 544d4a8
Formatting and messages
chandler05 6c0d3a0
Semicolon
chandler05 635731f
Await
chandler05 2dfc80d
Error
chandler05 9b36413
values
chandler05 6e6eeff
Update BulkCommand.ts
chandler05 37870ff
Change to arrays
chandler05 74580c3
spaces
chandler05 4e6bd21
Update BulkCommand.ts
chandler05 68ff39d
Merge branch 'master' into feature/bulk-actions
chandler05 9d04629
Merge branch 'master' into feature/bulk-actions
chandler05 63e0168
Rework system to work better
chandler05 da2fb91
Catch promise
chandler05 367a984
A-WAIT
chandler05 208f71e
Allow resolving through !jira bulk
chandler05 69a9820
Update src/events/request/RequestBulkRemoveEventHandler.ts
chandler05 9c7d8c3
Update src/commands/BulkCommand.ts
chandler05 27af05f
Fixes batch
chandler05 fc3b18c
merge branch
chandler05 93ef5d1
Add EmojiUtil
chandler05 bb6612f
Initialize properly, add deletion of messages, add to requests util
chandler05 a2cf642
Let to const
chandler05 acf0a4c
Remove bulk event handlers
chandler05 fed0a2b
Merge branch 'master' into feature/bulk-actions
chandler05 021c83c
Fix poll command not working
SPGoding ad442bd
Changes
chandler05 b139334
Merge branch 'master' into feature/bulk-actions
chandler05 3bdcbf4
Fix merge errors
chandler05 b21e1b2
Merge branch 'master' into feature/bulk-actions
chandler05 af6a76c
Refactor command to produce different results in different cases, sto…
chandler05 fa0fbb0
Fix some formatting
chandler05 a2f84c7
Changes
chandler05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
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'; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.