Advertisement
gravvy

Untitled

Aug 2nd, 2021
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Modules
  2. const botconfig = require("./botconfig.json");
  3. const Discord = require("discord.js");
  4. const cmdResponses = require("./utils/cmdResponses.js");
  5. const Locales = require("./utils/locales.js");
  6. const mongoose = require('mongoose');
  7. const Functions = require("./functions.js");
  8. const fs = require("fs");
  9. const bot = new Discord.Client();
  10. bot.commands = new Discord.Collection();
  11. bot.aliases = new Discord.Collection();
  12. const coinsEnabled = botconfig.coinsOn;
  13. const xpEnabled = botconfig.xpOn;
  14.  
  15. //Set up Mongoose
  16. mongoose.set('useUnifiedTopology', true);
  17. mongoose.set('useNewUrlParser', true);
  18. mongoose.set('useCreateIndex', true);
  19.  
  20. //Connect to Mongoose
  21. mongoose.connect(cmdResponses.mongodbconnect(), {
  22.     useUnifiedTopology: true,
  23.     useNewUrlParser: true,
  24.     keepAlive: true,
  25.     useCreateIndex: true
  26. }).then(() => console.log(Locales.Responses.databaseConnectedSuccess))
  27. .catch(err => {
  28.     console.log(`DB Connection Error: ${err.message}`);
  29. });
  30.  
  31. //Load all commands
  32. fs.readdir("./commands/", (err, files) => {
  33.     if(err) console.log(err);
  34.     let commandsLoaded = 0;
  35.     let jsfile = files.filter(f => f.split(".").pop() === "js");
  36.     if(jsfile.length <= 0){
  37.         return console.log(Locales.Responses.nouserfound);
  38.     }
  39.  
  40.     jsfile.forEach((f, i) => {
  41.         let props = require(`./commands/${f}`);
  42.         //console.log(`${f} loaded!`);
  43.         commandsLoaded += 1;
  44.         bot.commands.set(props.help.name, props);
  45.         props.help.aliases.forEach(alias => {
  46.             bot.aliases.set(alias, props.help.name);
  47.         });
  48.     });
  49.  
  50.     console.log(`${commandsLoaded} Commands Loaded.`);
  51. });
  52.  
  53. //Log bot status and time - Set bot discord status message
  54. bot.on("ready", async () => {
  55.     //Check Mongoose connection every 30 minutes
  56.     setTimeout(function(){
  57.         Functions.checkMongoose();
  58.         var dayMillseconds = 1000 * 60 * 30;
  59.             setInterval(function(){ // repeat this every 30 minutes
  60.                 Functions.checkMongoose();
  61.             }, dayMillseconds)
  62.         }, Functions.leftToEight())
  63.  
  64.     var DATE = Functions.convertUTCDateToLocalDate(new Date(Date.now()));
  65.     console.log(`${bot.user.username} is online on ${bot.guilds.size} servers!`);
  66.     console.log(`Time: ${DATE}`);
  67.     bot.user.setActivity("Lost Ark NA", {type: "PLAYING"});
  68. });
  69.  
  70. //User joins the server
  71. bot.on('guildMemberAdd', member => {
  72.     //Give new user the 'pleb' role
  73.     var roleNameCooldown = "Cooldown";
  74.     let roleCooldown = member.guild.roles.find(r => r.name === roleNameCooldown);
  75.  
  76.     if(!member.roles.has(roleCooldown.id))
  77.     {
  78.         var rolenameVerify = "pleb";
  79.         let rolePleb = member.guild.roles.find(r => r.name === rolenameVerify);
  80.         member.roles.add(rolePleb).catch(err => console.log(err));
  81.     }
  82.  
  83.     //Log new user
  84.     var d = new Date();
  85.     let channelName = Locales.ChannelNames.serverlogs;
  86.     let chan = member.guild.channels.find(c => c.name === channelName);
  87.     chan.send(member.user + ' has joined the server on ' + d.toUTCString());
  88. });
  89.  
  90. //User leaves the server
  91. bot.on('guildMemberRemove', member => {
  92.     //Log user leaving
  93.     var d = new Date();
  94.     let channelName = Locales.ChannelNames.serverlogs;
  95.     let chan = member.guild.channels.find(c => c.name === channelName);
  96.     chan.send(member.user + ' has left the server on ' + d.toUTCString());
  97. });
  98.  
  99. bot.on("message", async message => {
  100.     if(message.author.bot) return;
  101.     if(message.channel.type === "dm") return;
  102.  
  103.     let thisChannel = message.channel.name;
  104.     let roleName = "Guild Master";
  105.     let gRole = message.guild.roles.find(r => r.name === roleName);
  106.     let gUser = message.guild.member(message.author.id);
  107.     let foundBannedWord = false;
  108.     let marketBanned = message.guild.roles.find(r => r.name === "Market Banned");
  109.  
  110.     if(thisChannel === Locales.ChannelNames.bussingChannel)
  111.     {
  112.         if(message.member.roles.has(marketBanned.id))
  113.         {
  114.             return message.delete();
  115.         }
  116.     }
  117.  
  118.     //Function to check if guild master has posted in KR channel
  119.     if(thisChannel === botconfig.guildRecruitKR)
  120.     {
  121.         let guildChannel = botconfig.guildRecruitKR;
  122.         Functions.checkGuildMaster(guildChannel, message, gUser, gRole);
  123.     }
  124.  
  125.     //Function to check if guild master has posted in RU channel
  126.     if(thisChannel === botconfig.guildRecruitRU)
  127.     {
  128.         let guildChannel = botconfig.guildRecruitRU;
  129.         Functions.checkGuildMaster(guildChannel, message, gUser, gRole);
  130.     }
  131.  
  132.     //Banned words
  133.     var bannedWords = botconfig.bannedWords;
  134.     bannedWords.forEach(function(value)
  135.     {
  136.         if(message.content.toLowerCase().includes(value)) var foundBannedWord = true;
  137.     });
  138.  
  139.     if(foundBannedWord){message.delete();}
  140.  
  141.     //Command manager
  142.     let prefix1 = botconfig.prefix;
  143.     let prefix2 = botconfig.prefix2;
  144.     let prefix3 = botconfig.prefix3;
  145.     let prefix = botconfig.prefixArray;
  146.     let messageArray = message.content.split(" ");
  147.     let cmd = messageArray[0];
  148.     let args = messageArray.slice(1);
  149.  
  150.     if(message.content.startsWith(prefix1))
  151.     {
  152.         if(Functions.restrictedChannels(thisChannel) === true)return message.delete();
  153.         let commandFile = bot.commands.get(cmd.slice(prefix1.length)) || bot.commands.get(bot.aliases.get(cmd.slice(prefix1.length)));
  154.         if(commandFile) commandFile.run(bot,message,args);
  155.     }
  156.     else if(message.content.startsWith(prefix2))
  157.     {
  158.         if(Functions.restrictedChannels(thisChannel) === true)return message.delete();
  159.         let commandFile = bot.commands.get(cmd.slice(prefix2.length)) || bot.commands.get(bot.aliases.get(cmd.slice(prefix2.length)));
  160.         if(commandFile) commandFile.run(bot,message,args);
  161.     }
  162.     else if(message.content.startsWith(prefix3))
  163.     {
  164.         if(Functions.restrictedChannels(thisChannel) === true)return message.delete();
  165.         let commandFile = bot.commands.get(cmd.slice(prefix3.length)) || bot.commands.get(bot.aliases.get(cmd.slice(prefix3.length)));
  166.         if(commandFile) commandFile.run(bot,message,args);
  167.     }
  168.     else//Coins and XP
  169.     {
  170.         var userIDF = message.author.id;
  171.         var serverIDF = message.guild.id;
  172.  
  173.         if(coinsEnabled)
  174.         {
  175.             let coinstoadd = Math.ceil(Math.random() * 1);
  176.             Functions.addCoins(userIDF, serverIDF, coinstoadd);
  177.         }
  178.  
  179.         if(xpEnabled)
  180.         {
  181.             let xptoadd = Math.ceil(Math.random() * 2);
  182.             Functions.addXP(userIDF, serverIDF, xptoadd);
  183.         }
  184.     }
  185. });
  186.  
  187. bot.login(botconfig.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement