Search autocode's app inside discord. Uses: "!search-app <search-term>"
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let query = context.params.event.content.split(' ')?.slice(1)?.join('%20');
if (!query)
return lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Please provide a query to search`,
message_reference: {
message_id: `${context.params.event.id}`,
},
});
let request = await lib.http.request['@1.1.6']
.get({
url: `https://autocode.com/app/?q=${query}&prefetch`,
})
.then((s) => {
return s.data;
});
if (!request.data.sources.length)
return lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `No result found`,
message_reference: {
message_id: `${context.params.event.id}`,
},
});
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Here's the result for \`${request.data.searchParam}\``,
message_reference: {
message_id: `${context.params.event.id}`,
},
embeds: request.data.sources.slice(0, 10).map((a) => ({
title: `${a.title}`,
url: `https://autocode.com/app/${a.service_name}/`,
author: {
name: `${a.user.username}`,
icon_url: `${a.user.full_image_url ?? ''}`,
},
description: `${a.cachedService.description}`,
color: 0x00ff00,
thumbnail: {
url: `${a.thumbnail_image_url ?? `${a.user.full_image_url ?? ''}`}`,
},
fields: [
{
name: 'Views',
value: `\`${parseInt(a.cachedService.view_count).toLocaleString('en-US')}\``,
inline: true,
},
{
name: 'Installs',
value: `\`${parseInt(a.cachedService.install_count).toLocaleString('en-US')}\``,
inline: true,
},
{
name: 'Last updated',
value: ``,
inline: true,
},
{
name: 'Created',
value: ``,
inline: true,
},
{
name: 'API tags',
value: `\`${a.apiTags.length? a.apiTags.map((t) => t.user.username).join(', '): '- -'}\``,
inline: true,
},
],
})),
});