twitch_bot/commands/short.js

38 lines
862 B
JavaScript
Raw Normal View History

const command = {
name: "short",
desc: "shorten an url",
2023-02-02 23:37:42 +01:00
restricted: false,
2023-02-02 23:58:58 +01:00
mod: false,
run: async (client, msg, splitted) => {
if (!splitted[2]) {
2023-02-11 13:48:05 +01:00
await client.say(
msg.channelName,
`${msg.displayName}, supply an URL PoroSad`
);
return;
}
const formData = new FormData();
2023-02-02 14:16:21 +01:00
formData.append(
"url",
splitted[2].startsWith("https://") || splitted[2].startsWith("http://")
? splitted[2]
: `https://${splitted[2]}`
);
const data = await fetch(`https://s.lain.la`, {
method: "post",
body: formData,
})
.then((res) => res.text())
2023-02-11 13:48:05 +01:00
.catch((err) => console.log("Error shortening url: " + err.message));
2023-02-11 13:48:05 +01:00
await client.say(
msg.channelName,
`${msg.displayName}, shortened URL: ${data}`
);
},
};
2023-02-01 22:11:48 +01:00
module.exports = { command };