Skip to content

Commit c4c4206

Browse files
authored
Update music link to send a message (#486)
1 parent 82bc265 commit c4c4206

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

Parsers/Get a music link.js

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,45 @@
11
/*
22
activation_example:!music https://music.apple.com/us/song/inferna/1814573909
3-
regex:!music
3+
regex:^!music
44
flags:gmi
55
*/
66

7-
var input = current.text.trim();
8-
var link = input.replace('!music ', '');
9-
var tapeLinkObj = getTapeLink(link);
10-
var msg;
11-
if (tapeLinkObj.status == '200' && tapeLinkObj.body.success) {
12-
msg = `<https://${tapeLinkObj.body.shareableLink}|Stream this song on other platforms>`;
13-
} else {
14-
msg = `Something went wrong. Please check that you entered a full link. Error details: ${tapeLinkObj.body.error}`;
15-
}
16-
17-
gs.info(msg);
18-
197
function getTapeLink(url) {
208

219
try {
22-
var endpointURL = 'https://www.tapelink.io/api/generate-link';
23-
24-
var request = new sn_ws.RESTMessageV2();
10+
const endpointURL = 'https://www.tapelink.io/api/generate-link';
11+
const request = new sn_ws.RESTMessageV2();
2512
request.setHttpMethod('post');
2613
request.setEndpoint(endpointURL);
2714
request.setRequestHeader('Content-Type', 'application/json');
2815
request.setRequestHeader('Accept', 'application/json');
29-
var payload = {
30-
"url": url
16+
const payload = {
17+
'url': url
3118
};
32-
3319
request.setRequestBody(JSON.stringify(payload));
20+
const response = request.execute();
3421

35-
36-
var response = request.execute();
37-
38-
var httpStatus = response.getStatusCode();
39-
var responseBody = JSON.parse(response.getBody());
22+
const httpStatus = response.getStatusCode();
23+
const responseBody = JSON.parse(response.getBody());
4024

4125
return {
4226
body: responseBody,
4327
status: httpStatus
4428
};
45-
4629
} catch (ex) {
47-
gs.error('An error occurred in the RESTMessageV2 script: ' + ex.getMessage());
30+
gs.error(`An error occurred in the RESTMessageV2 script: ${ex.getMessage()}`);
4831
}
49-
}
32+
}
33+
34+
const slacker = new x_snc_slackerbot.Slacker();
35+
let input = current.text.trim();
36+
let link = input.replace('!music ', '');
37+
const tapeLinkObj = getTapeLink(link);
38+
let msg = '';
39+
if (tapeLinkObj.status == '200' && tapeLinkObj.body.success) {
40+
msg = `<https://${tapeLinkObj.body.shareableLink}|Stream this song on other platforms>`;
41+
} else {
42+
msg = `Something went wrong. Please check that you entered a full link. Error details: ${tapeLinkObj.body.error}`;
43+
}
44+
45+
slacker.send_chat(current, msg, false);

0 commit comments

Comments
 (0)