2020-08-03 15:51:28 +00:00
|
|
|
// Load up the libraries
|
|
|
|
const Discord = require('discord.js');
|
|
|
|
|
|
|
|
// Importing config
|
|
|
|
const config = require('./config.json')
|
|
|
|
|
2020-08-03 18:25:27 +00:00
|
|
|
//User array and random number
|
|
|
|
let players = [];
|
|
|
|
let value = players[Math.floor(Math.random() * players.length)];
|
2020-08-03 15:51:28 +00:00
|
|
|
|
|
|
|
// Create client
|
|
|
|
const client = new Discord.Client();
|
|
|
|
|
2020-08-03 18:25:27 +00:00
|
|
|
// Filter for filtering out only the beach ball emote
|
|
|
|
const filter = (reaction) => {
|
2020-08-03 21:28:26 +00:00
|
|
|
return reaction.emoji.id === config.emoteID;
|
2020-08-03 18:25:27 +00:00
|
|
|
};
|
|
|
|
|
2020-08-03 15:51:28 +00:00
|
|
|
client.on('ready', () => {
|
|
|
|
//logs when the bot comes online
|
|
|
|
console.info(
|
|
|
|
`Bot has started, with ${client.users.cache.size} users, in \
|
|
|
|
${client.channels.cache.size} channels of ${client.guilds.cache.size} guilds.`);
|
|
|
|
|
|
|
|
// Sits bots status to "Playing with beachballs"
|
|
|
|
client.user.setPresence({
|
|
|
|
activity: {
|
|
|
|
name: `with beachballs`,
|
|
|
|
type: 'PLAYING',
|
|
|
|
},
|
2020-08-03 20:29:36 +00:00
|
|
|
status: 'idle',
|
2020-08-03 15:51:28 +00:00
|
|
|
}).then(() => {
|
2020-08-04 17:42:26 +00:00
|
|
|
console.log("Status set!")
|
2020-08-03 15:51:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2020-08-03 20:29:36 +00:00
|
|
|
|
2020-08-03 18:25:27 +00:00
|
|
|
client.on('message', async message => {
|
2020-08-03 20:29:36 +00:00
|
|
|
// Message processing
|
|
|
|
|
|
|
|
// Only can be used in #linecon
|
2020-08-03 21:51:12 +00:00
|
|
|
// let okchannel = client.channels.cache.get("710574818222931968")
|
|
|
|
// if (!(message.channel === okchannel)) return;
|
2020-08-03 20:29:36 +00:00
|
|
|
|
|
|
|
// 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') {
|
|
|
|
|
|
|
|
const emote = client.emojis.cache.get(config.emoteID)
|
|
|
|
|
|
|
|
message.channel.send("Who wants to play with the beach ball?")
|
2020-08-03 21:51:12 +00:00
|
|
|
.then(message => {
|
2020-08-03 22:05:02 +00:00
|
|
|
// Reacts to its own message
|
2020-08-03 20:29:36 +00:00
|
|
|
message.react(config.emoteID)
|
|
|
|
.catch((err) => {
|
|
|
|
console.error('Something went wrong', err)
|
|
|
|
})
|
2020-08-03 22:05:02 +00:00
|
|
|
|
|
|
|
message.awaitReactions(filter, {max: 25, time: 60000, errors: ['time']})
|
|
|
|
.then(collected => {
|
|
|
|
const reaction = collected.first();
|
|
|
|
if (reaction.emoji === emote) {
|
|
|
|
players = reaction.users;
|
|
|
|
}
|
|
|
|
})
|
2020-08-03 20:29:36 +00:00
|
|
|
})
|
2020-08-03 18:25:27 +00:00
|
|
|
.catch((err) => {
|
|
|
|
console.error("Something went wrong!", err)
|
|
|
|
return message.channel.send("Something went wrong..."
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2020-08-03 22:05:02 +00:00
|
|
|
|
2020-08-03 18:25:27 +00:00
|
|
|
// going to change this to an on. statement and try making it more "JS" I think I see where you are going.
|
2020-08-03 22:05:02 +00:00
|
|
|
|
2020-08-03 20:29:36 +00:00
|
|
|
|
2020-08-03 18:25:27 +00:00
|
|
|
//This will start passing the ball
|
2020-08-03 20:29:36 +00:00
|
|
|
|
|
|
|
function ball(message) {
|
2020-08-03 21:51:12 +00:00
|
|
|
message.reply(`${emote} ${value}`)
|
2020-08-03 20:29:36 +00:00
|
|
|
.then(() => {
|
2020-08-03 21:51:12 +00:00
|
|
|
message.react('config.emoteID')
|
2020-08-03 20:29:36 +00:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error("something went wrong!", err)
|
|
|
|
return message.channel.send("Something went wrong... I couldn't react.")
|
|
|
|
})
|
|
|
|
}
|
2020-08-03 15:51:28 +00:00
|
|
|
|
2020-08-04 14:25:20 +00:00
|
|
|
//message.reply should start the game and call the first user based on the
|
|
|
|
//random user generator from our array
|
|
|
|
message.reply("Let's start! <@" + value + ">").then(() => {
|
2020-08-03 18:25:27 +00:00
|
|
|
})
|
|
|
|
message.awaitReactions(filter, {max: 1, time: 30000, errors: ['time']})
|
|
|
|
.then(collected => {
|
|
|
|
const reaction = collected.first();
|
2020-08-04 14:25:20 +00:00
|
|
|
//VERY rough while statement should maybe work...? Need to update the bot and see
|
|
|
|
//what happens when it runs since I don't write in JS
|
2020-08-04 17:31:39 +00:00
|
|
|
while (1) {
|
|
|
|
if (reaction.emoji === client.emojis.cache.get(config.emoteID)) {
|
|
|
|
message.reply("Let's start! <@" + value + ">")
|
|
|
|
.then(() => {
|
|
|
|
message.awaitReactions(filter, {max: 1, time: 30000, errors: ['time']})
|
|
|
|
}).catch( err => {
|
|
|
|
console.error("Something went wrong awaiting reactions", err )
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:25:27 +00:00
|
|
|
})
|
2020-08-03 15:51:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-08-03 20:29:36 +00:00
|
|
|
client.login(config.token).then(() => {
|
|
|
|
console.log("Bot is logged in!")
|
|
|
|
});
|