Advertisement
ComputerMan123

HouseBot Code

Nov 25th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const yt = require("ytdl-core");
  3. const http = require("http");
  4. const os = require("os");
  5.  
  6. const bot = new Discord.Client();
  7.  
  8. const mamajokes = [ // Some amazing yo mama jokes
  9.                    "Yo mama so fat she left the house in high heels and when she came back she had on flip flops.",
  10.                    "Yo mama so fat she sat on an iPhone and turned it into an iPad",
  11.                    "Yo mama so fat she went to KFC to get a bucket of chicken they asked her what size and she said the one on the roof",
  12.                    "Yo momma so fat she sued xbox 360 for guessing her weight",
  13.                    "yo mama so fat that she dont need the internet she's already world wide",
  14.                    "Yo mama so fat that I ran out of gas trying to drive around her."
  15. ]
  16. const knockjokes = [ // Knock Knock Jokes
  17.                     "Test"
  18. ]
  19.  
  20. const square = [
  21.    "|----------------|",
  22.    "|                |",
  23.    "|                |",
  24.    "|                |",
  25.    "|                |",
  26.    "|                |",
  27.    "|________________|"
  28. ]
  29. const prefix = '>>'; // Prefix for commands, you can change this
  30. const token = 'Token'; // Token to login to bot goes here
  31. const annouce_channel = ""
  32.  
  33.  
  34.  
  35. // HouseBot by houseofkraft
  36. // This is a basic bot using discord.js
  37. // If you copy this bot, Please give me credit
  38.  
  39.  
  40.  
  41. bot.on("ready", () => { // Executes the code below when the bot is ready for use
  42.     bot.user.setStatus("online", "HouseBot | >>help");
  43.     console.log("Ready!");
  44. });
  45.  
  46.  
  47.  
  48. bot.on("message", message => {  // Executes all the code below when a user sends a message
  49.  
  50. // Functions
  51. function checkPerm(member, perm) {
  52.     if( message.member.roles.filter(r=>r.hasPermission(perm)).size > 0) {
  53.         return true
  54.         // Returns True
  55.     }
  56.     else {
  57.             return false
  58.         // Returns False
  59.     }
  60. }  
  61.  
  62. function toGB(data) {
  63.   output = data / 1073741824  
  64.   output = output.toFixed(1)
  65.   return output
  66. }
  67.  
  68. // Making HTTP Callback
  69. callback = function(response) {
  70.   var str = '';
  71.  
  72.   //another chunk of data has been recieved, so append it to `str`
  73.   response.on('data', function (chunk) {
  74.     str += chunk;
  75.   });
  76.  
  77.   //the whole response has been recieved, so we just print it out here
  78.   response.on('end', function () {
  79.     message.channel.sendMessage(str)
  80.   });
  81. }
  82.  
  83.  
  84. function play(url) { // A little broken at the moment
  85. const ytdl = require('ytdl-core');
  86. const streamOptions = { seek: 0, volume: 1 };
  87.    const stream = ytdl(url, {filter : 'audioonly'});
  88.    const dispatcher = connection.playStream(stream, streamOptions);
  89. }
  90.  
  91. // Commands
  92. if (message.content.startsWith(prefix + "about"))  message.channel.sendMessage("HouseBot made by houseofkraft");  
  93. if (message.content.startsWith(prefix + "help"))  {
  94.   message.author.sendMessage("HouseBot Help \n```Commands:\n help - Get's help for commands.\n ping - Pong!\n about - Show's who made this bot.\n logo - HouseBot logo\n winlogo - Windows logo\n invite - Tell's you the link to invite HouseBot to other Discord Servers\n isadmin - Says if your an admin (admin perm) or not\n say <message> - Says a message\n kick <person> - Kick's the person (Admins Only) \n ban <person> - Ban's the person (Admins only) \n music_join - Makes the bot join the voice channel \n music_leave - Makes the bot leave the voice channel \n roll - Roll's the dice! \n yomama - Yo mama jokes!\n servers - Tells you how much servers HouseBot is on \n square - Makes a square \n stats - Stat's about the server HouseBot is running on \n github - Github Information \nBy houseofkraft``` \n Version: V2.1.0");
  95.   message.channel.sendMessage(message.author + " I just sent you a PM with the help contents")
  96. }
  97. if (message.content.startsWith(prefix + "logo"))  message.channel.sendFile("http://i.imgur.com/yy4aG6o.png");
  98. if (message.content.startsWith(prefix + "winlogo")) message.channel.sendFile("http://i.imgur.com/Gy2aISn.png");
  99. if (message.content === "<@236597190611566602> Hi")  message.channel.sendMessage("Hi, " + message.author);
  100. if (message.content === "<@236597190611566602> hi")  message.channel.sendMessage("Hi, " + message.author);
  101. if (message.content === "<@236597190611566602>")  message.channel.sendMessage("Wat?");
  102. if (message.content.startsWith(prefix + "invite"))  message.author.sendMessage("You can invite the bot to other servers by using this link: https://discordapp.com/oauth2/authorize?client_id=236597190611566602&scope=bot&permissions=101378");
  103. if (message.content.startsWith(prefix + "isadmin")) message.channel.sendMessage("Admin: " + checkPerm(message.author, "ADMINISTRATOR")); // Mostly for checking if the permission checking works, comment this cmd out to disable
  104. if (message.content.startsWith(prefix + "uptime")) message.channel.sendMessage("Uptime: " + (process.uptime() /60).toFixed(0) + " minute(s)")
  105. //if (message.content.startsWith(prefix + "wipeall")) {
  106. //   let args = message.content.split(" ").slice(1);
  107. //   message.channel.sendMessage("Purging " + totalmsgs.length + " messages...");
  108. //   message.channel.bulkDelete(totalmsgs);
  109. //   message.channel.sendMessage("Purged " + totalmsgs.length + " messages.");  
  110. //}
  111. if (message.content.startsWith(prefix + "say")) {
  112.     var user = message.author;
  113.     let saytext = message.content.split(" ").slice(1);
  114.     message.delete();
  115.      message.channel.sendMessage(saytext);
  116. }
  117.  
  118. if (message.content.startsWith(prefix + "kick")) { // Admin Command
  119.      let userToKick = message.mentions.users.first();
  120.      if (checkPerm(message.author, "KICK_MEMBERS") === true) {
  121.       if (checkPerm(userToKick, "ADMINISTRATOR") === true) {
  122.           message.channel.sendMessage("You cannot kick admins!");
  123.       }
  124.       else {
  125.           message.guild.member(userToKick).kick();
  126.           message.channel.sendMessage("Kicked " + userToKick + " by " + message.author);
  127.       }
  128.   };
  129. }
  130.  
  131. if (message.content.startsWith(prefix + "github")) {
  132.   message.channel.sendMessage("Github: https://github.com/CoolMan119/HouseBot")
  133. }
  134.  
  135. //if (message.content.startsWith(prefix + "ban")) {
  136. //  if (checkPerm(message.author, "KICK_MEMBERS")) {
  137. //    if (checkPerm(bot.self, "KICK_MEMBERS")) {
  138. //      message.guild.member(userToKick).ban();
  139. //      message.channel.sendMessage("Banned " + userToKick + " by " + message.author);
  140. //     } else {
  141. //      message.channel.sendMessage("I don't have permission to kick users!")
  142. //    }
  143. //   else {
  144. //    message.channel.sendMessage("You don't have permission!")
  145. //  }
  146. //}
  147.  
  148.  
  149. if (message.content.startsWith(prefix + "music_join")) { // Music Module
  150.   const voiceChannel = message.member.voiceChannel;
  151.   if (!voiceChannel || voiceChannel.type !== 'voice') {
  152.       message.channel.sendMessage(":warning: You are not in a voice channel")
  153.   }
  154.   else {
  155.       message.channel.sendMessage(":white_check_mark: Sucessfully joined " + voiceChannel);
  156.       voiceChannel.join().then(connection => resolve(connection)).catch(err => reject(err));
  157.   }
  158.    if (message.guild.voiceConnection === "") {
  159.        message.channel.sendMessage(":warning: Your voice channel either reached the max people allowed or is locked")
  160.    }
  161.    
  162. }
  163.  
  164. if (message.content.startsWith(prefix + "music_leave")) {
  165.   const voiceChannel = message.member.voiceChannel;
  166.   voiceChannel.leave()
  167.   message.channel.sendMessage(":white_check_mark: Sucessfully left " + voiceChannel);
  168.  
  169. }
  170.  
  171. if (message.content.startsWith(prefix + "play")) { // Don't get this confused with the play function, this just activates the play function
  172.     //let args = message.content.split(" ").slice(1);
  173.     //let song = args[0];
  174.   message.channel.sendMessage("Sorry, The play function is not working!")
  175. }
  176.  
  177. if (message.content.startsWith(prefix + "roll")) {
  178.     var roll = Math.floor(Math.random() * 4) + 1
  179.     if (roll === 1) {
  180.         return message.channel.sendMessage(":one:");
  181.     }
  182.     if (roll === 2) {
  183.         return message.channel.sendMessage(":two:");
  184.     }
  185.     if (roll === 3) {
  186.         return message.channel.sendMessage(":three:");
  187.     }
  188.     if (roll === 4) {
  189.         return message.channel.sendMessage(":four:");
  190.     }
  191.  
  192. }
  193.  
  194. if (message.content.startsWith(prefix + "yomama")) {
  195.      var joke = Math.floor(Math.random() * mamajokes.length) + 1
  196.    message.channel.sendMessage(mamajokes[joke])  
  197. }
  198.  
  199. if (message.content.startsWith(prefix + "knockknock")) {
  200.   var joke = Math.floor(Math.random() * knockjokes.length) + 1
  201.   message.channel.sendMessage("Knock Knock\n" + knockjokes[joke])
  202. }
  203.  
  204. if (message.content.startsWith(prefix + "stats")) {
  205.   //message.channel.sendMessage("HouseBot is on **" + bot.guilds.size + "** servers, monitoring **" + bot.channels.size + "** channels.");  
  206.   message.channel.sendMessage("```\nHouseBot Stats\nServers: " + bot.guilds.size + "\nChannels: " + bot.channels.size + "\nUsers: " + bot.users.size + "\nFree Memory: " + toGB(os.freemem()) + "/" + toGB(os.totalmem()) + "GB\n```")
  207. }
  208.  
  209. if (message.content.startsWith(prefix + "crash")) {
  210.  message.channel.sendMessage("And do you really think i would let you?")
  211. }
  212.  
  213. if (message.content.startsWith(prefix + "pastebin-get")) {
  214.   let args = message.content.split(" ").slice(1)
  215.   var input = args[0]
  216.   var options = {
  217.     host: 'www.pastebin.com',
  218.     path: '/raw.php?i=' + input
  219.   };
  220.   http.request(options, callback).end();
  221.   //message.channel.sendMessage(str)
  222. }
  223.  
  224. if (message.content.startsWith(prefix + "square")) {
  225.   square.forEach(function (i, index, array) {
  226.   message.channel.sendMessage(i)
  227. });
  228. }
  229.  
  230.  
  231.      
  232. });
  233. bot.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement