This command provides you javascript help based on given query, like if you do ?js merge array then it will tell you how you can merge two arrays using javascript.
/* Required Package/Modules */
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const axios = require('axios');
const stringSimilarity = require('string-similarity');
const message = context.params.event;
/* based on this we will show result */
const query = message.content.split(' ').slice(1).join(' ');
/* Get responce from api */
const {data: response} = await axios.get(
'https://1loc.dev/_next/data/zEKP4hPZ7m5_VW87zk8S7/index.json'
);
/* Save all snippets to a variable, there are more than 150 snippets */
const snippets = response.pageProps.snippets;
/* Find best match using stringSimilarity package */
const match = stringSimilarity.findBestMatch(
query,
snippets.map((x) => x.title)
).bestMatchIndex;
const {category, slug, title} = snippets[match];
/* Now get the content of best matched snippet using AP API */
const content = await axios
.get(
`https://1loc.dev/_next/data/zEKP4hPZ7m5_VW87zk8S7/${category}/${slug}.json`
)
.then((res) => {
return res.data.pageProps.content;
});
/* Send sweet message <3 */
return lib.discord.channels['@0.3.2'].messages.create({
content: ``,
channel_id: message.channel_id,
embed: {
author: {
name: title,
icon_url: 'https://plotly.com/all_static/images/icon-plotly_js.png',
},
description: content.replace(/\n\n/g, '\n'),
color: 0xffff00,
},
message_reference: {message_id: message.id},
});