IT'S ALIVE!!!
This commit is contained in:
parent
d63aa91a21
commit
dcc5cad7b3
294
src/index.js
294
src/index.js
|
@ -1,148 +1,146 @@
|
||||||
// Load up the libraries
|
// Load up the libraries
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
|
|
||||||
// Importing config
|
// Importing config
|
||||||
const config = require('./config.json')
|
const config = require('./config.json')
|
||||||
|
|
||||||
//User array and random number
|
// Create client
|
||||||
let players = [];
|
const client = new Discord.Client();
|
||||||
let value = players[Math.floor(Math.random() * players.length)];
|
|
||||||
|
// Triggers when the bot is logged in and
|
||||||
// Create client
|
client.on('ready', () => {
|
||||||
const client = new Discord.Client();
|
//logs when the bot comes online
|
||||||
|
console.info(
|
||||||
|
`Bot has started, with ${client.users.cache.size} users, in \
|
||||||
client.on('ready', () => {
|
${client.channels.cache.size} channels of ${client.guilds.cache.size} guilds.`);
|
||||||
//logs when the bot comes online
|
|
||||||
console.info(
|
// Sits bots status to "Playing with beachballs"
|
||||||
`Bot has started, with ${client.users.cache.size} users, in \
|
client.user.setPresence({
|
||||||
${client.channels.cache.size} channels of ${client.guilds.cache.size} guilds.`);
|
activity: {
|
||||||
|
name: `with beachballs`,
|
||||||
// Sits bots status to "Playing with beachballs"
|
type: 'PLAYING',
|
||||||
client.user.setPresence({
|
},
|
||||||
activity: {
|
status: 'idle',
|
||||||
name: `with beachballs`,
|
}).then(() => {
|
||||||
type: 'PLAYING',
|
console.log("Status set!")
|
||||||
},
|
});
|
||||||
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")
|
||||||
client.on('message', async message => {
|
// if (!(message.channel === okchannel)) return;
|
||||||
// Message processing
|
|
||||||
|
// Discards messages from bots
|
||||||
// Only can be used in #linecon
|
if (message.author.bot) return;
|
||||||
// let okchannel = client.channels.cache.get("710574818222931968")
|
|
||||||
// if (!(message.channel === okchannel)) return;
|
// Discards messages that dont being with the prefix
|
||||||
|
if (message.content.indexOf(config.prefix) !== 0) return;
|
||||||
// Discards messages from bots
|
|
||||||
if (message.author.bot) 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);
|
||||||
// Discards messages that dont being with the prefix
|
const command = args.shift().toLowerCase();
|
||||||
if (message.content.indexOf(config.prefix) !== 0) return;
|
|
||||||
|
// The main function of this bot. To play games!
|
||||||
// Makes the message into an array then cuts off the beginning and puts it in the command variable
|
if (command === "play") {
|
||||||
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
|
//making the filters for the collectors
|
||||||
const command = args.shift().toLowerCase();
|
|
||||||
|
|
||||||
// The main function of this bot. To play games!
|
// Makes a message saying Who wants to play?
|
||||||
if (command === 'play') {
|
message.channel.send("who wants to play a game?")
|
||||||
|
.then(message => {
|
||||||
// Filter for filtering out only the beach ball emote
|
// Reacts with a beach ball
|
||||||
const filter = (reaction) => {
|
message.react("739941658639990866")
|
||||||
return reaction.emoji.id === config.emoteID && !(message.author.bot);
|
.then(() => {
|
||||||
};
|
// Collects reactions on the previous message
|
||||||
|
const beachballfilter = (reaction, user) => {
|
||||||
const emote = client.emojis.cache.get(config.emoteID)
|
return reaction.emoji.id === '739941658639990866' && user.id !== '223215601638703105'
|
||||||
|
}
|
||||||
message.channel.send("Who wants to play with the beach ball?")
|
const collector = message.createReactionCollector(beachballfilter, {
|
||||||
.then(message => {
|
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 60 Seconds
|
||||||
// Reacts to its own message
|
max: 25,
|
||||||
message.react(config.emoteID)
|
maxUsers: 25,
|
||||||
.catch((err) => {
|
time: 10000
|
||||||
console.error('Something went wrong', err)
|
})
|
||||||
})
|
|
||||||
|
|
||||||
message.awaitReactions(filter, {max: 25, time: 300000, errors: ['time']})
|
// Triggers when someone joins the react
|
||||||
.then(collected => {
|
collector.on("end", () => {
|
||||||
const reaction = collected.first();
|
const players = Array.from(collector.users)
|
||||||
if (reaction.emoji === emote) {
|
|
||||||
players = reaction.users;
|
|
||||||
}
|
console.log(players)
|
||||||
})
|
console.log(players.length + " players")
|
||||||
})
|
|
||||||
.catch((err) => {
|
message.channel.send(`<:BeachBall:739941658639990866> ${(players[0].toString()).slice(19)}`).then(message => {
|
||||||
console.error("Something went wrong!", err)
|
message.react(config.emoteID).then(() => {
|
||||||
return message.channel.send("Something went wrong...")
|
const roundone = (reaction, user) => {
|
||||||
})
|
return reaction.emoji.name === config.emoteID && user.id !== '223215601638703105' //&& reaction.user === players[0]
|
||||||
|
}
|
||||||
// message.reply should start the game and call the first user.
|
const collector = message.createReactionCollector(roundone, {
|
||||||
// After that it is based on the random user generator from our array
|
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 60 Seconds
|
||||||
|
max: 2,
|
||||||
setTimeout(() => {
|
maxUsers: 2,
|
||||||
message.reply("Let's start!").then(message => {
|
time: 10000
|
||||||
// Initiating ball function
|
})
|
||||||
function ball() {
|
|
||||||
// In theory sends a message
|
collector.on("collect", () => {
|
||||||
message.channel.send(`${emote} ${value}`)
|
function ball() {
|
||||||
.then(() => {
|
// Generates a random number from 0 to players.length
|
||||||
message.react('config.emoteID')
|
let num = Math.floor(Math.random() * (players.length));
|
||||||
})
|
console.log(num);
|
||||||
|
|
||||||
.catch((err) => {
|
//sends a message with the beach ball emote and pings a player
|
||||||
console.error("something went wrong!", err)
|
message.channel.send(`<:BeachBall:739941658639990866> ${(players[num].toString()).slice(19)}`).then(message => {
|
||||||
return message.channel.send("Something went wrong... I couldn't react.")
|
// Reacts the message with hands
|
||||||
})
|
message.react(config.emoteID).then(() => {
|
||||||
}
|
|
||||||
|
// Makes a filter that allows the hand emoji and only form the player that was randomly picked
|
||||||
message.react(config.emoteID)
|
const handfilter = (reaction, user) => {
|
||||||
.then(() => {
|
return reaction.emoji.name === config.emoteID && user.id !== '223215601638703105' //&& reaction.user === players[num]
|
||||||
const collector = message.createReactionCollector(filter, {
|
}
|
||||||
max: 2,
|
const collector = message.createReactionCollector(handfilter, {
|
||||||
time: 30000,
|
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 60 Seconds
|
||||||
errors: ['time']
|
max: 2,
|
||||||
})
|
maxUsers: 2,
|
||||||
|
time: 10000
|
||||||
collector.on("collect", () => {
|
})
|
||||||
ball();
|
|
||||||
})
|
//on collection play again
|
||||||
})
|
collector.on("collect", () => {
|
||||||
|
ball()
|
||||||
|
})
|
||||||
// const collector = message.createReactionCollector(filter, {max: 1, time: 30000, errors: ['time']})
|
|
||||||
//
|
collector.on("end", () => {
|
||||||
// collector.on("collect", () => {
|
if (collector.users.size === 0) {
|
||||||
// ball();
|
message.channel.send("Ouch")
|
||||||
// })
|
}
|
||||||
// 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
|
ball()
|
||||||
// while (true) {
|
})
|
||||||
// if (reaction.emoji === client.emojis.cache.get(config.emoteID)) {
|
|
||||||
// message.reply("Let's start!")
|
collector.on("end", () => {
|
||||||
// .then(() => {
|
message.channel.send("Ouch!")
|
||||||
// message.awaitReactions(filter, {max: 1, time: 30000, errors: ['time']})
|
console.log(Array.from(collector.users))
|
||||||
// }).catch(err => {
|
})
|
||||||
// console.error("Something went wrong awaiting reactions", err)
|
})
|
||||||
// })
|
})
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// return message.channel.send("Ouch!")
|
})
|
||||||
// }
|
|
||||||
// }
|
})
|
||||||
})
|
|
||||||
// })
|
})
|
||||||
}, 10000)
|
}
|
||||||
|
});
|
||||||
}
|
|
||||||
});
|
client.login(config.token).then(() => {
|
||||||
|
console.log("logged in")
|
||||||
client.login(config.token).then(() => {
|
})
|
||||||
console.log("Bot is logged in!")
|
|
||||||
});
|
|
145
src/rewrite.js
145
src/rewrite.js
|
@ -1,145 +0,0 @@
|
||||||
// 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(
|
|
||||||
`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("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")
|
|
||||||
|
|
||||||
message.channel.send(`<:BeachBall:739941658639990866> ${(players[0].toString()).slice(19)}`).then(message => {
|
|
||||||
message.react(config.emoteID).then( () => {
|
|
||||||
const roundone = (reaction, user) => {
|
|
||||||
return reaction.emoji.name === config.emoteID && user.id !== '223215601638703105' //&& user === players[0]
|
|
||||||
}
|
|
||||||
const collector = message.createReactionCollector(roundone, {
|
|
||||||
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 60 Seconds
|
|
||||||
max: 2,
|
|
||||||
maxUsers: 2,
|
|
||||||
time: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
collector.on("collect", () => {
|
|
||||||
function ball() {
|
|
||||||
// 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
|
|
||||||
message.channel.send(`<:BeachBall:739941658639990866> ${(players[num].toString()).slice(19)}`).then(message => {
|
|
||||||
// Reacts the message with hands
|
|
||||||
message.react(config.emoteID).then(() => {
|
|
||||||
|
|
||||||
// Makes a filter that allows the hand emoji and only form the player that was randomly picked
|
|
||||||
const handfilter = (reaction, user) => {
|
|
||||||
return reaction.emoji.id === config.emoteID && user.id !== '223215601638703105' //&& reaction.user === players[num]
|
|
||||||
}
|
|
||||||
const collector = message.createReactionCollector(handfilter, {
|
|
||||||
// Sets the maximums to 1 type of emoji, 25 reactions, 25 users, in 60 Seconds
|
|
||||||
max: 2,
|
|
||||||
maxUsers: 2,
|
|
||||||
time: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
//on collection play again
|
|
||||||
collector.on("collect", () => {
|
|
||||||
ball()
|
|
||||||
})
|
|
||||||
collector.on("end", () => {
|
|
||||||
if (collector.users.size === 0)
|
|
||||||
message.channel.send("this mean that there was most likely a filter problem")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
ball()
|
|
||||||
})
|
|
||||||
|
|
||||||
collector.on("end", () => {
|
|
||||||
message.channel.send("Ouch!")
|
|
||||||
console.log(Array.from(collector.users))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
client.login(config.token).then(() => {
|
|
||||||
console.log("logged in")
|
|
||||||
})
|
|
Loading…
Reference in New Issue