Skip to content

Commit f5de37c

Browse files
committed
prettier/eslint changes to source
1 parent cd9bd03 commit f5de37c

9 files changed

+88
-60
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const app = require('./src/app')
1+
const app = require('./src/app');
22

3-
app()
3+
app();

src/app.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const dotenv = require('dotenv');
55
const handleChannelJoined = require('./handleChannelJoined');
66

77
const app = () => {
8-
98
const nodeEnv = process.env.NODE_ENV || 'development';
109
if (nodeEnv != 'production') {
1110
dotenv.config();
@@ -31,16 +30,17 @@ const app = () => {
3130
const token = process.env.SLACK_TOKEN;
3231
const web = new WebClient(token);
3332

34-
3533
/*
3634
Attach listeners to events by Slack Event "type". See: https://api.slack.com/events/message.im
3735
*/
3836

39-
const handleAppMentionCallback = (web) => (event) => handleAppMention(event, web)
37+
const handleAppMentionCallback = (web) => (event) =>
38+
handleAppMention(event, web);
4039
slackEvents.on('app_mention', handleAppMentionCallback(web));
4140

4241
// https://api.slack.com/events/member_joined_channel
43-
const handleChannelJoinedCallback = (web) => (event) => handleChannelJoined(event, web)
42+
const handleChannelJoinedCallback = (web) => (event) =>
43+
handleChannelJoined(event, web);
4444
slackEvents.on('member_joined_channel', handleChannelJoinedCallback(web));
4545

4646
// finally, start listening for events
@@ -52,7 +52,6 @@ const app = () => {
5252
console.log(`Listening for events on ${server.address().port}`);
5353
// console.log('---- server', server)
5454
})();
55+
};
5556

56-
}
57-
58-
module.exports = app
57+
module.exports = app;

src/buildResponse.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
21
const buildResponse = (template, data, encode = false) => {
32
if (!template) {
43
throw 'Blank template supplied to buildResponse';
54
}
65

7-
let result = template
6+
let result = template;
87

98
Object.keys(data).forEach((key) => {
10-
const token = `{{${key}}}`
11-
const encodedText = encode ? encodeURIComponent(data[key]) : data[key]
12-
result = result.replace(token, encodedText)
9+
const token = `{{${key}}}`;
10+
const encodedText = encode ? encodeURIComponent(data[key]) : data[key];
11+
result = result.replace(token, encodedText);
1312
});
1413

15-
return result
14+
return result;
1615
};
1716

18-
module.exports = buildResponse
17+
module.exports = buildResponse;

src/extractData.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
21
const extractData = (event) => {
3-
const botUserMatch = event.text.trim().match(/^(<@U.{10,12}>)/i)
4-
const text = (botUserMatch ? event.text.replace(botUserMatch[0], '') : event.text).trim();
5-
let atUser = `<@${event.user}>`
2+
const botUserMatch = event.text.trim().match(/^(<@U.{10,12}>)/i);
3+
const text = (botUserMatch
4+
? event.text.replace(botUserMatch[0], '')
5+
: event.text
6+
).trim();
7+
let atUser = `<@${event.user}>`;
68

79
return {
810
message: text,
9-
at_user: atUser
10-
}
11+
at_user: atUser,
12+
};
1113
};
1214

13-
module.exports = extractData
15+
module.exports = extractData;

src/handleAppMention.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
const extractData = require('./extractData');
22
const processSubmission = require('./processSubmission');
33
const sendHelp = require('./sendHelp');
4-
const sendIntroduction = require('./sendIntroduction')
4+
const sendIntroduction = require('./sendIntroduction');
55

66
const handleAppMention = async (event, web) => {
7-
console.log(`Received a app_mention event: user ${event.user} in channel ${event.channel} says ${event.text}`);
7+
console.log(
8+
`Received a app_mention event: user ${event.user} in channel ${event.channel} says ${event.text}`
9+
);
810
// console.log('---- event:', event);
911
// console.log('---- web:', web);
1012

11-
const { message } = extractData(event)
13+
const { message } = extractData(event);
1214

1315
if (message == '' || message == 'help') {
1416
sendHelp(event, web);
15-
return
17+
return;
1618
}
1719
if (message == '?' || message.includes('who are you')) {
1820
sendIntroduction(event, web);
19-
return
21+
return;
2022
}
2123

2224
processSubmission(event, web);
2325
};
2426

25-
module.exports = handleAppMention
27+
module.exports = handleAppMention;

src/handleChannelJoined.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
const sendIntroduction = require('./sendIntroduction')
1+
const sendIntroduction = require('./sendIntroduction');
22

33
const handleChannelJoined = async (event, web) => {
4-
console.log(`Received a member_joined_channel event: user ${event.user} in channel ${event.channel}`);
4+
console.log(
5+
`Received a member_joined_channel event: user ${event.user} in channel ${event.channel}`
6+
);
57
console.log('---- event:', event);
68
// console.log('---- web:', web);
79

@@ -11,12 +13,21 @@ const handleChannelJoined = async (event, web) => {
1113
// console.log('---- authTestResponse:', authTestResponse);
1214

1315
if (botUser == event.user) {
14-
console.log('---- bot', botName, 'joined the channel invited by', event.inviter);
16+
console.log(
17+
'---- bot',
18+
botName,
19+
'joined the channel invited by',
20+
event.inviter
21+
);
1522
sendIntroduction(event, web);
1623
} else {
17-
console.log('---- user', event.user, 'joined the channel invited by', event.inviter);
24+
console.log(
25+
'---- user',
26+
event.user,
27+
'joined the channel invited by',
28+
event.inviter
29+
);
1830
}
19-
2031
};
2132

22-
module.exports = handleChannelJoined
33+
module.exports = handleChannelJoined;

src/processSubmission.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
const extractData = require('./extractData');
2-
const buildResponse = require('./buildResponse')
3-
const ENCODE_THE_DATA = true
2+
const buildResponse = require('./buildResponse');
3+
const ENCODE_THE_DATA = true;
44

55
const processSubmission = async (event, web) => {
6-
console.log(`Processing submission: user ${event.user} in channel ${event.channel} says ${event.text}`);
6+
console.log(
7+
`Processing submission: user ${event.user} in channel ${event.channel} says ${event.text}`
8+
);
79
// console.log('---- event:', event);
810
// console.log('---- web:', web);
911

10-
const data = extractData(event)
12+
const data = extractData(event);
1113

12-
const messageTemplate = process.env.SUBMIT_MESSAGE_TEMPLATE
13-
const linkTemplate = process.env.SUBMIT_LINK_TEMPLATE
14+
const messageTemplate = process.env.SUBMIT_MESSAGE_TEMPLATE;
15+
const linkTemplate = process.env.SUBMIT_LINK_TEMPLATE;
1416

15-
const link = buildResponse(linkTemplate, data, ENCODE_THE_DATA)
16-
const response = buildResponse(messageTemplate, { link, ...data })
17+
const link = buildResponse(linkTemplate, data, ENCODE_THE_DATA);
18+
const response = buildResponse(messageTemplate, { link, ...data });
1719

1820
console.log('---- response:', response);
1921
try {
2022
await web.chat.postMessage({
2123
text: `<@${event.user}> ${response}`,
22-
channel: event.channel
24+
channel: event.channel,
2325
});
2426
} catch (err) {
25-
console.log('slack web api rejected the chat.postMessage request with', err)
26-
};
27+
console.log(
28+
'slack web api rejected the chat.postMessage request with',
29+
err
30+
);
31+
}
2732
};
2833

29-
module.exports = processSubmission
34+
module.exports = processSubmission;

src/sendHelp.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const sendHelp = async (event, web) => {
2-
console.log(`sending Help: user ${event.user} in channel ${event.channel} says ${event.text}`);
2+
console.log(
3+
`sending Help: user ${event.user} in channel ${event.channel} says ${event.text}`
4+
);
35
// console.log('---- event:', event);
46
// console.log('---- web:', web);
57

@@ -9,18 +11,21 @@ const sendHelp = async (event, web) => {
911
'Alternatively try sending me these commands:',
1012
' help',
1113
' ?',
12-
' who are you'
14+
' who are you',
1315
].join('\n');
1416

1517
console.log('---- response:', response);
1618
try {
1719
await web.chat.postMessage({
1820
text: `<@${event.user}> ${response}`,
19-
channel: event.channel
21+
channel: event.channel,
2022
});
2123
} catch (err) {
22-
console.log('slack web api rejected the chat.postMessage request with', err)
23-
};
24+
console.log(
25+
'slack web api rejected the chat.postMessage request with',
26+
err
27+
);
28+
}
2429
};
2530

26-
module.exports = sendHelp
31+
module.exports = sendHelp;

src/sendIntroduction.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
const packageJson = require('../package.json');
22

33
const sendIntroduction = async (event, web) => {
4-
console.log(`Sending introduction: user ${event.user} in channel ${event.channel} says ${event.text}`);
4+
console.log(
5+
`Sending introduction: user ${event.user} in channel ${event.channel} says ${event.text}`
6+
);
57
// console.log('---- event:', event);
68
// console.log('---- web:', web);
7-
const { name, version } = packageJson
9+
const { name, version } = packageJson;
810

911
const response = [
1012
`Hi. I am a bot running the ${name} software, version ${version}.`,
1113
'(I am presently in pre-beta status, please be gentle with me)',
1214
'I am here to help with submitting your data',
13-
'Send me a message with the text you want to submit, and I will get you started.'
15+
'Send me a message with the text you want to submit, and I will get you started.',
1416
].join('\n');
1517

1618
console.log('---- response:', response);
1719
try {
1820
await web.chat.postMessage({
1921
text: `<@${event.user}> ${response} `,
20-
channel: event.channel
22+
channel: event.channel,
2123
});
2224
} catch (err) {
23-
console.log('slack web api rejected the chat.postMessage request with', err)
24-
};
25+
console.log(
26+
'slack web api rejected the chat.postMessage request with',
27+
err
28+
);
29+
}
2530
};
2631

27-
module.exports = sendIntroduction
32+
module.exports = sendIntroduction;

0 commit comments

Comments
 (0)