twitch_bot/commands/rd.js

36 lines
921 B
JavaScript
Raw Normal View History

const command = {
name: "rd",
desc: "get post from reddit subreddit",
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) => {
const data = await fetch(
`https://teddit.namazso.eu/r/${
2023-02-06 15:02:34 +01:00
splitted[2] ? encodeURIComponent(splitted[2]) : "forsen"
}?api`
)
.then((res) => res.json())
.then((data) => data.links[Math.floor(Math.random() * data.links.length)])
2023-02-11 13:48:05 +01:00
.catch((err) =>
console.error("Error fetching from teddit: " + err.message)
);
if (!data) {
client.say(
msg.channelName,
`${msg.displayName}, nothing found or api is down`
);
return;
}
await client.say(
msg.channelName,
`${msg.displayName}, r/${splitted[2] ? splitted[2] : "forsen"}: ${
data.title
} (Score: ${data.score} Ratio: ${data.upvote_ratio}) ${data.url}`
);
},
};
2023-02-01 22:11:48 +01:00
module.exports = { command };