Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Things we need
- const Discord = require("discord.js");
- const client = new Discord.Client();
- const fs = require("fs");
- const config = require("./config.json");
- const YTDL = require("ytdl-core");
- let points = JSON.parse(fs.readFileSync("./points.json", "utf8"));
- let flowerType;
- var servers = {};
- function play(connection, message) {
- var server = servers[message.guild.id];
- server.dispatcher = connection.playStream(YTDL(server.queue[0], { filter: "audioonly" }));
- server.queue.shift();
- server.dispatcher.on("end", function () {
- if (server.queue[0]) play(connection, message);
- else connection.disconnect();
- });
- }
- function pickNumber() {
- return Math.floor(Math.random() * Math.floor(1001));
- }
- function pickFlower(number) {
- if (number == 0) {
- flowerType = 'white';
- }
- if (number == 1) {
- flowerType = 'black';
- }
- if (number > 2 && number < 142) {
- flowerType = 'red';
- }
- if (number > 142 && number < 295) {
- flowerType = 'blue';
- }
- if (number > 295 && number < 441) {
- flowerType = 'yellow';
- }
- if (number > 441 && number < 598) {
- flowerType = 'purple'
- }
- if (number > 598 && number < 742) {
- flowerType = 'orange'
- }
- if (number > 742 && number < 888) {
- flowerType = 'mixed'
- }
- if (number > 888 && number < 1000) {
- flowerType = 'assorted'
- }
- }
- // Sends things in the cmd and sets the bots activity and status
- client.on("ready", function (evt) {
- console.log(" ")
- console.log(" Connected!")
- console.log(" Logged in as: " + client.user.username + " " + client.user.id)
- console.log("========================================")
- console.log(" ")
- client.user.setActivity('oksure', { type: 'PLAYING' });
- client.user.setStatus('dnd');
- });
- // This loop reads the /events/ folder and attaches each event file to the appropriate event.
- fs.readdir("./events/", (err, files) => {
- if (err) return console.error(err);
- files.forEach(file => {
- let eventFunction = require(`./events/${file}`);
- let eventName = file.split(".")[0];
- // super-secret recipe to call events with all their proper arguments *after* the `client` var.
- client.on(eventName, (...args) => eventFunction.run(client, ...args));
- });
- });
- client.on("message", message => {
- if (message.author.bot) return;
- if (message.content.indexOf(config.prefix) !== 0) return;
- // Define args
- const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
- const command = args.shift().toLowerCase();
- // If the command isnt prefix then find the command it is
- if (command != "prefix") {
- if (command != "play") {
- if (command != "skip") {
- if (command != "stop") {
- if (command != "level") {
- if (command != "give") {
- if (command != "remove") {
- if (command != "gamble") {
- try {
- let commandFile = require(`./commands/${command}.js`);
- commandFile.run(client, message, args);
- } catch (err) {
- console.error(err);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- });
- client.on("message", async message => {
- if (message.author.bot) return;
- if (message.content.indexOf(config.prefix) !== 0) return;
- // Define args
- const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
- const command = args.shift().toLowerCase();
- let gameType;
- let hocPick;
- // if the points don"t exist, init to 0;
- if (!points[message.author.id]) points[message.author.id] = {
- points: 0,
- level: 0
- };
- fs.writeFile("./points.json", JSON.stringify(points), (err) => {
- if (err) console.error(err)
- });
- switch (command) {
- case "prefix":
- if (message.author.id == config.ownerID) {
- let newPrefix = message.content.split(" ").slice(1, 2)[0];
- if (!newPrefix) {
- message.channel.send("cant change prefix to blank");
- return;
- }
- if (newPrefix) {
- config.prefix = newPrefix;
- fs.writeFile("./config.JSON", JSON.stringify(config), (err) => console.error);
- message.channel.send("prefix has been set to " + newPrefix);
- console.log("prefix has been set to " + newPrefix);
- }
- }
- if (message.author.id != config.ownerID) {
- message.channel.send("you dont have access to this");
- }
- break;
- case "play":
- if (message.channel.type === 'dm') return;
- let linkFromMessage = args.slice(0).join(" ");
- const link = linkFromMessage;
- if (!args[0]) {
- message.channel.send("linkplsfuck");
- return;
- }
- if (!message.member.voiceChannel) {
- message.channel.send("not in channel");
- return;
- }
- if (!servers[message.guild.id]) servers[message.guild.id] = {
- queue: []
- };
- if (link.startsWith('https://www.youtube.com/watch?v=')) {
- var server = servers[message.guild.id];
- server.queue.push(args[0]);
- if (!message.guild.voiceConnection) message.member.voiceChannel.join().then(function (connection) {
- play(connection, message);
- });
- console.log("Playing: " + link);
- }
- if (!link.startsWith('https://www.youtube.com/watch?v=')) {
- message.channel.send("not valid");
- }
- break;
- case "skip":
- if (message.channel.type === 'dm') return;
- var server = servers[message.guild.id];
- if (server.dispatcher) server.dispatcher.end();
- break;
- case "stop":
- if (message.channel.type === 'dm') return;
- var server = servers[message.guild.id];
- if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
- break;
- case "give":
- if (message.channel.type === 'dm') return;
- let amountFromMessage = args.slice(1).join(" ");
- const giveMember = message.mentions.members.first();
- // if the points don"t exist, init to 0;
- if (!points[giveMember.id]) points[giveMember.id] = {
- points: 0,
- level: 0
- };
- message.reply("gave " + giveMember + " " + amountFromMessage + " points");
- var x = +points[giveMember.id].points + +amountFromMessage;
- points[giveMember.id].points = x;
- fs.writeFile("./points.json", JSON.stringify(points), (err) => {
- if (err) console.error(err)
- });
- break;
- case "remove":
- if (message.channel.type === 'dm') return;
- let amRemoveFromMessage = args.slice(1).join(" ");
- const takeMember = message.mentions.members.first();
- message.reply("took " + amRemoveFromMessage + " points from " + takeMember);
- var y = +points[takeMember.id].points + -amRemoveFromMessage;
- points[takeMember.id].points = y;
- fs.writeFile("./points.json", JSON.stringify(points), (err) => {
- if (err) console.error(err)
- });
- break;
- case "level":
- let userData = points[message.author.id];
- if (userData.points < 83) {
- userData.level = 0;
- message.reply(`You are currently level ${userData.level}, with ${userData.points} points.`);
- }
- if (userData.points >= 83 && userData.level != 1) {
- userData.level = 1;
- }
- if (userData.level >= 1) {
- let curLevel = Math.floor(userData.points / 70);
- userData.level = curLevel;
- message.reply(`You are currently level ${userData.level}, with ${userData.points} points.`);
- fs.writeFile("./points.json", JSON.stringify(points), (err) => {
- if (err) console.error(err)
- });
- }
- break;
- case "gamble":
- let gambleData = points[message.author.id];
- let amToGamble = args.slice(0).join(" ");
- message.delete().catch(O_o => { });
- if (amToGamble > gambleData.points) {
- message.reply(`you dont have enough points to gamble that much you only have ` + gambleData.points + " points");
- }
- if (gambleData.points >= amToGamble) {
- let mesg = await message.reply(`you have ` + gambleData.points + ` and you're trying to gamble ` + amToGamble + " confirm:");
- await mesg.react('👍');
- await mesg.react('👎');
- const filter = (reaction, user) => {
- return ['👍', '👎'].includes(reaction.emoji.name) && user.id === message.author.id;
- };
- const reactions = await mesg.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
- .then(collected => {
- const reaction = collected.first();
- if (reaction.emoji.name === '👍') {
- gameType = 'hoc';
- mesg.delete().catch(console.error);
- console.log(gameType);
- }
- if (reaction.emoji.name === '👎') {
- gameType = 'null';
- mesg.delete();
- message.reply('closing gamble request');
- console.log(gameType);
- }
- })
- .catch(collected => {
- message.reply('you didn\'t react with neither a thumbs up, nor a thumbs down.');
- message.channel.send('closing gamble request');
- mesg.delete();
- });
- }
- if (gameType == 'hoc') {
- let hocmesg = await message.reply(`hot or cold?`);
- await hocmesg.react('🔥');
- await hocmesg.react('🍧');
- const filter = (reaction, user) => {
- return ['🔥', '🍧'].includes(reaction.emoji.name) && user.id === message.author.id;
- };
- const reactions = await hocmesg.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
- .then(collected => {
- const reaction = collected.first();
- if (reaction.emoji.name === '🔥') {
- message.reply('you chose hot').then(msg => msg.delete(10000));
- hocPick = 'hot';
- let numeber = pickNumber();
- console.log(numeber);
- let flower = pickFlower(numeber)
- console.log(flowerType);
- message.channel.send('Flower was: ' + flowerType).then(msg => msg.delete(10000));
- hocmesg.delete();
- }
- if (reaction.emoji.name === '🍧') {
- message.reply('you chose cold').then(msg => msg.delete(10000));
- hocPick = 'cold';
- let numeber = pickNumber();
- console.log(numeber);
- let flower = pickFlower(numeber)
- console.log(flowerType);
- message.channel.send('Flower was: ' + flowerType).then(msg => msg.delete(10000));
- hocmesg.delete();
- }
- })
- .catch(collected => {
- message.reply('you didn\'t react with neither a thumbs up, nor a thumbs down.');
- message.channel.send('closing gamble request');
- mesg.delete();
- });
- if (hocPick == 'hot')
- if (flowerType == 'red' || flowerType == 'yellow' || flowerType == 'orange') {
- message.channel.send('won').then(msg => msg.delete(10000));
- var n = +points[message.author.id].points + +amToGamble;
- points[message.author.id].points = n;
- fs.writeFile("./points.json", JSON.stringify(points), (err) => {
- if (err) console.error(err)
- });
- return;
- }
- if (hocPick == 'hot')
- if (flowerType == 'purple' || flowerType == 'blue' || flowerType == 'assorted') {
- message.channel.send('lose ggez').then(msg => msg.delete(10000));
- var o = +points[message.author.id].points - +amToGamble;
- points[message.author.id].points = o;
- fs.writeFile("./points.json", JSON.stringify(points), (err) => {
- if (err) console.error(err)
- });
- return;
- }
- if (hocPick == 'cold')
- if (flowerType == 'purple' || flowerType == 'blue' || flowerType == 'assorted') {
- message.channel.send('won').then(msg => msg.delete(10000));
- var n = +points[message.author.id].points + +amToGamble;
- points[message.author.id].points = n;
- fs.writeFile("./points.json", JSON.stringify(points), (err) => {
- if (err) console.error(err)
- });
- return;
- }
- if (hocPick == 'cold')
- if (flowerType == 'red' || flowerType == 'yellow' || flowerType == 'orange') {
- message.channel.send('lose ggez').then(msg => msg.delete(10000));
- var o = +points[message.author.id].points - +amToGamble;
- points[message.author.id].points = o;
- fs.writeFile("./points.json", JSON.stringify(points), (err) => {
- if (err) console.error(err)
- });
- return;
- }
- if (flowerType == 'mixed') {
- message.channel.send('auto lose ggez').then(msg => msg.delete(10000));
- var o = +points[message.author.id].points - +amToGamble;
- points[message.author.id].points = o;
- fs.writeFile("./points.json", JSON.stringify(points), (err) => {
- if (err) console.error(err)
- });
- return;
- }
- if (flowerType == 'white' || flowerType == 'black') {
- message.channel.send('Wow, thats rare.. x100 win').then(msg => msg.delete(10000));
- var n = +points[message.author.id].points + (+amToGamble * 100);
- points[message.author.id].points = n;
- fs.writeFile("./points.json", JSON.stringify(points), (err) => {
- if (err) console.error(err)
- });
- return;
- }
- }
- break;
- }
- });
- client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement