-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from GlueOps/chore/refactor-code
Chore/refactor code
- Loading branch information
Showing
18 changed files
with
247 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
/* | ||
This is a simple command that replies with pong | ||
*/ | ||
|
||
export default { | ||
description: 'Replies with pong', | ||
|
||
|
This file contains 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 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 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 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 |
---|---|---|
@@ -1,26 +1,36 @@ | ||
/* | ||
This file is responsible for running the button | ||
That is associated with a command | ||
*/ | ||
|
||
export default async ({ | ||
commandName, | ||
actionId, | ||
handler, | ||
app, | ||
body, | ||
say, | ||
commandName, // the name of the command | ||
actionId, // the action ID of the button | ||
handler, // the command handler | ||
app, // the slack app | ||
body, // the body of the event | ||
say, // the say function to send a message | ||
}) => { | ||
// destructure the commands and command handler from the handler | ||
const { commandHandler } = handler; | ||
const { commands } = commandHandler; | ||
|
||
//retrieve the command object from the commands map | ||
const command = commands.get(commandName); | ||
|
||
//create a response function to send a message | ||
const response = (obj) => { | ||
say(obj) | ||
}; | ||
|
||
//check if the command does not exist, or has no button handler, if so return. | ||
if (!command || !command.button) { | ||
response({ | ||
text: `No button handler is registered.` | ||
}) | ||
return | ||
} | ||
|
||
// run the command's button handler | ||
command.button({ handler, app, body, response, actionId }); | ||
}; |
This file contains 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 |
---|---|---|
@@ -1,25 +1,35 @@ | ||
/* | ||
This file is responsible for running the command | ||
*/ | ||
|
||
export default async ({ | ||
commandName, | ||
handler, | ||
app, | ||
event, | ||
args, | ||
say | ||
commandName, // the name of the command | ||
handler, // the command handler | ||
app, // the slack app | ||
event, // the event object | ||
args, // the command arguments | ||
say // the say function to send a message | ||
}) => { | ||
// destructure the commands and command handler from the handler | ||
const { commandHandler } = handler; | ||
const { commands } = commandHandler; | ||
|
||
//retrieve the command object from the commands map | ||
const command = commands.get(commandName); | ||
|
||
//check if the command does not exist, or has no run function, if so return. | ||
if (!command || !command.run) { | ||
return | ||
} | ||
|
||
// retrieve the text from the arguments joined by a space | ||
const text = args.join(' '); | ||
|
||
//create a response function to send a message | ||
const response = (obj) => { | ||
say(obj) | ||
}; | ||
|
||
// run the command's run function | ||
command.run({ handler, app, event, response, text, args }); | ||
}; |
This file contains 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
Oops, something went wrong.