Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const $ = require("jquery");
- const request = require('xhr-request')
- const client = new Discord.Client();
- const bot_table="testing";
- const token="BOT_TOKEN";
- const default_prefix="m!";
- const prefix=default_prefix;
- const mysql = require('mysql');
- const conn = mysql.createConnection({
- host : 'DB_IP',
- user : 'root',
- password : 'DB_PASSWORD',
- database : 'DB_DATABASE'
- });
- conn.connect();
- client.on("ready", () => {
- // This event will run if the bot starts, and logs in, successfully.
- //console.log(client.guilds.get("329498711338123268").channels.find("name","general"));
- console.log(`Bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`);
- // Example of changing the bot's playing game to something useful. `client.user` is what the
- // docs refer to as the "ClientUser".
- if(client.shard !== undefined && client.shard !== null) {
- client.user.setGame(`${default_default_prefix}help | ${client.guilds.size} Guilds | Shard ${(client.shard.id+1)}/${client.shard.count} | ${client.users.size} Users`);
- } else {
- client.user.setGame(`${default_prefix}help | ${client.guilds.size} Guilds | Shard 1/1 | ${client.users.size} Users`);
- }
- });
- client.on("guildCreate", guild => {
- // This event triggers when the bot joins a guild.
- console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
- if(client.shard !== undefined && client.shard !== null) {
- client.user.setGame(`${default_prefix}help | ${client.guilds.size} Guilds | Shard ${(client.shard.id+1)}/${client.shard.count} | ${client.users.size} Users`);
- } else {
- client.user.setGame(`${default_prefix}help | ${client.guilds.size} Guilds | Shard 1/1 | ${client.users.size} Users`);
- }
- conn.query(`INSERT INTO ${bot_table} (discord_server_id,prefix,nsfw_enabled,nsfw_type) VALUES ("${guild.id}","${default_prefix}",0,"Straight")`);
- });
- client.on("guildDelete", guild => {
- // this event triggers when the bot is removed from a guild.
- console.log(`Removed from: ${guild.name} (id: ${guild.id})`);
- if(client.shard !== undefined && client.shard !== null) {
- client.user.setGame(`${default_prefix}help | ${client.guilds.size} Guilds | Shard ${(client.shard.id+1)}/${client.shard.count} | ${client.users.size} Users`);
- } else {
- client.user.setGame(`${default_prefix}help | ${client.guilds.size} Guilds | Shard 1/1 | ${client.users.size} Users`);
- }
- conn.query(`DELETE FROM ${bot_table} WHERE discord_server_id = "${guild.id}"`);
- });
- client.on("guildMemberAdd", member => {
- console.log(`USER_JOIN > ${member.username}#${member.discriminator} in guild ${member.guild.name} (${member.guild.id})`);
- conn.query(`SELECT * FROM ${bot_table} WHERE discord_server_id = "${member.guild.id}"`, function (error, results, fields) {
- if(results[0].join_enabled == 1 || results[0].join_enabled == true) {
- var join_message=results[0].join_message.replace(/{user}/g,`<@!${member.id}>`).replace(/{server}/g,member.guild.name);
- console.log(`Sent join message "${join_message}" to channel ${client.channels.get(results[0].join_channel).name} (${client.channels.get(results[0].join_channel).id}) in guild ${member.guild.name} (${member.guild.id})`);
- client.channels.get(results[0].join_channel).send(join_message);
- }
- });
- });
- client.on("message", async message => {
- if(message.author.bot) return;
- //message.reply(message.content);
- conn.query(`SELECT * FROM ${bot_table} WHERE discord_server_id = "${message.guild.id}"`, function (error, results, fields) {
- main(results[0].prefix);
- });
- //console.log("PREF: "+global.pref);
- async function main(prefix) {
- if (message.content.indexOf(prefix) !== 0) return;
- const args = message.content.slice(prefix.length).trim().split(/ +/g);
- const command = args.shift().toLowerCase();
- message.delete().catch(error=>{message.reply("Error deleting command")});
- switch(command) {
- case "help":
- var desc=`**${prefix}help** - Lists all bot commands${"\n"}**${prefix}ping** - Returns the bots ping${"\n"}**${prefix}info** - Returns info about the bot${"\n"}**${prefix}discord** - Join my discord server!${"\n"}**${prefix}mmorpg** - Play a text based MMORPG${"\n"}**${prefix}yiff** - Displays a random yiff image${"\n"}**${prefix}config** - Change config options for the bot on your server`;
- //var data = {"title": "Help For Our Bot", "url": "https://bot.discord.mcpro.games","color": 157661,"thumbnail": {"url": "https://i.mcpro.games/dragon.png"},"author": {"name": "Donovan_DMC","url": "https://www.donovand.info","icon_url": "https://i.mcpro.games/Don.jpeg"},"fields": [{"name": "Command","value": prefix+"help","inline": true},{"name": "Description","value": "Shows help about the bot","inline": true},{"name": prefix+"ping","value": prefix+"info","inline": true},{"name": "Returns the bots ping","value": "Shows info about the bot","inline": true},{"name": prefix+"discord","value": prefix+"mmorpg","inline": true},{"name": "Join my discord server!","value": "Play a text based MMORPG","inline": true},{"name":prefix+"yiff","value":prefix+"nsfw_type","inline":true},{"name":"Displays a random yiff image","value":"Change the type of yiff displayed","inline":true}]};
- var data = {"title": "Help For Our Bot (Command List)","description":desc,"url": "https://bot.discord.mcpro.games","color": 157661,"thumbnail": {"url": "https://i.mcpro.games/dragon.png"},"author": {"name": "Donovan_DMC","url": "https://www.donovand.info","icon_url": "https://i.mcpro.games/Don.jpeg"}};
- var embed = new Discord.RichEmbed(data);
- message.channel.send(embed);
- break;
- case "discord":
- var data = {"title": "Discord","description": "[Join Our Discord!](https://join.discord.mcpro.games)","color": 5540381,"thumbnail": {"url": "https://cdn.discordapp.com/embed/avatars/0.png"},"author": {"name": "Donovan_DMC","url": "https://www.donovand.info","icon_url": "https://i.mcpro.games/Don.jpeg"}};
- var embed = new Discord.RichEmbed(data);
- message.channel.send(embed);
- break;
- case"mmorpg":
- var data = {"title": "MMORPG","description": "[MMORPG Discord](https://www.furrycentr.al/mmorpg/inv/)\n[MMORPG Online Interface](https://www.furrycentr.al/mmorpg/)\nYou must be in the [MMORPG Discord](https://www.furrycentr.al/mmorpg/inv/) server for the web interface to work.\nThe web interface was made by me, [Donovan_DMC](https://twitter.com/Donovan_DMC)","color": 5540381,"thumbnail": {"url": "https://fc.api.mcpro.games/mmorpg/assets/images/mmorpg.png"},"author": {"name": "Donovan_DMC","url": "https://www.donovand.info","icon_url": "https://i.mcpro.games/Don.jpeg"}};
- var embed = new Discord.RichEmbed(data);
- message.channel.send(embed);
- break;
- case "ping":
- var m = await message.channel.send("Checking Ping..");
- m.edit("Ping Calculated!");
- m.delete().catch(O_o=>{});
- message.channel.send(`Bot Ping: ${m.createdTimestamp - message.createdTimestamp}ms\nAPI Ping: ${Math.round(client.ping)}ms`)
- break;
- case "yiff":
- if(message.channel.nsfw) {
- conn.query(`SELECT nsfw_type,nsfw_enabled FROM ${bot_table} WHERE discord_server_id = "${message.guild.id}"`, function (error, results, fields) {
- if (error) {
- console.log(error);
- } else {
- if(results == "" || !results) {
- console.log("nsfw_type and nsfw_enabled is not set");
- var data = {"title": `Please set the yiff type via the command:${"\n"}${prefix}config nsfw_type <type>`,"color": 14686101,"author": {"name": message.author.username,"icon_url": message.author.avatarURL}};
- var embed = new Discord.RichEmbed(data);
- message.channel.send(embed);
- } else {
- if(results[0].nsfw_enabled == 0) {
- var data = {"title": `NSFW commands are not enabled. Enable them via the command:${"\n"}${prefix}config nsfw_enabled true`,"color": 14686101,"author": {"name": message.author.username,"icon_url": message.author.avatarURL}};
- var embed = new Discord.RichEmbed(data);
- message.channel.send(embed);
- } else {
- var nsfw_type=results[0].nsfw_type;
- request(`https://discordbot.api.mcpro.games/Images/NSFW/${nsfw_type}/random.php`, {json: true}, function (err, data) {
- if (err) {
- console.log(err);
- } else {
- var img_name=data.response.image.split("/img/")[1];
- var msg=new Discord.Attachment(data.response.image,img_name);
- message.channel.send(msg);
- console.log(`\n\nNSFW_IMAGE >\nImage Requested\nGuild: ${message.guild.name} (${message.guild.id})\nChannel: ${message.channel.name} (${message.channel.id})\nUser: ${message.author.username} (${message.author.id})\nYiff Type: ${nsfw_type}\nImage URL: ${data.response.image}`);
- }
- });
- }
- }
- }
- });
- } else {
- var data = {"title": "The command you tried to use is only usable in an NSFW channel","color": 15286101,"author": {"name": message.author.username,"icon_url": message.author.avatarURL}};
- var embed = new Discord.RichEmbed(data);
- message.channel.send(embed);
- }
- break;
- case "config":
- var opts=Array("nsfw_enabled","nsfw_type","prefix");
- var opt_str="**"+opts.toString().replace(/,/g,"** | **")+"**";
- if(args[0] == "" || !args[0]) {
- message.reply(`Valid config options:${"\n"}${opt_str}`);
- } else {
- if(opts.indexOf(args[0]) == -1) {
- message.channel.send(`Invalid config option ${args[0]}`);
- } else {
- switch(args[0]) {
- case "prefix":
- if(args[1] == "" || !args[1]) {
- message.channel.send(`Config option: ${args[0]}${"\n"}Description: Changes the bot's command prefix for this server${"\n"}Prefix must be under 30 characters`);
- } else {
- if (args[1].length > 30) {
- message.reply("Prefix must be less than 30 characters in length");
- console.log(`Prefix too long, Length: ${args[1].length}\nGuild: ${message.guild.name} (${message.guild.id})\nUser: ${message.author.username}#${message.author.discriminator} (${message.author.id})`);
- } else {
- conn.query(`UPDATE ${bot_table} SET prefix = "${args[1]}" WHERE discord_server_id = "${message.guild.id}"`, function (error, results, fields) {
- if (error) {
- console.log(error);
- } else {
- console.log(`UPDATE_SETTING > Changed prefix from ${prefix} to ${args[1]} in guild ${message.guild.name} (${message.guild.id})`);
- message.reply(`Changed prefix to ${args[1]}`);
- }
- });
- }
- }
- break;
- case "nsfw_enabled":
- if(args[1] == "" || !args[1]) {
- message.channel.send(`Config option: ${args[0]}${"\n"}Description: Enables or disabled NSFW commands${"\n"}Valid values: TRUE,FALSE,1,0`);
- } else {
- switch (args[1].toLocaleLowerCase()) {
- case 1:
- case true:
- case "1":
- case "true":
- var opt="1";
- break;
- case 0:
- case false:
- case "0":
- case "false":
- var opt="0";
- break;
- }
- conn.query(`UPDATE ${bot_table} SET nsfw_enabled = "${opt}" WHERE discord_server_id = "${message.guild.id}"`, function (error, results, fields) {
- if (error) {
- console.log(error);
- } else {
- if(opt == false) {
- console.log(`UPDATE_SETTING > Disabled NSFW commands in guild ${message.guild.name} (${message.guild.id})`);
- message.reply(`Disabled NSFW Commands`);
- } else if(opt == true) {
- console.log(`UPDATE_SETTING > Enabled NSFW commands in guild ${message.guild.name} (${message.guild.id})`);
- message.reply(`Enabled NSFW Commands`);
- }
- if (error) {
- console.log(error);
- }
- }
- });
- }
- break;
- case "nsfw_type":
- var nsfw_types=Array("gay","femboy","straight","lesbian","gay-cub","straight-cub","lesbian-cub");
- var nsfw_types_str=nsfw_types.toString();
- if(args[1] == "" || !args[1]) {
- message.channel.send(`Config option: ${args[0]}${"\n"}Description: Changes the NSFW type shown when an NSFW command is used${"\n"}Valid values: ${nsfw_types_str}${"\n"}Usage: ${prefix}config ${args[0]} <value>`);
- } else {
- if(nsfw_types.indexOf(args[1]) == -1) {
- var data = {"fields":[{"name":`"${args[1]}" is not a valid value for nsfw_type`,"value":`Valid Values: ${nsfw_types_str}`,"inline":true}],"color": 14686101,"author": {"name": message.author.username,"icon_url": message.author.avatarURL}};
- var embed = new Discord.RichEmbed(data);
- message.channel.send(embed);
- } else {
- function yifftype(string) {
- var res=string.toLocaleLowerCase();
- if(res.indexOf("-") !== -1) {
- var resa=res.split("-");
- var resb=resa[0].charAt(0).toLocaleUpperCase();
- var resc=resa[1].charAt(0).toLocaleUpperCase();
- return resb+resa[0].slice(1)+"-"+resc+resa[1].slice(1);
- } else {
- var resa=res.charAt(0).toLocaleUpperCase();
- return resa+res.slice(1);
- }
- }
- var y_type=yifftype(args[1]);
- conn.query(`SELECT * FROM ${bot_table} WHERE discord_server_id = "${message.guild.id}"`, function (error, results, fields) {
- if (error) {
- console.log(error);
- } else {
- if (results == "" || !results) {
- conn.query(`INSERT INTO ${bot_table} (discord_server_id,prefix,enable_yiff,nsfw_type) VALUES ("${message.guild.id}","m!",0,"${y_type}")`, function (error, results, fields) {
- if (error) {
- console.log(error);
- } else {
- console.log(`SET_SETTING > Set nsfw_type to ${y_type} in guild ${message.guild.name} (${message.guild.id})`);
- message.reply(`Set nsfw_type to ${args[1].toLocaleLowerCase()}`);
- message.reply(`You must enable NSFW commands before they are usable, enable them via the command:${"\n"} **${prefix}config nsfw_enabled true**`);
- }
- });
- } else {
- var nsfwtype_og_value=results[0].nsfw_type;
- conn.query(`UPDATE ${bot_table} SET nsfw_type = "${y_type}" WHERE discord_server_id = "${message.guild.id}"`, function (error, results, fields) {
- if (error) {
- console.log(error);
- } else {
- console.log(`UPDATE_SETTING > Changed nsfw_type from ${nsfwtype_og_value} to ${y_type} in guild ${message.guild.name} (${message.guild.id})`);
- message.reply(`Changed nsfw_type from ${nsfwtype_og_value.toLocaleLowerCase()} to ${args[1].toLocaleLowerCase()}`);
- conn.query(`SELECT nsfw_enabled FROM ${bot_table} WHERE discord_server_id = "${message.guild.id}"`, function (error, results, fields) {
- if (error) {
- console.log(error);
- } else {
- if(results[0].nsfw_enabled == 0) {
- message.reply(`You must enable NSFW commands before they are usable, enable them via the command:${"\n"} **${prefix}config nsfw_enabled true**`);
- }
- }
- });
- }
- });
- }
- }
- });
- }
- }
- break;
- case "joinmsg_enabled":
- if(args[1] == "" || !args[1]) {
- message.channel.send(`Config option: ${args[0]}${"\n"}Description: Enables or disabled join message in <channel>${"\n"}Valid values: TRUE,FALSE,1,0${"\n"}Usage: ${prefix}config ${args[0]} <true/false> <channel>`);
- } else {
- switch (args[1].toLocaleLowerCase()) {
- case 1:
- case true:
- case "1":
- case "true":
- var opt="1";
- break;
- case 0:
- case false:
- case "0":
- case "false":
- var opt="0";
- break;
- }
- conn.query(`UPDATE ${bot_table} SET join_enabled = "${opt}" WHERE discord_server_id = "${message.guild.id}"`, function (error, results, fields) {
- if (error) {
- console.log(error);
- } else {
- if(opt == false) {
- console.log(`UPDATE_SETTING > Disabled Join Message in guild ${message.guild.name} (${message.guild.id})`);
- message.reply(`Disabled Join Message`);
- } else if(opt == true) {
- console.log(`UPDATE_SETTING > Enabled Join Message in guild ${message.guild.name} (${message.guild.id})`);
- message.reply(`Enabled NSFW Commands`);
- }
- if (error) {
- console.log(error);
- }
- }
- });
- }
- break;
- default:
- message.channel.send(`Invalid config option ${args[0]}`);
- }
- }
- }
- break;
- //case "info":
- default:
- message.reply("Invalid command.");
- }
- }
- });
- client.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement