Advertisement
Guest User

Untitled

a guest
Feb 13th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const bot = new Discord.Client({ disableEveryone: false });
  3. const ms = require("ms");
  4. const fs = require("fs");
  5. const botconfig = require("./botconfig.json")
  6. const mysql = require("mysql");
  7. var con = mysql.createConnection({
  8.   host: "us-cdbr-iron-east-03.cleardb.net",
  9.   user: "be38026c850bbb",
  10.   password: "531f44ee",
  11.   database: "heroku_13e939244c494b2"
  12. });
  13.  
  14. con.connect(function () {
  15.   console.log("Connected to database")
  16.   con.query("SHOW TABLES", console.log)
  17.   setInterval(() => {
  18.     con.query("select 1");
  19.   }, 45000);
  20. })
  21. const active = new Map();
  22. bot.commands = new Discord.Collection();
  23. bot.aliases = new Discord.Collection();
  24. function loadCmds() {
  25.   fs.readdir("./commands/", (err, files) => {
  26.     if (err) console.log(err);
  27.  
  28.     let jsfile = files.filter(f => f.split(".").pop() === "js")
  29.     if (jsfile.length <= 0) {
  30.       console.log("couldn't find commands,")
  31.       return;
  32.     }
  33.     jsfile.forEach((f, i) => {
  34.       delete require.cache[require.resolve(`./commands/${f}`)];
  35.       let props = require(`./commands/${f}`);
  36.       console.log(`${f} loaded!`);
  37.       if (props.help && props.help.name) {
  38.         bot.commands.set(props.help.name, props);
  39.         props.help.aliases.forEach(alias => {
  40.           bot.aliases.set(alias, props.help.name)
  41.         })
  42.       }
  43.     })
  44.   })
  45. }
  46.  
  47.  
  48. bot.on(`ready`, () => {
  49.   console.log(`Logged in as ${bot.user.tag}!`);
  50.   bot.user.setStatus("online")
  51. });
  52. loadCmds();
  53.  
  54. bot.on("message", async message => {
  55.  
  56.   let prefix = `$`
  57.   let messageArray = message.content.split(" ");
  58.   let cmd = messageArray[0].toLowerCase()
  59.   let args = messageArray.slice(1);
  60.   if (!message.content.startsWith(prefix)) return;
  61.   let commandfile = bot.commands.get(cmd.slice(prefix.length)) || bot.commands.get(bot.aliases.get(prefix.length));
  62.   if (commandfile) commandfile.run(bot, message, args);
  63.   function generatePoints() {
  64.     return Math.floor(Math.random() * 1 - 0 + 1) + 0
  65.   }
  66.   con.query(`insert ignore into points(id, points) values("${message.author.id}", 0)`)
  67.  
  68.   if(cmd === `${prefix}gmovie`) {
  69.     const items = require("./questions.json");
  70.     const item = items[[Math.floor(Math.random() * items.length)]];
  71.     const filter = response => { // في هذا السطر يقوم بصنع فلتر للأجوبة
  72.       return item.answers.some(answer => answer.toLowerCase() === response.content.toLowerCase());
  73.     };
  74.     message.channel.send('**Type the name of the character within 10 seconds**').then(message => {
  75.       let embed = new Discord.RichEmbed()
  76.         .setColor('#109ae2')
  77.         .setFooter(`${item.movie}`)
  78.         .setDescription(`**Guess the name of the character**`)
  79.         .setImage(`${item.type}`)
  80.       message.channel.send(embed).then(() => {
  81.         message.channel.awaitMessages(filter, { maxMatches: 1, time: 10000, errors: ['time'] })
  82.           .then((collected) => {
  83.             message.channel.send(`${collected.first().author} **Correct answer** ✅`);
  84.             console.log(`[Typing] ${collected.first().author} typed the word.`);
  85.             let won = collected.first().author; // في هذا السطر يقوم الكود بسحب الأي دي الذي قام بالأجابة اولاً
  86.             con.query(`UPDATE points SET points = points + ${generatePoints()} WHERE id = "${won.id}"`)
  87.           }).catch(collected => { // في حال لم يقم أحد بالإجابة
  88.             message.channel.send(`**Time ended and nobody wrote the name of the character**:x:`);
  89.             console.log(`[Typing] Error: No one type the word.`);
  90.           })
  91.       })
  92.     })
  93.   }
  94.  
  95.  
  96. if(cmd === `${prefix}gpoints`) {
  97.         let target = message.guild.member(message.mentions.users.first() || message.author);
  98.     con.query(`SELECT * FROM points WHERE id = '${target.id}'`, (err, rows) => {
  99.       if (!rows[0]) return message.channel.send("No points registered")
  100.       let points = rows[0].points;
  101.  
  102.       if(target) {
  103.       var embedd = new Discord.RichEmbed()
  104.         .setColor('#109ae2')
  105.         .setFooter("BrixMC | قسم الافلام والمسلسلات")
  106.         .setDescription(`**${target} has ${points} points**`)
  107.       message.channel.send(embedd)
  108.     }else {
  109.       let embedddd = new Discord.RichEmbed()
  110.       .setColor('#109ae2')
  111.       .setFooter("BrixMC | قسم الافلام والمسلسلات")
  112.       .setDescription(`**You have ${points} points**`)
  113.       message.channel.send(embedddd)
  114.   }
  115.     });
  116.   }
  117. })
  118. bot.login(botconfig.token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement