2023-02-03 20:26:14 +01:00
|
|
|
const command = {
|
|
|
|
name: "google",
|
|
|
|
desc: "google search",
|
|
|
|
restricted: false,
|
|
|
|
mod: false,
|
|
|
|
run: async (client, msg, splitted) => {
|
|
|
|
const data = await fetch(
|
2023-02-06 15:02:34 +01:00
|
|
|
`https://librex.nekus.gay/api.php?q="${encodeURIComponent(
|
|
|
|
splitted.slice(2).join(" ")
|
|
|
|
)}"`
|
2023-02-03 20:26:14 +01:00
|
|
|
)
|
|
|
|
.then((res) => res.json())
|
2023-02-06 12:00:00 +01:00
|
|
|
.then((data) => data[0])
|
2023-02-11 13:48:05 +01:00
|
|
|
.catch((err) =>
|
|
|
|
console.error("Error when fetching results: " + err.message)
|
|
|
|
);
|
2023-02-03 20:26:14 +01:00
|
|
|
|
2023-02-03 22:38:41 +01:00
|
|
|
if (!data) {
|
2023-02-03 20:26:14 +01:00
|
|
|
await client.say(
|
|
|
|
msg.channelName,
|
|
|
|
`${msg.displayName}, no results found or api is down`
|
|
|
|
);
|
2023-02-03 22:38:41 +01:00
|
|
|
|
|
|
|
return;
|
2023-02-03 20:26:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
await client.say(
|
|
|
|
msg.channelName,
|
2023-02-03 22:38:41 +01:00
|
|
|
`${msg.displayName}, First result for query ${splitted
|
|
|
|
.slice(2)
|
2023-02-06 12:00:00 +01:00
|
|
|
.join(" ")}: ${
|
|
|
|
data.hasOwnProperty("special_response")
|
|
|
|
? `${data.special_response.response.replaceAll("\n", "")} - ${
|
|
|
|
data.special_response.source
|
|
|
|
}`
|
|
|
|
: `${data.title} - ${data.description} ${data.url}`
|
|
|
|
}`
|
2023-02-03 20:26:14 +01:00
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = { command };
|