2020-08-05 16:56:17 +00:00
|
|
|
// Load up the libraries
|
|
|
|
const Discord = require('discord.js');
|
|
|
|
|
|
|
|
// Importing config
|
|
|
|
const config = require('./config.json')
|
|
|
|
|
|
|
|
// Create client
|
|
|
|
const client = new Discord.Client();
|
|
|
|
|
|
|
|
// Triggers when the bot is logged in and
|
|
|
|
client.on('ready', () => {
|
|
|
|
//logs when the bot comes online
|
|
|
|
console.info(
|
2020-08-05 20:48:10 +00:00
|
|
|
'Bot has started, with' + client.users.cache.size + 'users, in ' + client.channels.cache.size + 'channels of ' + client.guilds.cache.size + ' guilds.');
|
|
|
|
// Sets bots status to "Playing with beachballs"
|
2020-08-05 16:56:17 +00:00
|
|
|
client.user.setPresence({
|
|
|
|
activity: {
|
|
|
|
name: `with beachballs`,
|
|
|
|
type: 'PLAYING',
|
|
|
|
},
|
|
|
|
status: 'idle',
|
|
|
|
}).then(() => {
|
|
|
|
console.log("Status set!")
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2020-08-05 18:54:09 +00:00
|
|
|
// Makes a lock variable
|
|
|
|
let lock = false;
|
|
|
|
|
2020-08-05 16:56:17 +00:00
|
|
|
client.on('message', async message => {
|
|
|
|
// Message processing
|
|
|
|
|
|
|
|
// Only can be used in #linecon
|
|
|
|
// let okchannel = client.channels.cache.get("710574818222931968")
|
|
|
|
// if (!(message.channel === okchannel)) return;
|
|
|
|
|
|
|
|
// Discards messages from bots
|
|
|
|
if (message.author.bot) return;
|
|
|
|
|
|
|
|
// Discards messages that dont being with the prefix
|
|
|
|
if (message.content.indexOf(config.prefix) !== 0) return;
|
|
|
|
|
|
|
|
// Makes the message into an array then cuts off the beginning and puts it in the command variable
|
|
|
|
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
|
|
|
|
const command = args.shift().toLowerCase();
|
|
|
|
|
|
|
|
// The main function of this bot. To play games!
|
|
|
|
if (command === "play") {
|
2020-08-05 18:54:09 +00:00
|
|
|
// Makes it so one game at a time
|
|
|
|
if (lock === true) return
|
2020-08-05 16:56:17 +00:00
|
|
|
|
|
|
|
// Makes a message saying Who wants to play?
|
|
|
|
message.channel.send("who wants to play a game?")
|
|
|
|
.then(message => {
|
2020-08-05 18:54:09 +00:00
|
|
|
lock = true
|
2020-08-05 16:56:17 +00:00
|
|
|
// Reacts with a beach ball
|
|
|
|
message.react("739941658639990866")
|
|
|
|
.then(() => {
|
|
|
|
// Collects reactions on the previous message
|
|
|
|
const beachballfilter = (reaction, user) => {
|
|
|
|
return reaction.emoji.id === '739941658639990866' && user.id !== '223215601638703105'
|
|
|
|
}
|
|
|
|
const collector = message.createReactionCollector(beachballfilter, {
|
|
|
|
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 60 Seconds
|
|
|
|
max: 25,
|
|
|
|
maxUsers: 25,
|
|
|
|
time: 10000
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Triggers when someone joins the react
|
|
|
|
collector.on("end", () => {
|
|
|
|
const players = Array.from(collector.users)
|
|
|
|
|
|
|
|
console.log(players)
|
|
|
|
console.log(players.length + " players")
|
|
|
|
|
2020-08-05 20:48:10 +00:00
|
|
|
message.channel.send('<:BeachBall:739941658639990866> ' + (players[0].toString()).slice(19)).then(message => {
|
2020-08-05 16:56:17 +00:00
|
|
|
message.react(config.emoteID).then(() => {
|
|
|
|
const roundone = (reaction, user) => {
|
2020-08-05 18:54:09 +00:00
|
|
|
return reaction.emoji.name === config.emoteID && user.id !== '223215601638703105' && user.id === (players[0].toString()).substr(0, 18)
|
2020-08-05 16:56:17 +00:00
|
|
|
}
|
|
|
|
const collector = message.createReactionCollector(roundone, {
|
|
|
|
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 60 Seconds
|
2020-08-05 18:54:09 +00:00
|
|
|
max: 1,
|
2020-08-05 20:32:41 +00:00
|
|
|
maxUsers: 1,
|
|
|
|
time: 5000
|
2020-08-05 16:56:17 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
collector.on("collect", () => {
|
|
|
|
function ball() {
|
2020-08-05 20:32:41 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
// Generates a random number from 0 to players.length
|
|
|
|
let num = Math.floor(Math.random() * (players.length));
|
|
|
|
console.log(num);
|
|
|
|
|
|
|
|
//sends a message with the beach ball emote and pings a player
|
2020-08-05 20:48:10 +00:00
|
|
|
message.channel.send('<:BeachBall:739941658639990866> ' + (players[num].toString()).slice(19)).then(message => {
|
2020-08-05 20:32:41 +00:00
|
|
|
// Reacts the message with hands
|
|
|
|
message.react(config.emoteID).then(() => {
|
|
|
|
// Keeping the lock locked
|
|
|
|
lock = true
|
|
|
|
// Makes a filter that allows the hand emoji and only form the player that was randomly picked
|
|
|
|
const handfilter = (reaction, user) => {
|
|
|
|
return reaction.emoji.name === config.emoteID && user.id !== '223215601638703105' && user.id === (players[num].toString()).substr(0, 18)
|
2020-08-05 16:56:17 +00:00
|
|
|
}
|
2020-08-05 20:32:41 +00:00
|
|
|
|
|
|
|
// Creates
|
|
|
|
const collector = message.createReactionCollector(handfilter, {
|
|
|
|
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 10 Seconds
|
|
|
|
max: 1,
|
|
|
|
maxUsers: 1,
|
|
|
|
time: 5000
|
|
|
|
})
|
|
|
|
|
|
|
|
//on collection play again
|
|
|
|
collector.on("collect", () => {
|
|
|
|
ball()
|
|
|
|
})
|
|
|
|
|
|
|
|
// When the 10s ends
|
|
|
|
collector.on("end", () => {
|
|
|
|
if (collector.users.size === 0) {
|
|
|
|
lock = false
|
2020-08-05 20:48:10 +00:00
|
|
|
return message.channel.send((players[num].toString()).slice(19)+ ' got hit in the head!');
|
2020-08-05 20:32:41 +00:00
|
|
|
}
|
|
|
|
})
|
2020-08-05 16:56:17 +00:00
|
|
|
})
|
|
|
|
})
|
2020-08-05 20:32:41 +00:00
|
|
|
}, Math.floor(Math.random() * (3000)))
|
2020-08-05 16:56:17 +00:00
|
|
|
}
|
2020-08-05 18:54:09 +00:00
|
|
|
|
|
|
|
// This is the game function being used.
|
2020-08-05 16:56:17 +00:00
|
|
|
ball()
|
|
|
|
})
|
|
|
|
collector.on("end", () => {
|
2020-08-05 18:54:09 +00:00
|
|
|
if (collector.users.size === 0) {
|
|
|
|
lock = false;
|
2020-08-05 20:48:10 +00:00
|
|
|
return message.channel.send('Somehow ' + (players[0].toString()).slice(19) + ' got hit.');
|
2020-08-05 18:54:09 +00:00
|
|
|
}
|
2020-08-05 16:56:17 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
client.login(config.token).then(() => {
|
|
|
|
console.log("logged in")
|
|
|
|
})
|