Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.12 KB | None | 0 0
  1. //TO DO:
  2. //- Add prefix.json
  3. //- Add warnings.json
  4. //- Add xp.json
  5. //- Add coins.json
  6. //- Add badwords.txt
  7. //- Add colors.json
  8. //- Add Procfile
  9.  
  10. //***********************************************************************************************************************************************
  11. // -------------------------------------------
  12. const Discord = require("discord.js")
  13. const fs = require("fs")
  14. // -------------------------------------------
  15. const colors = require("colors.json")
  16. const botconfig = require("botconfig.json")
  17. const coins = require("coins.json")
  18. const xp = require("xp.json")
  19. const badwords = require("badwords.txt")
  20. const procfile = require("Procfile")
  21. // -------------------------------------------
  22. const command = require("./commmands")
  23. // -------------------------------------------
  24. const client = new Discord.Client()
  25. const bot = new Discord.Client()
  26. // -------------------------------------------
  27. bot.commands = new Discord.Collection()
  28. // -------------------------------------------
  29. let cooldown = new Set();
  30. let cdseconds = 5;
  31. //--------------------------------------------
  32. let warns = JSON.parse(fs.readFileSync("./warnings.json", "utf8"))
  33. // -------------------------------------------
  34. //################################
  35. let red = botconfig.red
  36. let orange = botconfig.orange
  37. let yellow = botconfig.yellow
  38. let green = botconfig.green
  39. let blue = botconfig.blue
  40. let indigo = botconfig.indigo
  41. let violet = botconfig.violet
  42. //################################
  43. let black = botconfig.black
  44. let gray = botconfig.gray
  45. let white = botconfig.white
  46. //################################
  47. let pink = botconfig.pink
  48. let brown = botconfig.brown
  49. let maroon = botconfig.maroon
  50. let crimson = botconfig.crimson
  51. let turquoise = botconfig.turquoise
  52. let aqua = botconfig.aqua
  53. let aquamarine = botconfig.aquamarine
  54. let ltblue = botconfig.ltblue
  55. let navy = botconfig.navy
  56. let purple = botconfig.purple
  57. let magenta = botconfig.magenta
  58. //################################
  59. //***********************************************************************************************************************************************
  60. //END OF CONSTANTS AND VARIABLES
  61. //***********************************************************************************************************************************************
  62. fs.readdir("./commands/", (err, files) => {
  63.  
  64. if(err) console.log(err);
  65. let jsfile = files.filter(f => f.split(".").pop() === "js");
  66. if(jsfile.length <= 0){
  67. console.log("Couldn't find commands.");
  68. return;
  69. }
  70. //***********************************************************************************************************************************************
  71. jsfile.forEach((f, i) =>{
  72. let props = require(`./commands/${f}`);
  73. console.log(`${f} loaded!`);
  74. bot.commands.set(props.help.name, props);
  75. });
  76. });
  77. //***********************************************************************************************************************************************
  78. //START OF ACTUAL BOT
  79. //***********************************************************************************************************************************************
  80. bot.on("ready", async () => {
  81.  
  82. console.log(`${bot.user.username} is online on ${bot.guilds.size} servers!`);
  83. bot.user.setActivity("YeDankDimers", {type: "WATCHING"});
  84.  
  85. });
  86. //***********************************************************************************************************************************************
  87. bot.on("message", async message => {
  88.  
  89. if(message.author.bot) return;
  90. if(message.channel.type === "dm") return;
  91.  
  92. let prefixes = JSON.parse(fs.readFileSync("./prefix.json", "utf8"));
  93. if(!prefixes[message.guild.id]){
  94. prefixes[message.guild.id] = {
  95. prefixes: botconfig.prefix
  96. };
  97. }
  98. //***********************************************************************************************************************************************
  99. //Beginning of coin system
  100. //***********************************************************************************************************************************************
  101. if(!coins[message.author.id]){
  102. coins[message.author.id] = {
  103. coins: 0
  104. };
  105. }
  106.  
  107. let coinAmt = Math.floor(Math.random() * 15) + 1;
  108. let baseAmt = Math.floor(Math.random() * 15) + 1;
  109. console.log(`${coinAmt} ; ${baseAmt}`);
  110.  
  111. if(coinAmt === baseAmt){
  112. coins[message.author.id] = {
  113. coins: coins[message.author.id].coins + coinAmt
  114. };
  115. fs.writeFile("./coins.json", JSON.stringify(coins), (err) => {
  116. if (err) console.log(err)
  117. });
  118. let coinEmbed = new Discord.RichEmbed()
  119. .setAuthor(message.author.username)
  120. .setColor("#0000FF")
  121. .addField("💸", `${coinAmt} coins added!`);
  122.  
  123. message.channel.send(coinEmbed).then(msg => {msg.delete(5000)});
  124. }
  125. //***********************************************************************************************************************************************
  126. //End of coin system
  127. //===============================================================================================================================================
  128. //Beginning of XP system
  129. //***********************************************************************************************************************************************
  130. let xpAdd = Math.floor(Math.random() * 7) + 8;
  131. console.log(xpAdd);
  132.  
  133. if(!xp[message.author.id]){
  134. xp[message.author.id] = {
  135. xp: 0,
  136. level: 1
  137. };
  138. }
  139.  
  140.  
  141. let curxp = xp[message.author.id].xp;
  142. let curlvl = xp[message.author.id].level;
  143. let nxtLvl = xp[message.author.id].level * 300;
  144. xp[message.author.id].xp = curxp + xpAdd;
  145. if(nxtLvl <= xp[message.author.id].xp){
  146. xp[message.author.id].level = curlvl + 1;
  147. let lvlup = new Discord.RichEmbed()
  148. .setTitle("Level Up!")
  149. .setColor(purple)
  150. .addField("New Level", curlvl + 1);
  151.  
  152. message.channel.send(lvlup).then(msg => {msg.delete(5000)});
  153. }
  154. fs.writeFile("./xp.json", JSON.stringify(xp), (err) => {
  155. if(err) console.log(err)
  156. });
  157. //***********************************************************************************************************************************************
  158. //End of XP system
  159. //===============================================================================================================================================
  160. //Beginning of cooldown system
  161. //***********************************************************************************************************************************************
  162. let prefix = prefixes[message.guild.id].prefixes;
  163. if(!message.content.startsWith(prefix)) return;
  164. if(cooldown.has(message.author.id)){
  165. message.delete();
  166. return message.reply("You have to wait 5 seconds between commands.")
  167. }
  168. if(!message.member.hasPermission("ADMINISTRATOR")){
  169. cooldown.add(message.author.id);
  170. }
  171. //***********************************************************************************************************************************************
  172. //End of cooldown system
  173. //===============================================================================================================================================
  174. //Beginning of command handler
  175. //***********************************************************************************************************************************************
  176. let messageArray = message.content.split(" ");
  177. let cmd = messageArray[0];
  178. let args = messageArray.slice(1);
  179.  
  180. let commandfile = bot.commands.get(cmd.slice(prefix.length));
  181. if(commandfile) commandfile.run(bot,message,args);
  182.  
  183. setTimeout(() => {
  184. cooldown.delete(message.author.id)
  185. }, cdseconds * 1000)
  186. //***********************************************************************************************************************************************
  187. //End of command handler
  188. //===============================================================================================================================================
  189. bot.login(process.env.BOT_TOKEN)
  190. //End of index.js
  191. //***********************************************************************************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement