Skip to content
Merged
Changes from all commits
Commits
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
50 changes: 23 additions & 27 deletions Parsers/Get a music link.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
/*
activation_example:!music https://music.apple.com/us/song/inferna/1814573909
regex:!music
regex:^!music
flags:gmi
*/

var input = current.text.trim();
var link = input.replace('!music ', '');
var tapeLinkObj = getTapeLink(link);
var msg;
if (tapeLinkObj.status == '200' && tapeLinkObj.body.success) {
msg = `<https://${tapeLinkObj.body.shareableLink}|Stream this song on other platforms>`;
} else {
msg = `Something went wrong. Please check that you entered a full link. Error details: ${tapeLinkObj.body.error}`;
}

gs.info(msg);

function getTapeLink(url) {

try {
var endpointURL = 'https://www.tapelink.io/api/generate-link';

var request = new sn_ws.RESTMessageV2();
const endpointURL = 'https://www.tapelink.io/api/generate-link';
const request = new sn_ws.RESTMessageV2();
request.setHttpMethod('post');
request.setEndpoint(endpointURL);
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Accept', 'application/json');
var payload = {
"url": url
const payload = {
'url': url
};

request.setRequestBody(JSON.stringify(payload));
const response = request.execute();


var response = request.execute();

var httpStatus = response.getStatusCode();
var responseBody = JSON.parse(response.getBody());
const httpStatus = response.getStatusCode();
const responseBody = JSON.parse(response.getBody());

return {
body: responseBody,
status: httpStatus
};

} catch (ex) {
gs.error('An error occurred in the RESTMessageV2 script: ' + ex.getMessage());
gs.error(`An error occurred in the RESTMessageV2 script: ${ex.getMessage()}`);
}
}
}

const slacker = new x_snc_slackerbot.Slacker();
let input = current.text.trim();
let link = input.replace('!music ', '');
const tapeLinkObj = getTapeLink(link);
let msg = '';
if (tapeLinkObj.status == '200' && tapeLinkObj.body.success) {
msg = `<https://${tapeLinkObj.body.shareableLink}|Stream this song on other platforms>`;
} else {
msg = `Something went wrong. Please check that you entered a full link. Error details: ${tapeLinkObj.body.error}`;
}

slacker.send_chat(current, msg, false);
Loading