Advertisement
Guest User

Untitled

a guest
Jul 21st, 2021
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Client, Collection } = require("discord.js");
  2. const Discord = require('discord.js')
  3. const AutoPoster = require('topgg-autoposter')
  4. const { addScalarDependencies, e } = require("mathjs");
  5. const config = require("./config");
  6. const mongoose = require('mongoose');
  7. const express = require('express')
  8.  
  9. class EconomyClient extends Client {
  10.     constructor() {
  11.        
  12.         super();
  13.         this.discord = require("discord.js");
  14.         this.fs = require("fs");
  15.         this.path = require("path");
  16.         this.mongoose = require("mongoose");
  17.         this.commands = new Collection();
  18.         this.timeouts = new Collection();
  19.         this.ms = require('ms')
  20.         this.config = {
  21.             prefix: '$',
  22.         };
  23.  
  24.         this.schema = this.mongoose.model(
  25.             `economy`,
  26.             new this.mongoose.Schema({
  27.                 User: String,
  28.                 Bobux: Number,
  29.  
  30.             })
  31.         );
  32.  
  33.  
  34.         const self = this
  35.         this.economy = {
  36.             async getBal(User) {
  37.                 return await self.schema.findOne({
  38.                     User
  39.                 }).then((d) => d ? d.Bobux : 0)
  40.             },
  41.  
  42.             async addBal(User, Bobux) {
  43.                 return await self.schema.findOne({ User }, async(err, data) => {
  44.                     if(err) throw err
  45.                     if(data) {
  46.                         data.Bobux += Number(Bobux)
  47.                     } else {
  48.                         data = new self.schema({ User, Bobux })
  49.                     }
  50.                     data.save()
  51.                 })
  52.             },
  53.             async subBal(User, Bobux) {
  54.                 return await self.schema.findOne({ User }, async(err, data) => {
  55.                     if(err) throw err
  56.                     if(data) {
  57.                         data.Bobux -= Number(Bobux)
  58.                     } else {
  59.                         data = new self.schema({ User, Bobux })
  60.                     }
  61.                     data.save()
  62.                 })
  63.             }
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.         }
  78.     }
  79.     commandHandler(path) {
  80.         this.fs.readdirSync(this.path.normalize(path)).map((f) => {
  81.             const File = require(this.path.join(__dirname, `.`, path, f));
  82.             this.commands.set(File.name, File);
  83.         });
  84.     }
  85.     getCommand(cmd) {
  86.         return this.commands.has(cmd) ? this.commands.get(cmd) : false;
  87.     }
  88.     async start(token, path) {
  89.         this.commandHandler(path);
  90.         await  this.mongoose.connect(
  91.             `mongodb+srv://dbUser:[email protected]/Data?retryWrites=true&w=majority
  92.  
  93.  
  94.  
  95.         `,
  96.             {
  97.                 useNewUrlParser: true,
  98.                 useUnifiedTopology: true,
  99.                 useFindAndModify: false,
  100.             }
  101.  
  102.         );
  103.         this.on("ready", () => {
  104.  
  105.             const channel = this.channels.cache.get('844642765484720149');
  106.             const embed = new this.discord.MessageEmbed()
  107.                 .setTitle('Bot restarting')
  108.                 .setTimestamp()
  109.             channel.send(embed)
  110.             setTimeout(() => {
  111.                 channel.send(`Restart successful`)
  112.             }, 5000);
  113.             this.user.setActivity(`$help || $donatehelp `).catch((err) => { throw err; })
  114.         });
  115.  
  116.         this.on("message", async (message) => {
  117.             if (
  118.                 message.author.bot ||
  119.                 !message.guild ||
  120.                 !message.content.toLocaleLowerCase().startsWith(this.config.prefix)
  121.             ) return;
  122.  
  123.             const args =
  124.                 message.content.slice(this.config.prefix.length).trim().split(' ');
  125.             const cmd = args.shift().toLocaleLowerCase();
  126.             const command = this.getCommand(cmd) || this.commands.find(a => a.aliases && a.aliases.includes(cmd))
  127.             if (!command) return;
  128.             if (command.timeout) {
  129.                 if (this.timeouts.has(`${command.name}${message.author.id}`))
  130.                     return message.channel.send(
  131.                         this.embed({
  132.                             description: `You can't use this commmand for another ${this.ms(
  133.                                this.timeouts.get(`${command.name}${message.author.id}`) - Date.now(),
  134.                                { long: true }
  135.                            )}`,
  136.                        }, message)
  137.                    );
  138.                command.run(this, message, args).catch(console.error);
  139.                this.timeouts.set(
  140.                    `${command.name}${message.author.id}`,
  141.                    Date.now() + command.timeout
  142.                );
  143.                setTimeout(() => {
  144.                    this.timeouts.delete(`${command.name}${message.author.id}`);
  145.                }, command.timeout);
  146.            } else return command.run(this, message, args).catch(console.error);
  147.  
  148.  
  149.        });
  150.  
  151.        this.on('guildCreate', async (guild, message) => {
  152.            const Embed = new Discord.MessageEmbed()
  153.                .setTitle('Boblox Help!')
  154.  
  155.                .addFields(
  156.                    { name: '💰 How to earn Bobux', value: '`$earnhelp`' },
  157.                    { name: '💸How to create and earn bobux off a game', value: '`$gamehelp`' },
  158.                    { name: '💹 Complete Guide on how to use boblox and become the richest', value: '`$guide`' },
  159.                    { name: '🧧 Donate to support us and recieve many Benefits', value: '`$donatehelp`' },
  160.                    { name: '💹 How to trade in the Boblox Stonk Market', value: '`$stonkhelp`' },
  161.  
  162.                )
  163.  
  164.  
  165.            const owner = await guild.members.fetch(guild.ownerID);
  166.            owner.send('Support/community server: https://discord.gg/BcNx4SUq54')
  167.             owner.send(Embed)
  168.  
  169.             const yourembed = new this.discord.MessageEmbed()
  170.                 .setTitle('New server bois')
  171.                 .setDescription(`Server name: ${guild.name} \n Server id: ${guild.id} \n Server owner: ${owner} \n Member Count: ${guild.memberCount}`)
  172.             const channel = this.channels.cache.get("836989035804753951")
  173.             channel.send(yourembed)
  174.  
  175.  
  176.         });
  177.        
  178.  
  179.            await this.login(token);
  180.  
  181.      
  182.     }
  183.    
  184.     embed(data, message) {
  185.         return new this.discord.MessageEmbed({
  186.             ...data,
  187.             color: `RANDOM`,
  188.         }).setTimestamp()
  189.     }
  190. }
  191.  
  192.  
  193.  
  194.  
  195. module.exports = EconomyClient;
  196. new EconomyClient().start(require(`./config`).token, './commands', './index');
  197.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement