Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

feat: added message/reaction recognition for beerjars #38

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
23d5c3b
feat: included help feature
baserrato Sep 14, 2022
b6b549e
added style guide
snowmang1 Sep 14, 2022
0df43ac
Added response to emoji
rhoofard Sep 14, 2022
ee648d7
Changed single quotes to double
rhoofard Sep 14, 2022
64035f7
feat: added scopes to reactions and direct messaging onto the manifest
baserrato Sep 14, 2022
90674b8
fixed linting messege by taking unused parameter "messege" out of hel…
snowmang1 Sep 14, 2022
55be42e
added parsing and display name lookup
rhoofard Sep 14, 2022
616f9e9
feat: emoji reaction to the recognized message and give feedback to o…
baserrato Sep 15, 2022
cd2097a
fix: updated npm package lock
baserrato Sep 15, 2022
db95bd9
docs: updated readme to include slack signing secret environment vari…
baserrato Sep 15, 2022
dff5248
fix: changed promise return calls to await due to deprecation of the …
baserrato Sep 15, 2022
8097a85
Fixed typing errors on receiverID's
rhoofard Sep 15, 2022
fdac061
fix: resolved conflicts with reactions and recognizing message.
baserrato Sep 15, 2022
22090e8
feat: Added empheral response when user clicks on appropriate emoji r…
baserrato Sep 15, 2022
53d8939
test: added testing for incrementation of beerjar
baserrato Sep 15, 2022
731a2de
test: created unit testing for some helper functions
baserrato Sep 16, 2022
51de951
test: created more unit tests for helper functions used in beerjar.
baserrato Sep 16, 2022
f15a186
added mock testing for simple query
snowmang1 Sep 16, 2022
f3dd3cf
feat: added direct messaging to receivers
baserrato Sep 19, 2022
6c70c62
added tabCount feature and test for getting persons current tab
snowmang1 Sep 19, 2022
5c5f8a8
added passing test using sinon Stubed db pool
snowmang1 Sep 19, 2022
c0587da
added function to print users tab
snowmang1 Sep 19, 2022
ae3ac9f
implemented tab query on user side
snowmang1 Sep 19, 2022
15ce118
fixed linting errors, added description block to file. with todo list…
snowmang1 Sep 19, 2022
d8a07de
added nyc output to git ignore
snowmang1 Sep 19, 2022
c85d13f
removed nyc output from git history
snowmang1 Sep 19, 2022
193adfb
fixed conflicts in package-lock.json
snowmang1 Sep 19, 2022
5cfbc3f
added nyc output to prettier ignore, updated npm to latest
snowmang1 Sep 19, 2022
1a82a6f
feature: added testing for sending messages to giver
rhoofard Sep 20, 2022
fa225d5
Added testing for the features
rhoofard Sep 22, 2022
816a111
added more tests for recognize.js
rhoofard Sep 22, 2022
fb3d682
added middleware test folder/updated test descriptions
rhoofard Sep 22, 2022
886e78d
fix: fixed formatting
rhoofard Sep 23, 2022
15cbc2a
fix: removed commented code and rearranged package.json
rhoofard Sep 23, 2022
951832e
fix: changed "discontent" to "beerJarData"
rhoofard Sep 23, 2022
5143942
fix: re-linted the code
rhoofard Sep 23, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ variables.sh
*/terraform.tfstate.backup
.terraform
.vscode
.nyc_output
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
chart
tf/.terraform
.vscode
.nyc*
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export MYSQL_USER=""
export MYSQL_PASSWORD=""
export SLACK_BOT_USER_OAUTH_TOKEN=""
export SLACK_APP_TOKEN=""
export SLACK_SIGNING_SECRET=""
```

4. Run docker-compose up to run the bot in your workspace. Only one person needs to run the bot locally at any given time; anyone in the Slack workspace will be able to test against it.
17 changes: 17 additions & 0 deletions docs/styleguide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Code

- variables and bindings = camalCase
- function, methods, imports, structures = UpperCamalCase
- comments = should explain all new methods, use case and function. Please put a block comment above methods explaining them.
- abbreviating = refrain from abbreviating where possible
- file explanation = at the top of each file there should be a block comment explaining the purpose of the file

## Git

- branches = lowercase-seporated-by-dashes
- commits = <fileChanged>: <concise messege about what changed>, <comma seporation>

## File management

- names = camalCase
- directories = snake_case (only if needed)
12 changes: 12 additions & 0 deletions features/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This file defines a help messege that
// will make the functionality of beerjar
// obvious to users

module.exports = function (app) {
app.message("help", helpMe);
};

async function helpMe({ say }) {
console.log("help messege invoked");
await say("N0 h31p 4 U!");
}
83 changes: 83 additions & 0 deletions features/recognize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const { ReactionMatches } = require("../middleware");
const recognize = require("../services/recognizeServ");

//const beerEmojiRegex = new RegExp(":beerjar:", "g");

/*
async function userInfo(client, userId){
const response = await client.users.info({ user: userId });
if (response.ok) {
return response.user;
}
throw new SlackError(
"users.info",
response.error,
`Something went wrong while sending recognition. When retreiving user information from Slack, the API responded with the following error: ${response.message} \n Recognition has not been sent.`
);
}
*/

module.exports = function (app) {
app.message(
":cheers_to_the_beer_jar:", // anyOf(directMention(), directMessage()),
Recognize
);
app.event("reaction_added", ReactionMatches(":beerjar:"), Reaction);
};

async function Recognize(client, message) {
//Promise.all(ReceiverIdsIn(message.text).map(async (receiver)=>userInfo(client, receiver)))
var discontent = {
rhoofard marked this conversation as resolved.
Show resolved Hide resolved
giver: message.user,
receivers: recognize.ReceiverIdsIn(message.text),
count: recognize.EmojiCountIn(message.text),
message: message.text,
channel: message.channel,
};

/*
if (receiverID.length==1){
await client.chat.postEphemeral({
channel: message.channel,
user: message.user,
text: response,
});
}else if(receiversID.length>1){
for(let i=1;i<receiversID.length;i++){
response+=` ${receiverID[i]}`
}
await client.chat.postEphemeral({
channel: message.channel,
user: message.user,
text: response,
});
}
*/
await recognize.SendNotificationToGiver(client, discontent);
await recognize.SendNotificationToReceivers(client, discontent);

await client.reactions.add({
channel: message.channel,
name: "beerjar",
timestamp: message.ts,
});
}

async function Reaction(client, event) {
var originalMessage = await recognize.GetMessageReacted(client, event);
var discontent = {
giver: event.user,
receivers: recognize.ReceiverIdsIn(originalMessage.text),
count: 1,
message: originalMessage.text,
channel: event.item.channel,
};

await recognize.SendNotificationToGiver(client, discontent);
await recognize.SendNotificationToReceivers(client, discontent);
}

module.exports = {
Reaction,
Recognize,
};
23 changes: 23 additions & 0 deletions features/tabCount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";
/*
* This file adds functionality for users to query their respective
* 'tabs' or the amount of beer jars they currently possess at the
* time. it does this by querying a db and returning all unresolved
* beer jars connected to the user.
*
* in its current form:
* TODO
* - not tested
* no db connection
*/

module.exports = function (app) {
app.message(":cheers_to_the_beer_jar: tab", SendTab);
};

async function SendTab({ message, client }) {
await client.chat.postMessage({
channel: message.user,
text: "`" + "1" + "`",
});
}
14 changes: 14 additions & 0 deletions middleware/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function ReactionMatches(emoji) {
return async ({ event, next }) => {
if (emoji[0] == ":" && emoji[emoji.length - 1] == ":") {
emoji = emoji.slice(1, -1);
}
if (event.reaction.includes(emoji)) {
await next();
}
};
}

module.exports = {
ReactionMatches,
};
Loading