added !code to searching
This commit is contained in:
32
commands/code.js
Normal file
32
commands/code.js
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
};
|
||||
24
libFlayer.js
24
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}`;
|
||||
|
||||
Reference in New Issue
Block a user