From 5514e68d969bcce5968856e9f5e1676c4a57a0f7 Mon Sep 17 00:00:00 2001 From: John Facey Date: Thu, 6 Oct 2022 15:21:49 -0500 Subject: [PATCH] added !code to searching --- commands/code.js | 32 ++++++++++++++++++++++++++++++++ libFlayer.js | 24 ++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 commands/code.js diff --git a/commands/code.js b/commands/code.js new file mode 100644 index 0000000..75767b2 --- /dev/null +++ b/commands/code.js @@ -0,0 +1,32 @@ +var libFlayer = require("../libFlayer.js"); + +module.exports = { + name: 'code', + description: 'Code', + async execute(message, args) { + try { + if (args.length < 1) { + message.reply(`Please use in !code [search term] - ex !code python loop`); + return; + } + var question = encodeURIComponent(args.join(" ")); + + var returnData = await libFlayer.getCode(question); + if (returnData.length > -1) { + message.reply( + ` + Name: **${returnData[0].name}** + Snippet: **${returnData[0].snippet}** + URL: **${returnData[0].url}** + ` + ); + } else { + message.reply('No result found'); + } + + + } catch (err) { + message.reply(err.toString()); + } + } +}; \ No newline at end of file diff --git a/libFlayer.js b/libFlayer.js index 71321d3..9e2e5e1 100644 --- a/libFlayer.js +++ b/libFlayer.js @@ -355,6 +355,30 @@ exports.getNPM = async function (question) { return returnData; } +exports.getCode = async function (question) { + + var answerURL = `https://you.com/api/performSearch?q=${question}&page=1&count=10&safeSearch=Moderate&onShoppingPage=false&mkt=en-US&responseFilter=WebPages,Translations,TimeZone,Computation,RelatedSearches&domain=youcode`; + console.log(answerURL); + let returnData = []; + + await axios.get(answerURL) + .then(response => { + console.log(response.data); + + if (response.data.length != 0) { + response.data.searchResults.mainline.bing_search_results.forEach(codeResult => { + returnData.push(codeResult); + }); + } + + return returnData; + }) + .catch(error => { + console.log(error); + }); + return returnData; +} + exports.getStock = async function (stock) { var answerURL = `https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${stock}&interval=5min&apikey=${stockKey}`;