Facebook
From IkBenBlind, 7 Months ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 90
  1. const BananenBase = require("bananenbase");
  2. const discord = require("discord.js");
  3. const moment = require("moment");
  4.  
  5. new BananenBase({
  6.   token: "NTQ5NTQ3MDM5NDk1NTUzMDI3.XKuBAw.CKR8Fd6NzM4sVa7X2QRw0TszIXk",
  7.   keepTrackOfDatabase: true,
  8.   database: {
  9.     package: "keyv",
  10.     type: "sqlite",
  11.     code: `${process.cwd()}/database.sqlite`
  12.   },
  13.   permissionLevels: [
  14.     (client, message, args) => { // Permission level 0
  15.       return true;
  16.     }, (client, message, args) => { // Permission level 1
  17.       if (message.member.roles.some(r => ["Giveaway", "giveaway"].includes(r.name))) return true;
  18.       return false;
  19.     }, (client, message, args) => { // Permission level 2
  20.       if (client.config.botOwners.includes(message.author.id)) return true; // A bot owner
  21.       else return false; // No bot owner
  22.     }
  23.   ],
  24.   ignore: {
  25.     pm: true
  26.   },
  27.   botConfig: {
  28.     authorSettings: {},
  29.     guildSettings: {
  30.       embed: {
  31.         color: "#34363c",
  32.         footerText: "© ZeuvenCode || order",
  33.         time: true
  34.       },
  35.       prefix: "."
  36.     }
  37.   },
  38.   language: "NL",
  39.  
  40.   bot: (client) => {
  41.     setInterval(async () => {
  42.       let giveaways = await client.db.get("giveaways");
  43.       if (!giveaways) giveaways = [];
  44.       let newGiveaways = [];
  45.       let count = 0;
  46.       await giveaways.forEach(async (giveaway) => {
  47.         let channel = client.channels.find(c => c.id === giveaway.channel.id);
  48.         if (!channel) {
  49.           count++;
  50.           newGiveaways.push(giveaway);
  51.           return;
  52.         }
  53.         let msg = await channel.fetchMessage(giveaway.msg);
  54.         if (!msg) {
  55.           count++;
  56.           newGiveaways.push(giveaway);
  57.           return;
  58.         }
  59.         if (giveaway.endsOn < Date.now()) {
  60.           if (giveaway.done) {
  61.             count++;
  62.             newGiveaways.push(giveaway);
  63.             return;
  64.           }
  65.           if (giveaway.mensenDieMeedoen.length === 0) return msg.edit(new discord.RichEmbed()
  66.             .setTitle(giveaway.titel)
  67.             .setColor("#ff0000")
  68.             .setDescription(`Niemand heeft gewonnen, want niemand deed mee!`)
  69.           );
  70.           let winnaars = [];
  71.           for (let i = 0; i < giveaway.winnaars; i++) {
  72.             let w = giveaway.mensenDieMeedoen[Math.floor(Math.random() * giveaway.mensenDieMeedoen.length)];
  73.             if (!winnaars.includes(w)) winnaars.push(w);
  74.           }
  75.           channel.send(new discord.RichEmbed()
  76.             .setTitle(giveaway.titel)
  77.             .setColor("RANDOM")
  78.             .setDescription(`De winnaars zijn: **<@${winnaars.join(">**, **<@")}>**`)
  79.           );
  80.           await msg.edit(new discord.RichEmbed()
  81.             .setTitle(`? ${giveaway.titel} ?`)
  82.             .setColor("#ff0000")
  83.             .setDescription(`${giveaway.beschrijving}\nWinnaars: **<@${winnaars.join(">**, **<@")}>**\nGiveaway is geĂ«indigd!`)
  84.             .setFooter(`Door ${giveaway.author.username}. GeĂ«indigd op `)
  85.             .setTimestamp()
  86.           );
  87.           giveaway.done = true;
  88.           if (giveaway.role) {
  89.             let guild = client.guilds.find(g => g.id === giveaway.guild.id);
  90.             let role = guild.roles.find(r => r.name === giveaway.role);
  91.             winnaars.forEach(winnaar => {
  92.               let member = guild.members.find(m => m.id === winnaar);
  93.               try {
  94.                 member.addRole(role);
  95.                 member.user.send(new discord.RichEmbed()
  96.                   .setTitle("Gefeliciteerd!")
  97.                   .setColor("RANDOM")
  98.                   .setDescription(`Je hebt de giveaway **${giveaway.titel}** gewonnen op **${giveaway.guild.name}**! Daarom heb je de rol **${giveaway.role}** ontvangen! Gefeliciteerd!`)
  99.                 );
  100.               } catch(e) {}
  101.             });
  102.           }
  103.           newGiveaways.push(giveaway);
  104.           count++;
  105.           return;
  106.         }
  107.  
  108.         msg.edit(new discord.RichEmbed()
  109.           .setTitle(`? ${giveaway.titel} ?`)
  110.           .setColor("RANDOM")
  111.           .setDescription(`${giveaway.beschrijving}\nWinnaars: **${giveaway.winnaars}**\nGiveaway eindigd **${moment(giveaway.endsOn).fromNow()}**`)
  112.           .setFooter(`Door ${giveaway.author.username}. Actief tot `)
  113.           .setTimestamp(giveaway.endsOn)
  114.         );
  115.  
  116.         newGiveaways.push(giveaway);
  117.         count++;
  118.       });
  119.       let interval = setInterval(async () => {
  120.         if (count === giveaways.length) {
  121.           clearInterval(interval);
  122.           await client.db.set("giveaways", newGiveaways);
  123.         }
  124.       });
  125.     }, 10000);
  126.   }
  127. });
  128.