add link sketching and shortening commands and hacker news command

This commit is contained in:
Joonas 2023-02-01 20:44:49 +02:00
parent d761ddcd2f
commit 0066ac5277
4 changed files with 88 additions and 7 deletions

21
commands/hn.js Normal file
View file

@ -0,0 +1,21 @@
const command = {
name: "hn",
desc: "fetch hacker news",
run: async (client, msg, splitted) => {
const data = await fetch(
`https://hn.algolia.com/api/v1/search?tags=front_page`
)
.then((res) => res.json())
.then((data) => data.hits[Math.floor(Math.random() * data.hits.length)])
.catch((err) => console.log(err));
client
.say(
msg.channelName,
`${msg.displayName}, Hacker News: ${data.title} (Points: ${data.points}, Comments: ${data.num_comments}) Article: ${data.url} Comments: https://news.ycombinator.com/item?id=${data.objectID}`
)
.catch((err) => console.log(err));
},
};
export default { command };

28
commands/short.js Normal file
View file

@ -0,0 +1,28 @@
const command = {
name: "short",
desc: "shorten an url",
run: async (client, msg, splitted) => {
if (!splitted[2]) {
client
.say(msg.channelName, `${msg.displayName}, supply an URL PoroSad`)
.catch((err) => console.log(err));
return;
}
const formData = new FormData();
formData.append("url", splitted[2]);
const data = await fetch(`https://s.lain.la`, {
method: "post",
body: formData,
})
.then((res) => res.text())
.catch((err) => console.log(err));
client
.say(msg.channelName, `${msg.displayName}, shortened URL: ${data}`)
.catch((err) => console.log(err));
},
};
export default { command };

32
commands/sketch.js Normal file
View file

@ -0,0 +1,32 @@
const command = {
name: "sketch",
desc: "make a suspicious link",
run: async (client, msg, splitted) => {
if (!splitted[2]) {
client.say(
msg.channelName,
`${msg.displayName}, please supply an URL PoroSad`
);
return;
}
let formData = new FormData();
formData.append("long_url", splitted[2]);
const data = await fetch(
`https://verylegit.link/sketchify?long_url=twitter.com`,
{
body: formData,
method: "POST",
}
)
.then((res) => res.text())
.catch((err) => console.log(err));
client
.say(msg.channelName, `${msg.displayName}, sketchified URL: ${data}`)
.catch((err) => console.log(err));
},
};
export default { command };

View file

@ -20,13 +20,13 @@ client.on("PRIVMSG", async (msg) => {
}
if (splitted[0] === "%") {
await commands[splitted[1]]
.run(client, msg, splitted)
.catch(() =>
client
.say(msg.channelName, `${msg.displayName}, not a command PoroSad`)
.catch((err) => console.log(err))
);
try {
await commands[splitted[1]].run(client, msg, splitted);
} catch {
client
.say(msg.channelName, `${msg.displayName}, not a command PoroSad`)
.catch((err) => console.log(err));
}
}
});