One game at a time
This commit is contained in:
parent
f2d6eaea16
commit
af6dfb2597
35
src/index.js
35
src/index.js
|
@ -27,6 +27,9 @@ client.on('ready', () => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Makes a lock variable
|
||||||
|
let lock = false;
|
||||||
|
|
||||||
client.on('message', async message => {
|
client.on('message', async message => {
|
||||||
// Message processing
|
// Message processing
|
||||||
|
|
||||||
|
@ -46,12 +49,13 @@ client.on('message', async message => {
|
||||||
|
|
||||||
// The main function of this bot. To play games!
|
// The main function of this bot. To play games!
|
||||||
if (command === "play") {
|
if (command === "play") {
|
||||||
//making the filters for the collectors
|
// Makes it so one game at a time
|
||||||
|
if (lock === true) return
|
||||||
|
|
||||||
// Makes a message saying Who wants to play?
|
// Makes a message saying Who wants to play?
|
||||||
message.channel.send("who wants to play a game?")
|
message.channel.send("who wants to play a game?")
|
||||||
.then(message => {
|
.then(message => {
|
||||||
|
lock = true
|
||||||
// Reacts with a beach ball
|
// Reacts with a beach ball
|
||||||
message.react("739941658639990866")
|
message.react("739941658639990866")
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
@ -71,18 +75,17 @@ client.on('message', async message => {
|
||||||
collector.on("end", () => {
|
collector.on("end", () => {
|
||||||
const players = Array.from(collector.users)
|
const players = Array.from(collector.users)
|
||||||
|
|
||||||
|
|
||||||
console.log(players)
|
console.log(players)
|
||||||
console.log(players.length + " players")
|
console.log(players.length + " players")
|
||||||
|
|
||||||
message.channel.send(`<:BeachBall:739941658639990866> ${(players[0].toString()).slice(19)}`).then(message => {
|
message.channel.send(`<:BeachBall:739941658639990866> ${(players[0].toString()).slice(19)}`).then(message => {
|
||||||
message.react(config.emoteID).then(() => {
|
message.react(config.emoteID).then(() => {
|
||||||
const roundone = (reaction, user) => {
|
const roundone = (reaction, user) => {
|
||||||
return reaction.emoji.name === config.emoteID && user.id !== '223215601638703105' && user.id === (players[0].toString()).substr(0,18)
|
return reaction.emoji.name === config.emoteID && user.id !== '223215601638703105' && user.id === (players[0].toString()).substr(0, 18)
|
||||||
}
|
}
|
||||||
const collector = message.createReactionCollector(roundone, {
|
const collector = message.createReactionCollector(roundone, {
|
||||||
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 60 Seconds
|
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 60 Seconds
|
||||||
max: 2,
|
max: 1,
|
||||||
maxUsers: 2,
|
maxUsers: 2,
|
||||||
time: 10000
|
time: 10000
|
||||||
})
|
})
|
||||||
|
@ -100,10 +103,12 @@ client.on('message', async message => {
|
||||||
|
|
||||||
// Makes a filter that allows the hand emoji and only form the player that was randomly picked
|
// Makes a filter that allows the hand emoji and only form the player that was randomly picked
|
||||||
const handfilter = (reaction, user) => {
|
const handfilter = (reaction, user) => {
|
||||||
return reaction.emoji.name === config.emoteID && user.id !== '223215601638703105' && user.id === (players[num].toString()).substr(0,18)
|
return reaction.emoji.name === config.emoteID && user.id !== '223215601638703105' && user.id === (players[num].toString()).substr(0, 18)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creates
|
||||||
const collector = message.createReactionCollector(handfilter, {
|
const collector = message.createReactionCollector(handfilter, {
|
||||||
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 60 Seconds
|
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 10 Seconds
|
||||||
max: 2,
|
max: 2,
|
||||||
maxUsers: 2,
|
maxUsers: 2,
|
||||||
time: 10000
|
time: 10000
|
||||||
|
@ -114,28 +119,30 @@ client.on('message', async message => {
|
||||||
ball()
|
ball()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// When the 10s ends
|
||||||
collector.on("end", () => {
|
collector.on("end", () => {
|
||||||
if (collector.users.size === 0) {
|
if (collector.users.size === 0) {
|
||||||
message.channel.send("Ouch")
|
lock = false
|
||||||
|
return message.channel.send(`${(players[num].toString()).slice(19)} got hit in the head!`);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is the game function being used.
|
||||||
ball()
|
ball()
|
||||||
})
|
})
|
||||||
collector.on("end", () => {
|
collector.on("end", () => {
|
||||||
message.channel.send("Ouch!")
|
if (collector.users.size === 0) {
|
||||||
console.log(Array.from(collector.users))
|
lock = false;
|
||||||
|
return message.channel.send(`Somehow ${(players[0].toString()).slice(19)} got hit.`);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue