diff --git a/Parsers/Find a relevant XKCD comic.js b/Parsers/Find a relevant XKCD comic.js index a36cc56..d680ca6 100644 --- a/Parsers/Find a relevant XKCD comic.js +++ b/Parsers/Find a relevant XKCD comic.js @@ -4,9 +4,18 @@ regex:!xkcd flags:g */ -function buildComicOutput(xkcdPayload) { +function buildComicOutput(xkcdPayload, foundComic) { var blockArr = []; var block = {}; + if(!foundComic) { //if search didn't find a relevant comic add a message that this is a random one. + block = {}; + block.type = "section"; + block.text = {}; + block.text.type = "plain_text"; + block.text.text = 'No relevant XKCD found, here is a random one'; + blockArr.push(block); + } + block = {}; block.type = "header"; block.text = {}; block.text.type = "plain_text"; @@ -37,6 +46,31 @@ function buildComicOutput(xkcdPayload) { return block; } +function getComic(endpoint) { + var rm = new sn_ws.RESTMessageV2(); + rm.setHttpMethod('GET'); + rm.setEndpoint(endpoint); + rm.setRequestHeader('User-Agent', 'servicenow'); + var response = rm.execute(); + var body = response.getBody(); + // Check if we got an empty search result, as the result regex will match the page even if no result + var checkResponse = body.match(/

/g); + if (checkResponse === null) { + var result = body.match(/(?:/g); -if (checkResponse === null){ - var result = body.match(/(?: