Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Beep. Boop.
- const Discord = require('discord.js');
- const client = new Discord.Client;
- const ytdl = require('ytdl-core');
- const request = require('request');
- const fs = require('fs')
- const getYouTubeID = require('get-youtube-id');
- const fetchVideoInfo = require('youtube-info')
- const yt_api_key = config.yt_api_key;
- const bot_controller = config.bot_controller;
- var queue = [];
- var isPlaying = false;
- var dispatcher = null;
- var voiceChannel = null;
- var skipReq = 0;
- var skippers = [];
- function SetCurrentGame() {
- var presence = {};
- presence.game = {};
- presence.status = "online";
- presence.afk = false;
- //What's the bot playing?
- switch (Math.floor(Math.random() * 1000) % 31) {
- case 0:
- presence.game.name = "nothing rn";
- break;
- case 1:
- presence.game.name = "r!help";
- break;
- case 2:
- presence.game.name = "with ban buttons";
- break;
- case 3:
- presence.game.name = "around";
- break;
- case 4:
- presence.game.name = "annoying lolrepeatlol™";
- break;
- case 5:
- presence.game.name = "something obviously";
- break;
- case 6:
- presence.game.name = "with the world";
- break;
- case 7:
- presence.game.name = "a game";
- break;
- case 8:
- presence.game.name = "with code";
- break;
- case 9:
- presence.game.name = "r!help for info";
- break;
- case 10:
- presence.game.name = "something";
- break;
- case 11:
- presence.game.name = "a movie";
- break;
- case 12:
- presence.game.name = "with my creator";
- break;
- case 13:
- presence.game.name = "the waiting game";
- break;
- case 14:
- presence.game.name = "with a giraffe";
- break;
- case 15:
- presence.game.name = "with best bird";
- break;
- case 16:
- presence.game.name = "with best squid";
- break;
- case 17:
- presence.game.name = "with jason";
- break;
- case 18:
- presence.game.name = "with happy magnets";
- break;
- case 19:
- presence.game.name = "with soy sauce";
- break;
- case 20:
- presence.game.name = "c:";
- break;
- case 21:
- presence.game.name = "taking over the world";
- break;
- case 22: //this is the point where i run out of ideas
- presence.game.name = "with boredom";
- break;
- case 23:
- presence.game.name = "on steam";
- break;
- case 24:
- presence.game.name = "(or rather, eating chick-fil-a?)";
- break;
- case 25:
- presence.game.name = "(or rather, fooling around?)";
- break;
- case 26:
- presence.game.name = "(or rather, doing nothing?)"
- break;
- case 27:
- presence.game.name = "munzee";
- break;
- case 28:
- presence.game.name = "geocaching";
- break;
- case 29:
- presence.game.name = "chess";
- break;
- case 30:
- presence.game.name = "reeeeeeeeeeeeeeee";
- break;
- }
- client.user.setPresence(presence);
- }
- function isYouTube(str) {
- return str.toLowerCase().indexOf('youtube.com') > -1;
- }
- function search_video(query, callback) {
- request("https://www.googleapis.com/youtube/v3/search?part=id&type=video&q=" + encodeURIComponent(query) + "&key=" + yt_api_key, function(error, response, body) {
- var json = JSON.parse(body);
- callback(json.items[0].id.videoId);
- });
- }
- function getID(str, cb) {
- if (isYoutube(str)) {
- cb(getYouTubeID(str));
- } else {
- search_video(str, function(id) {
- cb(id);
- });
- }
- }
- function add_to_queue(strID) {
- if (isYouTube(strID)) {
- queue.push(getID(getYouTubeID(strID)));
- } else {
- queue.push(strID);
- }
- }
- function playMusic(id, message) {
- voiceChannel = message.member.voiceChannel;
- voiceChannel.join().then(function (connection) {
- stream = ytdl("https://youtube.com/watch?v=" + id, {
- filter: "audioonly"
- })
- skipReq = 0;
- skippers = [];
- dispatcher = connection.playStream(stream);
- });
- }
- //Holds the prefix and token
- const config = JSON.parse(fs.readFileSync('./config.json', 'utf-8'));
- //Motivates me when turning bot on I guess
- client.on('ready', () => {
- console.log('go. destroy. create.');
- client.setInterval(SetCurrentGame, 150000);
- SetCurrentGame();
- });
- //Greetings!
- client.on('guildMemberAdd', member => {
- let guild = member.guild;
- guild.defaultChannel.send(`oi ${member.user}! be sure to check out the rules! c:`);
- });
- //Notifies when a guild is added in cmd.
- client.on("guildCreate", guild => {
- console.log(`new server added, woop woop!
- name: ${guild.name}
- owner: ${guild.owner.user.username}
- keep on working! c:`);
- });
- client.on('message', message => {
- const ergs = message.content.split(" ").slice(1);
- if (message.author.bot) return;
- if (!message.content.startsWith(config.prefix)) return;
- //Prefix stuff
- let command = message.content.split(" ")[0];
- command = command.slice(config.prefix.length);
- let args = message.content.split(" ").slice(1);
- //Math + command
- if (command === 'add') {
- let numArray = args.map(n=> parseInt(n));
- let total = numArray.reduce( (p, c) => p+c);
- message.channel.send(total);
- }
- //Echo command
- if (command === 'say') {
- message.channel.send(args.join(" "));
- }
- //<3
- if (command === 'ping') {
- message.channel.send('pong! c;');
- }
- if (command === 'pong') {
- message.channel.send('ping.', `you're not that funny.`)
- }
- //Mod only easter-egg.
- if (command === `super`) {
- let modRole = message.guild.roles.find('name', 'moddi');
- if(message.member.roles.has(modRole.id)) {
- message.channel.send('secret c;');
- } else {
- message.reply(`bwahahaha you cant access the secrets of the ocean! ;p `);
- }
- }
- //Kick members.
- if (command === 'kick') {
- let modRole = message.guild.roles.find("name", "Mod");
- if (!message.member.roles.has(modRole.id)) {
- message.channel.send(`sorry, you don't have permission to do that.`);
- }
- if (message.mentions.users.size === 0) {
- return message.channel.send(`don't forget to mention the user you want to kick!`);
- }
- let kickMember = message.guild.member(message.mentions.users.first());
- if(!kickMember) {
- return message.channel.send('wait, who? try retyping the username.');
- }
- if(!message.guild.member(client.user).hasPermission('KICK_MEMBERS')) {
- return message.channel.send(`i don't have the permission to do that. go into server settings > roles > reBot and give me the "Kick Members" permission. then, drag me over the user you'd like to kick. c:`)
- }
- kickMember.kick();
- }
- //Ban members.
- if (command === `ban`) {
- let modRole = message.guild.roles.find("name", "Mod");
- if (!message.member.roles.has(modRole.id)) {
- message.channel.send(`sorry, you don't have permission to do that.`);
- }
- if (message.mentions.users.size === 0) {
- return message.channel.send(`don't forget to mention the user you want to ban!`);
- }
- let banMember = message.guild.member(message.mentions.users.first());
- if(!banMember) {
- return message.channel.send('wait, who? try retyping the username.');
- }
- if(!message.guild.member(client.user).hasPermission('BAN_MEMBERS')) {
- return message.channel.send(`i don't have the permission to do that. go into server settings > roles > reBot and give me the "Ban Members" permission. then, drag me over the user you'd like to ban. c:`)
- }
- banMember.ban().catch(console.error);
- }
- if (command === `help`) {
- message.channel.send(`__** HELP **__
- --*ping*
- ping *the bot*
- pong *the bot*
- --*moderation*
- ban *someone*
- kick *someone*
- --*music*`
- );
- }
- //addrole and removerole. temp
- let user = message.author;
- if (command === "updates") {
- let addedRole = message.guild.roles.find("name", "Updates");
- message.guild.member(user).addRole(addedRole).catch(console.error);
- }
- //music!
- //play command
- if (command === "play") {
- if (queue.length > 0 || isPlaying) {
- getID(args, function (id) {
- add_to_queue(id);
- fetchVideoInfo(id, function (err, videoInfo){
- if (err) throw new Error(err);
- message.channel.send(':white_check_mark:**' + videoInfo.title + '** *was just added to the queue.*')
- });
- });
- } else {
- isPlaying = true;
- getID(args, function (id) {
- queue.push('placeholder');
- playMusic(id, message);
- fetchVideoInfo(id, function (err, videoInfo){
- if (err) throw new Error(err);
- message.channel.send(':white_check_mark: *now playing:* **' + videoInfo.title + '**')
- });
- });
- }
- //The one and powerful eval command.
- if (command === 'eval') {
- if (message.author.id !== '271443182066204673') return;
- try {
- const code = args.join(" ");
- let evaled = eval(code);
- if (typeof evaled !== "string")
- evaled = require("util").inspect(evaled);
- message.channel.send(clean(evaled), {code:"xl"});
- } catch (err) {
- message.channel.send(`\`ERROR\` \`\`\`xl\n${clean(err)}\n\`\`\``);
- }
- }
- }
- function clean(text) {
- if (typeof(text) === "string")
- return text.replace (/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
- else {
- return text;
- }
- }
- //Told you so.
- client.login(config.token)
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement