reddit command, also remove unneccesary code

This commit is contained in:
Joonas 2023-02-01 18:38:41 +02:00
parent 8a513c89ef
commit 8c31f37059
10 changed files with 55 additions and 44 deletions

View file

@ -8,12 +8,10 @@ const command = {
.readdirSync("./commands")
.map((cmd) => cmd.replace(".js", ""));
await client
.say(
msg.channelName,
`${msg.displayName}, List of commands: ${commandFiles.join(", ")}`
)
.catch((err) => console.log(err));
await client.say(
msg.channelName,
`${msg.displayName}, List of commands: ${commandFiles.join(", ")}`
);
},
};

View file

@ -14,7 +14,7 @@ const command = {
str += `${splitted.slice(2).join(" ")} `;
}
await client.me(msg.channelName, str).catch((err) => console.log(err));
await client.me(msg.channelName, str);
},
};

View file

@ -26,12 +26,10 @@ const command = {
return;
}
await client
.say(
msg.channelName,
`${msg.displayName}, (Now Playing) Album: ${data.album["#text"]} Track: ${data.name} Artist: ${data.artist["#text"]} | ${data.url}`
)
.catch((err) => console.log(err));
await client.say(
msg.channelName,
`${msg.displayName}, (Now Playing) Album: ${data.album["#text"]} Track: ${data.name} Artist: ${data.artist["#text"]} | ${data.url}`
);
},
};

View file

@ -7,16 +7,12 @@ const command = {
return;
}
await client
.say(
msg.channelName,
`${msg.displayName}, ${splitted[2]} and ${
splitted[3]
} are about ${Math.floor(
Math.random() * 100
)}% in love with each other!`
)
.catch((err) => console.log(err));
await client.say(
msg.channelName,
`${msg.displayName}, ${splitted[2]} and ${
splitted[3]
} are about ${Math.floor(Math.random() * 100)}% in love with each other!`
);
},
};

View file

@ -29,17 +29,13 @@ const command = {
let temp = [];
for (let name of names) {
if (temp.join(" ").length > 450) {
client
.say(msg.channelName, temp.join(" "))
.catch((err) => console.log(err));
client.say(msg.channelName, temp.join(" "));
temp = [];
}
temp.push(name);
if (names.slice(-1)[0] === name) {
client
.say(msg.channelName, temp.join(" "))
.catch((err) => console.log(err));
client.say(msg.channelName, temp.join(" "));
}
}
},

View file

@ -17,16 +17,12 @@ const command = {
let arr = [];
for (let i = 0; i < parseInt(splitted[2]); i++) {
arr.push(splitted.slice(3).join(" "));
client
.say(msg.channelName, arr.join(" "))
.catch((err) => console.log(err));
client.say(msg.channelName, arr.join(" "));
}
for (let i = parseInt(splitted[2]); i > 1; i--) {
arr.pop();
client
.say(msg.channelName, arr.join(" "))
.catch((err) => console.log(err));
client.say(msg.channelName, arr.join(" "));
}
},
};

29
commands/rd.js Normal file
View file

@ -0,0 +1,29 @@
const command = {
name: "rd",
desc: "get post from reddit subreddit",
run: async (client, msg, splitted) => {
const data = await fetch(
`https://teddit.net/r/${splitted[2] ? splitted[2] : "forsen"}?api`
)
.then((res) => res.json())
.then((data) => data.links[Math.floor(Math.random() * data.links.length)])
.catch((err) => console.log(err));
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}`
);
},
};
export default { command };

View file

@ -29,12 +29,10 @@ const command = {
return;
}
await client
.say(
msg.channelName,
`${msg.displayName} Weather for ${splitted[2]} Status: ${data.weatherDesc[0]?.value} Temp: ${data.temp_C}°C Feels like: ${data.FeelsLikeC}°C`
)
.catch((err) => console.log(err));
await client.say(
msg.channelName,
`${msg.displayName} Weather for ${splitted[2]} Status: ${data.weatherDesc[0]?.value} Temp: ${data.temp_C}°C Feels like: ${data.FeelsLikeC}°C`
);
},
};

View file

@ -16,12 +16,12 @@ const command = {
.join(" ")}`
)
.then((res) => res.json())
.then((data) => data[0])
.then((data) => data[Math.floor(Math.random() * data.length)])
.catch((err) => console.log(err));
await client.say(
msg.channelName,
`${msg.displayName}, First video with search term: ${splitted
`${msg.displayName}, YouTube video with search term: ${splitted
.slice(2)
.join(" ")}; ${data.title} by ${data.author}, Link: youtu.be/watch?v=${
data.videoId

View file

@ -29,4 +29,4 @@ client.on("PRIVMSG", async (msg) => {
});
client.connect();
client.join(process.env.TWITCH_USERNAME);
client.joinAll([process.env.TWITCH_USERNAME, "rollinjuusto"]);