Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const config = require("./config.json");
- const Discord = require("discord.js");
- const bot = new Discord.Client({disableEveryone: true});
- const commandTimeout = new Set();
- const invites = {};
- const wait = require('util').promisify(setTimeout);
- bot.on("ready", async () => {
- // "ready" isn't really ready. We need to wait a spell.
- wait(1000);
- // Load all invites for all guilds and save them to the cache.
- bot.guilds.forEach(g => {
- g.fetchInvites().then(guildInvites => {
- invites[g.id] = guildInvites;
- });
- });
- console.log(`Invites | Logged in as ${bot.user.username}#${bot.user.discriminator}`)
- var status = (`${bot.users.size} users | ${config.prefix}help`)
- bot.user.setActivity(status, { type: 'LISTENING' });
- console.log(`Invites | Status set to '${status}'`)
- if (bot.guilds.size < 2) {
- console.log(`Invites | ${bot.guilds.size} Guild`)
- } else {
- console.log(`Invites | ${bot.guilds.size} Guilds`)
- }
- if (bot.users.size < 2) {
- console.log(`Invites | ${bot.users.size} User`)
- } else {
- console.log(`Invites | ${bot.users.size} Users`)
- }
- console.log(`Invites | Client ID: ${bot.user.id}`)
- console.log(`Invites | Token: ${config.token}`)
- console.log(`Invites | Invite Link: https://discordapp.com/oauth2/authorize?&client_id=${bot.user.id}&scope=bot&permissions=8`)
- });
- bot.on('guildMemberAdd', member => {
- console.log(`[LOG] ${member.user.username}#${member.user.discriminator} joined the server`)
- member.addRole(member.guild.roles.find(val => val.name === 'Member'));
- member.guild.fetchInvites().then(guildInvites => {
- // This is the *existing* invites for the guild.
- const ei = invites[member.guild.id];
- // Update the cached invites for the guild.
- invites[member.guild.id] = guildInvites;
- // Look through the invites, find the one for which the uses went up.
- const invite = guildInvites.find(i => ei.get(i.code).uses < i.uses);
- // This is just to simplify the message being sent below (inviter doesn't have a tag property)
- const inviter = bot.users.get(invite.inviter.id);
- const logChannel = member.guild.channels.find(channel => channel.name === "šŖ-join-leave");
- var fs = require('fs')
- var joinedlist = fs.readFileSync('joined.txt', 'utf8');
- var newjoinedlist = joinedlist + `\n${member.user.id}`
- fs.writeFile("joined.txt", newjoinedlist, function(err) {
- if(err) {
- return console.log(err);
- }
- })
- if (joinedlist.includes(member.user.id) === false) {
- var path = `${inviter.id}.txt`
- if (fs.existsSync(path)) {
- var invitecount = fs.readFileSync(path, 'utf8');
- var newinvitecount = parseInt(invitecount) + parseInt(1)
- fs.writeFile(path, newinvitecount, function(err) {
- if(err) {
- return console.log(err);
- }
- })
- console.log(`[LOG] ${path} modified.`)
- logChannel.send(`<@${member.user.id}> joined using invite code **${invite.code}** from <@${inviter.id}>.\n<@${inviter.id}> now has a total of **${newinvitecount}** invites.`);
- if ((newinvitecount % 3) === 0) {
- var keylist = fs.readFileSync('keys.txt', 'utf8');
- var keyarray = keylist.split('\n')
- var keyarrayforrewrite = keylist.split('\n')
- var newkeyarray = keyarrayforrewrite.splice(1)
- var newkeylist = newkeyarray.join('\n')
- fs.writeFile("keys.txt", newkeylist, function(err) {
- if(err) {
- return console.log(err);
- }
- })
- bot.users.get(inviter.id).send(keyarray[0])
- }
- else {
- return;
- }
- if (newinvitecount === 3) {
- member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'Rookie (3+ Invites)'));
- }
- else if (newinvitecount === 5) {
- member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'Super (5+ Invites)'));
- }
- else if (newinvitecount === 10) {
- member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'Elite (10+ Invites)'));
- }
- else if (newinvitecount === 25) {
- member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'Ultra (25+ Invites)'));
- }
- else if (newinvitecount === 50) {
- member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'Pro (50+ Invites)'));
- }
- else if (newinvitecount === 100) {
- member.guild.members.get(inviter.id).addRole(member.guild.roles.find(val => val.name === 'VIP (100+ Invites)'));
- }
- }
- else {
- fs.writeFile(path, '1', function (err) {
- if (err) throw err;
- console.log(`[LOG] ${path} created.`)
- })
- logChannel.send(`<@${member.user.id}> joined using invite code ${invite.code} from <@${inviter.id}>.\n<@${inviter.id}> now has a total of **1** invite.`);
- }
- }
- else {
- var path = `${inviter.id}.txt`
- if (fs.existsSync(path)) {
- var invitecount = fs.readFileSync(path, 'utf8');
- var newinvitecount = parseInt(invitecount) + parseInt(0)
- fs.writeFile(path, newinvitecount, function(err) {
- if(err) {
- return console.log(err);
- }
- })
- console.log(`[LOG] ${path} modified.`)
- logChannel.send(`<@${member.user.id}> joined using invite code ${invite.code} from <@${inviter.id}>.\n<@${inviter.id}> now has a total of **${newinvitecount}** invites.`);
- }
- else {
- logChannel.send(`<@${member.user.id}> joined using invite code ${invite.code} from <@${inviter.id}>.`);
- }
- }
- });
- })
- bot.on("message", async message => {
- var status = (`${bot.users.size} users | ${config.prefix}help`)
- bot.user.setActivity(status, { type: 'LISTENING' });
- if (message.author.bot) return;
- if (!message.content.startsWith(config.prefix)) {
- if (message.channel.id !== "654808100897030160") {
- return;
- }
- else {
- if (message.member.voiceChannel === undefined) {
- message.delete()
- message.author.send("Messages can only be sent in <#654808100897030160> if you're in a voice channel.")
- }
- else {
- return;
- }
- }
- };
- var args = message.content.slice(config.prefix.length).trim().split(/ +/g);
- var command = args.shift().toLowerCase();
- if (command === "ping") {
- console.log(`[LOG] ${message.author.username}#${message.author.discriminator} executed ${config.prefix}ping`)
- var m = await message.channel.send("Pong!")
- m.edit(`Pong! ${m.createdTimestamp - message.createdTimestamp}ms`)
- }
- else if (command === "help") {
- console.log(`[LOG] ${message.author.username}#${message.author.discriminator} executed ${config.prefix}help`)
- message.react('ā ')
- var helpembed = new Discord.RichEmbed()
- .setColor('#ee3734')
- .setTitle('Help')
- .setDescription(`__**General**__\n**${config.prefix}help** Displays all commands\n\n__**Casino**__\n**${config.prefix}spin** Take your chances at winning a steam key!`)
- message.author.send(helpembed)
- }
- else if (command === "spin") {
- const casinoleft = bot.emojis.get("655003282707841065");
- const casinoright = bot.emojis.get("655004694988455937");
- console.log(`[LOG] ${message.author.username}#${message.author.discriminator} executed ${config.prefix}spin`)
- if (message.channel.id !== "654804323535945765") {
- message.channel.send(`Daily spins can only be completed in <#654804323535945765>.`)
- return;
- }
- else {
- if (commandTimeout.has(message.author.id)) {
- message.channel.send(`You can only spin once every 24 hours!`)
- }
- else {
- commandTimeout.add(message.author.id)
- setTimeout(() => {
- commandTimeout.delete(message.author.id);
- }, 86400000);
- var spinrng = (Math.random() * (9 - 0) + 0)
- console.log(`[SPIN] ${message.author.username}#${message.author.discriminator} rolled ${spinrng}`)
- if (spinrng > 8) {
- var n = await message.channel.send(`${casinoleft} | š° | ${casinoright}\nā | ā | ā \nā | ā | ā \nā | ā | ā`)
- setTimeout(() => {
- n.edit(`${casinoleft} | š° | ${casinoright}\nā | ā | ā \nā | ā | ā \nā | ā | ā `);
- }, 1500);
- setTimeout(() => {
- n.edit(`${casinoleft} | š° | ${casinoright}\nā | ā | ā\nā | ā | ā \nā | ā | ā `);
- }, 2500);
- setTimeout(() => {
- message.channel.send(`**Winnings:**\nš <@${message.author.id}> You have won 1x Steam Key! Check your DMs for your prize! š`)
- }, 2600);
- setTimeout(() => {
- var fs = require('fs');
- var keylist = fs.readFileSync('keys.txt', 'utf8');
- var keyarray = keylist.split('\n')
- var keyarrayforrewrite = keylist.split('\n')
- var newkeyarray = keyarrayforrewrite.splice(1)
- var newkeylist = newkeyarray.join('\n')
- fs.writeFile("keys.txt", newkeylist, function(err) {
- if(err) {
- return console.log(err);
- }
- })
- message.author.send(keyarray[0])
- }, 2600);
- }
- else {
- var n = await message.channel.send(`${casinoleft} | š° | ${casinoright}\nā | ā | ā \nā | ā | ā \nā | ā | ā`)
- setTimeout(() => {
- n.edit(`${casinoleft} | š° | ${casinoright}\nā | ā | ā\nā | ā | ā \nā | ā | ā `);
- }, 1500);
- setTimeout(() => {
- n.edit(`${casinoleft} | š° | ${casinoright}\nā | ā | ā\nā | ā | ā\nā | ā | ā `);
- }, 2500);
- setTimeout(() => {
- message.channel.send(`ā You have lost! Try again tomorrow! ā`)
- }, 2600);
- }
- }
- }
- }
- });
- bot.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement