From bfe32fcce23a4ff6a922bdeb704ad31fcd57ff80 Mon Sep 17 00:00:00 2001 From: Blue Malgeran Date: Wed, 7 Mar 2018 14:37:04 +0200 Subject: [PATCH] oops, fixing bugs oops, fixing bugs --- index.js | 273 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 231 insertions(+), 42 deletions(-) diff --git a/index.js b/index.js index 7b7a05b..3c75e1d 100644 --- a/index.js +++ b/index.js @@ -20,35 +20,80 @@ var fortunes = [ // Functions when the bot is online client.on("ready", function() { - console.log("Bot connected to: " + client.user.username + "#" + client.user.discriminator); - console.log("The bot is in " + client.guilds.size + " servers."); + var clientonmessage = ` +------------------------------------------------------ +> Logging in... +------------------------------------------------------ +Logged in as ${client.user.tag} +Working on ${client.guilds.size} servers! +${client.channels.size} channels and ${client.users.size} users cached! +I am logged in and ready to roll! +LET'S GO! +------------------------------------------------------ +----------Bot created by Blue Malgeran#3106----------- +------------------------------------------------------ +-----------------Bot's commands logs------------------` + + console.log(clientonmessage); client.user.setGame( - "NotABot | BETA | http://BlueMalgeran.tk", + "NotABot | BETA | http://BlueMalgeran.com", "https://www.twitch.tv/BlueMalgeran" - ); + ); +}); + +// Logs of the bot joined a server +client.on("guildCreate", guild => { + console.log(`The bot just joined to ${guild.name}, Owned by ${guild.owner.user.tag}`); + + var guildMSG = guild.channels.find('name', 'general'); + + guildMSG.send(` +Hello there! My original name is \`NotABot\`!\n\ +This bot created by **Blue Malgeran#3106**\n\ +For more info type \`${settings.botPREFIX}help\`!`); +}); + +// Logs of the bot leaves a server +client.on("guildDelete", guild => { + console.log(`The bot has been left ${guild.name}, Owned by ${guild.owner.user.tag}`); }); // Message function -client.on("message", function(message, userID, channelID, user, event) { +client.on("message", async message => { if (message.author.equals(client.user)) return; if (!message.content.startsWith(settings.botPREFIX)) return; + //Disables commands in a private chat + if (message.channel.type == "dm") return console.log(`${message.author.tag} tried to use a command in DM!`); + + //Users blacklist + if (message.author.id == "") return console.log(`[BlackList] ${message.author.tag} tried to use a command!`); + + //Channels blacklist + if (message.channel.id == "") return; + + //Servers blacklist + if (message.guild.id == "") return; + var args = message.content.substring(settings.botPREFIX.length).split(" "); // Bot's commands from here. switch (args[0]) { case "ping": + console.log(`${message.author.tag} used the ${settings.botPREFIX}pong command!`); message.reply("Pong!"); break; case "botinfo": + console.log(`${message.author.tag} used the ${settings.botPREFIX}botinfo command!`); + message.channel.send({embed: { color: 3447003, title: "Info:", description: "This is the info about the bot", fields: [{ name: "Created by:", - value: "This bot created by [Blue Malgeran](http://BlueMalgeran.tk)" + value: "This bot created by [Blue Malgeran](http://BlueMalgeran.com)" }, { name: "Made with:", @@ -56,7 +101,7 @@ client.on("message", function(message, userID, channelID, user, event) { }, { name: "Contact me:", - value: "_**Blue Malgeran#5546**_" + value: "_**Blue Malgeran#3106**_" }, { name: "Social Media", @@ -77,11 +122,14 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "8ball": + console.log(`${message.author.tag} used the ${settings.botPREFIX}8ball command!`); + let question = message.content.split(' ').slice(1).join(' '); if (!question) { return message.reply('What question should I answer on?\n\**Usage:** `~8ball is Blue Malgeran is sexy af?`'); } + message.channel.send({embed: { color: 3447003, author: { @@ -103,6 +151,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "weather": + console.log(`${message.author.tag} used the ${settings.botPREFIX}botinfo command!`); + let apiKey = settings.weatherAPI; const fetch = require('node-fetch'); let arg = message.content.split(' ').join(' ').slice(8); @@ -125,7 +175,7 @@ client.on("message", function(message, userID, channelID, user, event) { const embed = new Discord.RichEmbed() .setColor(26368) .setTitle(`This is the weather for :flag_${json.sys.country.toLowerCase()}: **${json.name}**`) - .addField('Information:', `**Temp:** ${json.main.temp}°C\n**WindSpeed:** ${json.wind.speed}m/s\n**Humidity:** ${json.main.humidity}%\n**Sunrise:** ${timestr}\n**Sunset:** ${timesstr}`); + .addField('Information:', `**Temp:** ${json.main.temp}°C\n**Wind speed:** ${json.wind.speed}m/s\n**Humidity:** ${json.main.humidity}%\n**Sunrise:** ${timestr}\n**Sunset:** ${timesstr}`); message.channel.send({embed}) .catch(console.error); }).catch(err => { @@ -136,20 +186,25 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "invitebot": + console.log(`${message.author.tag} used the ${settings.botPREFIX}invitebot command!`); + message.reply("Okay, you can invite me here: https://discordapp.com/oauth2/authorize?client_id=" + client.user.id + "&scope=bot&permissions=0"); break; - + case "coinflip": + console.log(`${message.author.tag} used the ${settings.botPREFIX}coinflip command!`); + let answers = [ 'heads', 'tails' ]; + message.channel.send({embed: { color: 3447003, title: "Coinflip:", fields: [{ name: "Result", - value: "`" + `${answers[~~(Math.random() * answers.length)]}` + "`" + value: `\`${answers[~~(Math.random() * answers.length)]}\`` } ], timestamp: new Date(), @@ -162,6 +217,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "userinfo": + console.log(`${message.author.tag} used the ${settings.botPREFIX}userinfo command!`); + let user = message.mentions.users.first(); if (!user) { return message.reply('You must mention someone!'); @@ -214,7 +271,7 @@ client.on("message", function(message, userID, channelID, user, event) { }, fields: [{ name: '**UserInfo:**', - value: `**name:** ${user.username}#${user.discriminator}\n**JoinedDiscord:** ${joineddiscord}\n**LastMessage:** ${messag}\n**Playing:** ${game}\n**Status:** ${status}\n**Bot?** ${user.bot}` + value: `**Username:** ${user.tag}\n**Joined Discord:** ${joineddiscord}\n**Last message:** ${messag}\n**Playing:** ${game}\n**Status:** ${status}\n**Bot?** ${user.bot}` }, { name: 'DiscordInfo:', @@ -231,6 +288,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "avatar": + console.log(`${message.author.tag} used the ${settings.botPREFIX}avatar command!`); + if(message.mentions.users.first()) { //Check if the message has a mention in it. let user = message.mentions.users.first(); //Since message.mentions.users returns a collection; we must use the first() method to get the first in the collection. let output = user.username + "#" + user.discriminator /*Username and Discriminator*/ + @@ -242,6 +301,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "uptime": + console.log(`${message.author.tag} used the ${settings.botPREFIX}uptime command!`); + let ms = client.uptime; let cd = 24 * 60 * 60 * 1000; // Calc days let ch = 60 * 60 * 1000; // Calc hours @@ -267,31 +328,31 @@ client.on("message", function(message, userID, channelID, user, event) { hours = 0; } let dateStrings = []; - + if (days === 1) { dateStrings.push('**1** day'); } else if (days > 1) { dateStrings.push('**' + String(days) + '** days'); } - + if (hours === 1) { dateStrings.push('**1** hour'); } else if (hours > 1) { dateStrings.push('**' + String(hours) + '** hours'); } - + if (minutes === 1) { dateStrings.push('**1** minute'); } else if (minutes > 1) { dateStrings.push('**' + String(minutes) + '** minutes'); } - + if (seconds === 1) { dateStrings.push('**1** second'); } else if (seconds > 1) { dateStrings.push('**' + String(seconds) + '** seconds'); } - + let dateString = ''; for (let i = 0; i < dateStrings.length - 1; i++) { dateString += dateStrings[i]; @@ -328,6 +389,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "serverinfo": + console.log(`${message.author.tag} used the ${settings.botPREFIX}serverinfo command!`); + let guildmessageServerInfo = message.guild; let nameServerInfo = message.guild.name; let createdAtServerInfo = moment(message.guild.createdAt).format('MMMM Do YYYY, h:mm:ss a'); @@ -370,6 +433,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "botservers": + console.log(`${message.author.tag} used the ${settings.botPREFIX}botservers command!`); + let Table = require(`cli-table`); let table = new Table({ head: [ @@ -393,6 +458,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "botping": + console.log(`${message.author.tag} used the ${settings.botPREFIX}botping command!`); + message.reply({embed: { color: 3447003, author: { @@ -414,13 +481,15 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "ban": + console.log(`${message.author.tag} used the ${settings.botPREFIX}ban command!`); + const mmss = require('ms'); let reason = message.content.split(' ').slice(3).join(' '); let time = message.content.split(' ')[2]; let guild = message.guild; let modlog = message.guild.channels.find('name', 'mod-log'); let usermention = message.mentions.users.first(); - + if (!message.guild.member(message.author).hasPermission('BAN_MEMBERS')) { return message.reply(':lock: **You** need `BAN_MEMBERS` Permissions to execute `ban`') } @@ -440,7 +509,7 @@ client.on("message", function(message, userID, channelID, user, event) { if (message.author.id === usermention.id) { return message.reply('You cant punish yourself :wink:') } - + if (!time) { return message.reply(`How much time ? **Usage:**\`~ban [@mention] [1d] [example]\``) } @@ -452,7 +521,7 @@ client.on("message", function(message, userID, channelID, user, event) { if (!reason) { return message.reply(`You must give me a reason for the ban **Usage:**\`~ban [@mention] [1d] [example]\``) } - + if (!message.guild.member(usermention).bannable) { return message.reply('This member is above me in the `role chain` Can\'t ban them') } @@ -485,6 +554,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "kick": + console.log(`${message.author.tag} used the ${settings.botPREFIX}kick command!`); + if (!message.guild.member(message.author).hasPermission('KICK_MEMBERS')) { return message.reply(':lock: You dont have permissions for that') } @@ -531,15 +602,14 @@ client.on("message", function(message, userID, channelID, user, event) { }); break; - message.channel.send('This command is disabled by `Blue Malgeran#5546`'); - break; - case "mute": + console.log(`${message.author.tag} used the ${settings.botPREFIX}mute command!`); + if (!message.guild.member(message.author).hasPermission('MUTE_MEMBERS')) { message.channel.send(':lock: **I** need `MANAGE_ROLES` Permissions to execute `mute`'); return; } - + if (!message.guild.member(client.user).hasPermission('MANAGE_ROLES')) { return message.reply(':lock: **I** need `MANAGE_ROLES` Permissions to execute `mute`') } @@ -551,15 +621,15 @@ client.on("message", function(message, userID, channelID, user, event) { let memberMute = message.guild.member; let modlogMute = message.guild.channels.find('name', 'mod-log'); let userMute = message.mentions.users.first(); - let muteRoleMute = client.guilds.get(message.guild.id).roles.find('name', 'muted'); + let muteRoleMute = client.guilds.get(message.guild.id).roles.find('name', 'NotAMute'); if (!modlogMute) { return message.reply('I need a text channel named `mod-log` to print my ban/kick logs in, please create one'); } - + if (!muteRoleMute) { - return message.reply('`Please create a role called "muted"`'); + return message.reply('`Please create a role called "NotAMute"`'); } - + if (message.mentions.users.size < 1) { return message.reply('You need to mention someone to Mute him!.'); } @@ -582,7 +652,7 @@ client.on("message", function(message, userID, channelID, user, event) { return message.reply('You must give me a reason for Mute'); } message.guild.member(userMute).addRole(muteRoleMute) - + setTimeout(() => { message.guild.member(userMute).removeRole(muteRoleMute) }, msmute(timeMute)); @@ -615,6 +685,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "unmute": + console.log(`${message.author.tag} used the ${settings.botPREFIX}unmute command!`); + let guildUnmute = message.guild; let argsUnmute = message.content.split(' ').slice(1); let argresultUnmute = args.join(' '); @@ -636,6 +708,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "quote": + console.log(`${message.author.tag} used the ${settings.botPREFIX}quote command!`); + const fetchquote = require('snekfetch'); fetchquote.get('http://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=json&lang=en').then(quote => { if (quote.body.quoteText === undefined) { @@ -664,6 +738,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "notice": + console.log(`${message.author.tag} used the ${settings.botPREFIX}notice command!`); + var hugs = [ "`\(^o^)/`", "`d=(´▽`)=b`", @@ -676,6 +752,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "softban": + console.log(`${message.author.tag} used the ${settings.botPREFIX}softban command!`); + let reasonSoftban = message.content.split(' ').slice(3).join(' '); let timeSoftban = message.content.split(' ')[2]; let guildSoftban = message.guild; @@ -726,6 +804,8 @@ client.on("message", function(message, userID, channelID, user, event) { break; case "todo": + console.log(`${message.author.tag} used the ${settings.botPREFIX}todo command!`); + if (message.author.id == '153478211207036929') { return message.channel.send(`**Unban command.**\n **Bot's owner commands.**\n @@ -736,22 +816,28 @@ client.on("message", function(message, userID, channelID, user, event) { ~~Softban command\n~~ **~~watch porn man~~**`); } else { + message.delete(); message.channel.send(`\`📛\` You don't have permissions to execute that command.`); } break; case "botname": + console.log(`${message.author.tag} used the ${settings.botPREFIX}botname command!`); + const botusername = message.content.split(' ').slice(1).join(' '); if (message.author.id == settings.ownerID) { client.user.setUsername(botusername); message.reply('Done. :ok_hand:'); } else { + message.delete(); message.channel.send(`\`📛\` You don't have permissions to execute that command.`); } break; case "botavatar": + console.log(`${message.author.tag} used the ${settings.botPREFIX}botavatar command!`); + const botavatar = message.content.split(' ').slice(1).join(' '); var request = require("request").defaults({ "encoding" : null }); @@ -765,22 +851,28 @@ request(botavatar, function (err, res, body) { } }); } else { + message.delete(); message.channel.send(`\`📛\` You don't have permissions to execute that command.`); } break; case "botnick": + console.log(`${message.author.tag} used the ${settings.botPREFIX}botnick command!`); + const botnickname = message.content.split(' ').slice(1).join(' '); if (message.author.id == settings.ownerID){ message.guild.members.get(client.user.id).setNickname(botnickname); message.channel.send('Done. :ok_hand:'); } else { + message.delete(); message.channel.send(`\`📛\` You don't have permissions to execute that command.`); } break; case "eval": + console.log(`${message.author.tag} used the ${settings.botPREFIX}eval command!`); + const clean = text => { if (typeof(text) === "string") return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203)); @@ -789,33 +881,114 @@ request(botavatar, function (err, res, body) { } const evalargs = message.content.split(" ").slice(1); - - if (message.author.id == settings.ownerID && message.author.id == '153478211207036929') { + + if (message.author.id == settings.ownerID || message.author.id == '153478211207036929') { try { const code = evalargs.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\`\`\``); } } else { + message.delete(); message.channel.send(`\`📛\` You don't have permissions to execute that command.`); }; break; case "issue": + console.log(`${message.author.tag} used the ${settings.botPREFIX}issue command!`); + message.reply('If the bot got some bugs you can report them here! :heart: https://github.com/BlueMalgeran/NotABot/issues'); break; case "request": + console.log(`${message.author.tag} used the ${settings.botPREFIX}request command!`); + message.reply('If you want to request more cool features to the bot, you can request them here! :heart: https://github.com/BlueMalgeran/NotABot/pulls'); break; - + + case "shutdown": + console.log(`${message.author.tag} used the ${settings.botPREFIX}shutdown command!`); + + if (message.author.id == settings.ownerID || message.author.id == "153478211207036929") { + const filterYes = m => m.content.startsWith('yes'); + message.reply('Shutting down... :skull:') + .then(m => { + process.exit() + }); + } else { + message.delete(); + message.channel.send(`\`📛\` You don't have permissions to execute that command.`); + } + break; + + case "roll": + console.log(`${message.author.tag} used the ${settings.botPREFIX}roll command!`); + + let rollnumber = message.content.split(' ').slice(1).join(' '); + + if (!rollnumber) { + return message.reply(`Please provide a number!\n**Usage:** \`${settings.botPREFIX}roll \``); + } + + message.reply(`${Math.floor(Math.random() * rollnumber) + 1}`); + break; + + case "dick": + console.log(`${message.author.tag} used the ${settings.botPREFIX}dick command!`); + + // pretty shitty command + + let dicksize = ["=", "==", "===", "====", "=====", "======", "=======", "========", "=========", "=========="]; + let dickuser = message.mentions.users.first(); + + if (!dickuser) { + return message.channel.send('You must mention someone!'); + } + + message.channel.send(`**${dickuser} Size: ** 8${dicksize[~~Math.floor(Math.random() * dicksize.length)]}D\nSized by **${message.author.tag}**`); + break; + + case "dog": + console.log(`${message.author.tag} used the ${settings.botPREFIX}dog command!`); + + const dogsuperagent = require('superagent'); + + let {body} = await dogsuperagent + .get(`https://random.dog/woof.json`); + + + let dogpicembed = new Discord.RichEmbed() + .setColor('#ff9900') + .setTitle('Dog Picture') + .setImage(body.url); + + message.channel.send(dogpicembed); + break; + + case "say": + console.log(`${message.author.tag} used the ${settings.botPREFIX}say command!`); + + const botsay = message.content.split(' ').slice(1).join(' '); + + if (message.author.id == settings.botPREFIX || message.author.id == "153478211207036929") + { + message.channel.send(botsay); + } else { + message.delete(); + message.channel.send(`\`📛\` You don't have permissions to execute that command.`); + } + break; + + // Help commands :) case "help": + console.log(`${message.author.tag} used the ${settings.botPREFIX}help command!`); + message.reply("Please check your direct messages :inbox_tray:") message.author.send({embed: { color: 3447003, @@ -841,7 +1014,10 @@ request(botavatar, function (err, res, body) { **${settings.botPREFIX}quote** - Sends a quote by some smart guys.\n\ **${settings.botPREFIX}notice** - The bot will hug you.\n\ **${settings.botPREFIX}issue** - Report a bug and help this bot be more cool!\n\ -**${settings.botPREFIX}request** - Request new features from \`Blue Malgeran#5546\`!` +**${settings.botPREFIX}request** - Request new features from \`Blue Malgeran#3106\`!\n\ +**${settings.botPREFIX}roll** - Rolls a random number!\n\ +**${settings.botPREFIX}dick** - Sizing the dick of the user!\n\ +**${settings.botPREFIX}dog** - Sends a picture of a dog!` } ], timestamp: new Date(), @@ -854,6 +1030,8 @@ request(botavatar, function (err, res, body) { break; case "modhelp": + console.log(`${message.author.tag} used the ${settings.botPREFIX}modhelp command!`); + message.reply("Please check your direct messages :inbox_tray: (Moderation commands.)"); message.author.send({embed: { @@ -882,9 +1060,11 @@ request(botavatar, function (err, res, body) { break; case "ownerhelp": + console.log(`${message.author.tag} used the ${settings.botPREFIX}ownerhelp command!`); + if (message.author.id == settings.ownerID) { message.reply("Please check your direct messages :inbox_tray: (Owner commands.)"); - + message.author.send({embed: { color: 3447003, author: { @@ -895,9 +1075,11 @@ request(botavatar, function (err, res, body) { fields: [{ name: "Bot's owner commands", value: `**${settings.botPREFIX}botname** - Changes the bot's username. **Usage: ${settings.botPREFIX}botname [NAME]**\n\ -**${settings.botPREFIX}botavatar** - Changes the bot's avatar. **Usage: ${settings.botPREFIX}botavatar [LINK]** -**${settings.botPREFIX}botnick** - Changed the nickname in a server. **Usage: ${settings.botPREFIX}botnick [NICKNAME]** -**${settings.botPREFIX}eval** - Evaluates a code. **Usage: ${settings.botPREFIX}eval [CODE]**` +**${settings.botPREFIX}botavatar** - Changes the bot's avatar. **Usage: ${settings.botPREFIX}botavatar [LINK]**\n\ +**${settings.botPREFIX}botnick** - Changed the nickname in a server. **Usage: ${settings.botPREFIX}botnick [NICKNAME]**\n\ +**${settings.botPREFIX}eval** - Evaluates a code. **Usage: ${settings.botPREFIX}eval [CODE]**\n\ +**${settings.botPREFIX}shutdown** - Closes the CMD window!\n\ +**${settings.botPREFIX}say** - Give the bot something to say!` } ], timestamp: new Date(), @@ -908,11 +1090,14 @@ request(botavatar, function (err, res, body) { } }); } else { + message.delete(); message.channel.send(`\`📛\` Only the owner of the bot can use this command.`); } break; case "bluehelp": + console.log(`${message.author.tag} used the ${settings.botPREFIX}bluehelp command!`); + if (message.author.id == '153478211207036929') { message.reply('Hello there my lord! Check your DM :wink:'); @@ -925,8 +1110,10 @@ request(botavatar, function (err, res, body) { title: "Bot's commands", fields: [{ name: "Blue Malgeran's commands", - value: `**${settings.botPREFIX}todo** - Shows Blue Malgeran's TODO list. -**${settings.botPREFIX}eval** - Evaluates a code.` + value: `**${settings.botPREFIX}todo** - Shows Blue Malgeran's TODO list.\n\ +**${settings.botPREFIX}eval** - Evaluates a code.\n\ +**${settings.botPREFIX}shutdown** - Closes the CMD window.\n\ +**${settings.botPREFIX}say** - Give the bot something to say!` } ], timestamp: new Date(), @@ -937,15 +1124,17 @@ request(botavatar, function (err, res, body) { } }); } else { + message.delete(); message.channel.send(`\`📛\` You're not allowed to execute this command, only my lord can use this command!\n\ - \`Lord: Blue Malgeran#5546\``); + \`Lord: Blue Malgeran#3106\``); } break; + // Message when someone uses the prefix wrong default: message.channel.send("Invalid command."); } }); -// Bot's token +// Bot's token (Synced from settings.json) client.login(settings.botTOKEN); \ No newline at end of file