Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. const { CommandoClient } = require('discord.js-commando');
  2. const mysql = require("mysql");
  3. const token = require("./token.json");
  4. let coins = require("./coins.json");
  5.  
  6. const client = new CommandoClient({
  7. commandPrefix: '~',
  8. owner: '142764278582214656',
  9. });
  10.  
  11. var con = mysql.createConnection({
  12. host: "localhost",
  13. user: "root",
  14. password: "-",
  15. database: "-"
  16. });
  17.  
  18. con.connect(err => {
  19. if(err) throw err;
  20. console.log("I'm connected to the database! ~")
  21. con.query("SHOW TABLES");
  22. });
  23.  
  24. client.registry.registerGroup('random');
  25. client.registry.registerGroup('advertising');
  26. client.registry.registerGroup('other');
  27. client.registry.registerGroup('xp');
  28. client.registry.registerDefaults();
  29. client.registry.registerCommandsIn(__dirname + "/commands")
  30.  
  31. client.on('ready', () => {
  32. console.log('Im online! ~')
  33. client.user.setActivity('Reciting the vitamin hymns.');
  34. });
  35.  
  36. function generateXp() {
  37. let min = 1;
  38. let max = 1;
  39. return Math.floor(Math.random() * (max - min + 1)) + min;
  40. }
  41.  
  42. client.on("message", async message => {
  43. if(message.author.bot) return;
  44. if(message.channel.type === "dm") return;
  45.  
  46. if(!coins[message.author.id]){
  47. coins[message.author.id] = {
  48. coins: 0
  49. };
  50. }
  51.  
  52. let coinAmt = Math.floor(Math.random() * 1) + 1;
  53. let baseAmt = Math.floor(Math.random() * 1) + 1;
  54. console.log(`${coinAmt} ; ${baseAmt}`);
  55.  
  56. if(coinAmt === baseAmt){
  57. coins[message.author.id] = {
  58. coins: coins[message.author.id].coins + coinAmt
  59. };
  60.  
  61. fs.writeFile("./coins.json", JSON.stringify(coins), (err) => {
  62. if (err) console.log(err)
  63. });
  64. }
  65.  
  66. con.query(`SELECT * FROM xp WHERE id = '${message.author.id}'`, (err,rows) => {
  67. if(err) throw err;
  68.  
  69. let sql;
  70.  
  71. if(rows.length < 1) {
  72. sql = `INSERT INTO xp (id, xp) VALUES ('${message.author.id}', ${generateXp()})`;
  73. } else {
  74. let xp = rows[0].xp;
  75. sql = `UPDATE xp SET xp = ${xp + generateXp()} WHERE id = '${message.author.id}'`;
  76. }
  77. con.query(sql)
  78. })
  79. });
  80.  
  81. client.login(token.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement