dvs come take a look

This commit is contained in:
Alex 2020-08-04 20:20:51 -05:00
parent e6fdc23355
commit 014fddea3c
2 changed files with 149 additions and 47 deletions

View File

@ -11,10 +11,6 @@ let value = players[Math.floor(Math.random() * players.length)];
// Create client
const client = new Discord.Client();
// Filter for filtering out only the beach ball emote
const filter = (reaction) => {
return reaction.emoji.id === config.emoteID;
};
client.on('ready', () => {
//logs when the bot comes online
@ -56,6 +52,11 @@ client.on('message', async message => {
// The main function of this bot. To play games!
if (command === 'play') {
// Filter for filtering out only the beach ball emote
const filter = (reaction) => {
return reaction.emoji.id === config.emoteID && !(message.author.bot);
};
const emote = client.emojis.cache.get(config.emoteID)
message.channel.send("Who wants to play with the beach ball?")
@ -66,7 +67,7 @@ client.on('message', async message => {
console.error('Something went wrong', err)
})
message.awaitReactions(filter, {max: 25, time: 60000, errors: ['time']})
message.awaitReactions(filter, {max: 25, time: 300000, errors: ['time']})
.then(collected => {
const reaction = collected.first();
if (reaction.emoji === emote) {
@ -75,49 +76,70 @@ client.on('message', async message => {
})
})
.catch((err) => {
console.error("Something went wrong!", err)
return message.channel.send("Something went wrong..."
)
}
)
// going to change this to an on. statement and try making it more "JS" I think I see where you are going.
//This will start passing the ball
function ball(message) {
message.reply(`${emote} ${value}`)
.then(() => {
message.react('config.emoteID')
})
.catch((err) => {
console.error("something went wrong!", err)
return message.channel.send("Something went wrong... I couldn't react.")
})
}
//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(() => {
})
message.awaitReactions(filter, {max: 1, time: 30000, errors: ['time']})
.then(collected => {
const reaction = collected.first();
//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
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 )
})
}
}
console.error("Something went wrong!", err)
return message.channel.send("Something went wrong...")
})
// message.reply should start the game and call the first user.
// After that it is based on the random user generator from our array
setTimeout(() => {
message.reply("Let's start!").then(message => {
// Initiating ball function
function ball() {
// In theory sends a message
message.channel.send(`${emote} ${value}`)
.then(() => {
message.react('config.emoteID')
})
.catch((err) => {
console.error("something went wrong!", err)
return message.channel.send("Something went wrong... I couldn't react.")
})
}
message.react(config.emoteID)
.then(() => {
const collector = message.createReactionCollector(filter, {
max: 2,
time: 30000,
errors: ['time']
})
collector.on("collect", () => {
ball();
})
})
// const collector = message.createReactionCollector(filter, {max: 1, time: 30000, errors: ['time']})
//
// collector.on("collect", () => {
// ball();
// })
// message.awaitReactions(filter, {max: 1, time: 30000, errors: ['time']})
// .then(collected => {
// const reaction = collected.first();
// //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
// while (true) {
// if (reaction.emoji === client.emojis.cache.get(config.emoteID)) {
// message.reply("Let's start!")
// .then(() => {
// message.awaitReactions(filter, {max: 1, time: 30000, errors: ['time']})
// }).catch(err => {
// console.error("Something went wrong awaiting reactions", err)
// })
// }
// else {
// return message.channel.send("Ouch!")
// }
// }
})
// })
}, 10000)
}
});

80
src/rewrite.js Normal file
View File

@ -0,0 +1,80 @@
// Load up the libraries
const Discord = require('discord.js');
// Importing config
const config = require('./config.json')
// Create client
const client = new Discord.Client();
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',
},
status: 'idle',
}).then(() => {
console.log("Status set!")
});
})
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") {
//making the filters for the collectors
// Makes a message saying Who wants to play?
message.channel.send("who wants to play a game?")
.then( message => {
// Reacts with a beach ball
message.react("740294983982252203").then((reaction) => {
const collector = new message.createReactionCollector( beachballfilter, {
maxEmojis: 1,
max: 25,
maxUsers: 25,
time: 60000
})
//
let players
// Triggers when someone joins the react
collector.on("collect", (reaction) => {
players = reaction.users.fetch({limit: 100})
})
})
})
}
});
client.login(config.token).then(() => {
console.log("logged in")
})