twitch_bot/commands/massping.js
2023-02-01 13:04:14 +02:00

43 lines
992 B
JavaScript

const command = {
name: "massping",
run: async (client, msg) => {
const data = await fetch(`https://tmi.twitch.tv/group/user/elis/chatters`)
.then((res) => res.json())
.then((data) => {
return data.chatters;
})
.catch((err) => console.log(err));
let names = [];
function printValues(obj) {
for (var key in obj) {
if (typeof obj[key] === "object") {
printValues(obj[key]);
} else {
names.push(obj[key]);
}
}
}
printValues(data);
let temp = [];
for (let name of names) {
if (temp.join(" ").length > 450) {
client
.say(msg.channelName, temp.join(" "))
.catch((err) => console.log(err));
temp = [];
}
if (names.slice(-1)[0] === name) {
client
.say(msg.channelName, temp.join(" "))
.catch((err) => console.log(err));
}
temp.push(name);
}
},
};
export default { command };