Advertisement
DayDun

Kunskapsbotten

Apr 9th, 2018
2,857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require("fs");
  2.  
  3. const Discord = require("discord.js");
  4. const discord = new Discord.Client();
  5.  
  6. const secret = JSON.parse(fs.readFileSync("secret.json"));
  7.  
  8. // TODO: Embed menu api
  9.  
  10. const PREFIX = "kp!";
  11. const COLOR = 0x2c9ff7;
  12. const MENU_LIFETIME = 4;
  13.  
  14. let menus = [];
  15.  
  16. class Menu {
  17.     constructor() {
  18.        
  19.     }
  20. }
  21.  
  22. class PageMenu {
  23.     constructor(user) {
  24.         this.user = user;
  25.     }
  26. }
  27.  
  28. const roles = {
  29.     "432939088711254037": { // Moderator
  30.         commands: ["help", "eval"]
  31.     },
  32.     "431418564755456000": { // @everyone
  33.         commands: ["help"]
  34.     }
  35. };
  36.  
  37. const commands = {
  38.     "help": {
  39.         usage: "help (<command>)",
  40.         description: "Shows a list of all commands and tells you more information about a specific command",
  41.         use: function(args, message) {
  42.             if (args.length === 0) {
  43.                 message.channel.send(new Discord.RichEmbed({
  44.                     title: "Kunskapsbotten Help",
  45.                     color: COLOR,
  46.                     fields: [
  47.                         {
  48.                             name: "Info",
  49.                             value: "Kunskapsbotten är en bot."
  50.                         },
  51.                         {
  52.                             name: "Användning",
  53.                             value: "Använd pilknapparna för att navigera menyer som denna.\n:1234: Knappen låter dig hoppa till ett specifierat sidnummer.\n:eject: Knappen stänger menyn"
  54.                         }
  55.                     ],
  56.                     footer: {
  57.                         text: "Sida 1 av mom gay"
  58.                     }
  59.                 })).then(async function(message) {
  60.                     await message.react("⏮");
  61.                     await message.react("⬅");
  62.                     await message.react("➡");
  63.                     await message.react("⏭");
  64.                     await message.react("🔢");
  65.                     await message.react("⏏");
  66.                 });
  67.             } else if (args[0].toLowerCase() in commands) {
  68.                 let command = args[0].toLowerCase();
  69.                 message.channel.send(new Discord.RichEmbed({
  70.                     title: command,
  71.                     color: COLOR,
  72.                     description: commands[command].description,
  73.                     fields: [
  74.                         {
  75.                             name: "Använding: " + commands[command].usage,
  76.                             value: ""
  77.                         }
  78.                     ],
  79.                     footer: {
  80.                         text: "Kategori: Info"
  81.                     }
  82.                 }));
  83.             }
  84.             return true;
  85.         }
  86.     },
  87.     "eval": {
  88.         usage: "eval <javascript>",
  89.         description: "Run a piece of code on the server.",
  90.         use: function(args, message) {
  91.             if (args.length === 0) {
  92.                 return false;
  93.             } else {
  94.                 let result;
  95.                 try {
  96.                     result = eval(args.join(" "));
  97.                 } catch(e) {
  98.                     message.channel.send(e.toString());
  99.                     return true;
  100.                 }
  101.                 // Idk if this is equivalent to just JSON.stringify lol.
  102.                 if (typeof result == "undefined") {
  103.                     message.channel.send("`undefined`");
  104.                 } else if (typeof result == "number") {
  105.                     message.channel.send("`" + result + "`");
  106.                 } else if (typeof result == "string") {
  107.                     message.channel.send("`\"" + result + "\"`");
  108.                 } else if (Array.isArray(result)) {
  109.                     message.channel.send("`" + JSON.stringify(result) + "`");
  110.                 } else {
  111.                     message.channel.send("`" + result.toString() + "`");
  112.                 }
  113.                 return true;
  114.             }
  115.         }
  116.     }
  117. };
  118.  
  119. discord.on("ready", function() {
  120.     console.log("Ready");
  121. });
  122.  
  123. discord.on("message", function(message) {
  124.     if (message.author.bot) {
  125.         return;
  126.     }
  127.    
  128.     if (message.content.startsWith(PREFIX)) {
  129.         let content = message.content.slice(PREFIX.length).split(" ");
  130.         let command = content[0].toLowerCase();
  131.         if (command in commands) {
  132.             let canUse = false;
  133.             let rolesArray = message.member.roles.array();
  134.             let permission = message.member.roles.some(function(role) {
  135.                 return (role.id in roles) && roles[role.id].commands.includes(command);
  136.             });
  137.            
  138.             if (permission) {
  139.                 let result = commands[command].use(content.slice(1), message);
  140.                 if (!result) {
  141.                     message.channel.send("**:x: " + command + " usage:** `" + commands[command].usage + "`");
  142.                 }
  143.             } else {
  144.                 message.channel.send(":x: You don't have permission to use this command!");
  145.             }
  146.         }
  147.         // Don't send an error message if the command doesn't exist.
  148.     }
  149. });
  150. discord.on("messageReactionAdd", function(reaction, user) {
  151.    
  152. });
  153.  
  154. discord.login(secret.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement