twitch_bot/commands/massping.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-02-01 12:04:14 +01:00
const command = {
name: "massping",
desc: "ping every chatter in the room (this one also blocks the thread until it's done)",
2023-02-01 12:04:14 +01:00
run: async (client, msg) => {
const data = await fetch(
`https://tmi.twitch.tv/group/user/${msg.channelName}/chatters`
)
2023-02-01 12:04:14 +01:00
.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 };