Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require("discord.js");
- const bot = new Discord.Client({ disableEveryone: false });
- const ms = require("ms");
- const fs = require("fs");
- const botconfig = require("./botconfig.json")
- const mysql = require("mysql");
- var con = mysql.createConnection({
- host: "us-cdbr-iron-east-03.cleardb.net",
- user: "be38026c850bbb",
- password: "531f44ee",
- database: "heroku_13e939244c494b2"
- });
- con.connect(function () {
- console.log("Connected to database")
- con.query("SHOW TABLES", console.log)
- setInterval(() => {
- con.query("select 1");
- }, 45000);
- })
- const active = new Map();
- bot.commands = new Discord.Collection();
- bot.aliases = new Discord.Collection();
- function loadCmds() {
- fs.readdir("./commands/", (err, files) => {
- if (err) console.log(err);
- let jsfile = files.filter(f => f.split(".").pop() === "js")
- if (jsfile.length <= 0) {
- console.log("couldn't find commands,")
- return;
- }
- jsfile.forEach((f, i) => {
- delete require.cache[require.resolve(`./commands/${f}`)];
- let props = require(`./commands/${f}`);
- console.log(`${f} loaded!`);
- if (props.help && props.help.name) {
- bot.commands.set(props.help.name, props);
- props.help.aliases.forEach(alias => {
- bot.aliases.set(alias, props.help.name)
- })
- }
- })
- })
- }
- bot.on(`ready`, () => {
- console.log(`Logged in as ${bot.user.tag}!`);
- bot.user.setStatus("online")
- });
- loadCmds();
- bot.on("message", async message => {
- let prefix = `$`
- let messageArray = message.content.split(" ");
- let cmd = messageArray[0].toLowerCase()
- let args = messageArray.slice(1);
- if (!message.content.startsWith(prefix)) return;
- let commandfile = bot.commands.get(cmd.slice(prefix.length)) || bot.commands.get(bot.aliases.get(prefix.length));
- if (commandfile) commandfile.run(bot, message, args);
- function generatePoints() {
- return Math.floor(Math.random() * 1 - 0 + 1) + 0
- }
- con.query(`insert ignore into points(id, points) values("${message.author.id}", 0)`)
- if(cmd === `${prefix}gmovie`) {
- const items = require("./questions.json");
- const item = items[[Math.floor(Math.random() * items.length)]];
- const filter = response => { // في هذا السطر يقوم بصنع فلتر للأجوبة
- return item.answers.some(answer => answer.toLowerCase() === response.content.toLowerCase());
- };
- message.channel.send('**Type the name of the character within 10 seconds**').then(message => {
- let embed = new Discord.RichEmbed()
- .setColor('#109ae2')
- .setFooter(`${item.movie}`)
- .setDescription(`**Guess the name of the character**`)
- .setImage(`${item.type}`)
- message.channel.send(embed).then(() => {
- message.channel.awaitMessages(filter, { maxMatches: 1, time: 10000, errors: ['time'] })
- .then((collected) => {
- message.channel.send(`${collected.first().author} **Correct answer** ✅`);
- console.log(`[Typing] ${collected.first().author} typed the word.`);
- let won = collected.first().author; // في هذا السطر يقوم الكود بسحب الأي دي الذي قام بالأجابة اولاً
- con.query(`UPDATE points SET points = points + ${generatePoints()} WHERE id = "${won.id}"`)
- }).catch(collected => { // في حال لم يقم أحد بالإجابة
- message.channel.send(`**Time ended and nobody wrote the name of the character**:x:`);
- console.log(`[Typing] Error: No one type the word.`);
- })
- })
- })
- }
- if(cmd === `${prefix}gpoints`) {
- let target = message.guild.member(message.mentions.users.first() || message.author);
- con.query(`SELECT * FROM points WHERE id = '${target.id}'`, (err, rows) => {
- if (!rows[0]) return message.channel.send("No points registered")
- let points = rows[0].points;
- if(target) {
- var embedd = new Discord.RichEmbed()
- .setColor('#109ae2')
- .setFooter("BrixMC | قسم الافلام والمسلسلات")
- .setDescription(`**${target} has ${points} points**`)
- message.channel.send(embedd)
- }else {
- let embedddd = new Discord.RichEmbed()
- .setColor('#109ae2')
- .setFooter("BrixMC | قسم الافلام والمسلسلات")
- .setDescription(`**You have ${points} points**`)
- message.channel.send(embedddd)
- }
- });
- }
- })
- bot.login(botconfig.token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement