Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.60 KB | None | 0 0
  1. // Load up the discord.js library
  2. const Discord = require("discord.js");
  3.  
  4. // This is your client. Some people call it `bot`, some people call it `self`,
  5. // some might call it `cootchie`. Either way, when you see `client.something`, or `bot.something`,
  6. // this is what we're refering to. Your client.
  7. const client = new Discord.Client();
  8.  
  9. // Here we load the config.json file that contains our token and our prefix values.
  10. const config = require("./config.json");
  11. // config.token contains the bot's token
  12. // config.prefix contains the message prefix.
  13.  
  14.  
  15. var mysql = require('mysql');
  16.  
  17. var con = mysql.createConnection({
  18. host: "localhost",
  19. user: "root",
  20. password: "root",
  21. database: "bcq_reclutamiento"
  22. });
  23.  
  24. var servers_id = {
  25. 'FdQ': '428874791957561350'
  26. }
  27.  
  28. con.connect(function(err) {
  29. if (err) throw err;
  30. console.log("Connected! to DB");
  31. });
  32.  
  33. client.on("ready", () => {
  34. // This event will run if the bot starts, and logs in, successfully.
  35. console.log(`Bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`);
  36. // Example of changing the bot's playing game to something useful. `client.user` is what the
  37. // docs refer to as the "ClientUser".
  38. client.user.setActivity(`Serving ${client.guilds.size} servers`);
  39. });
  40.  
  41. client.on("guildCreate", guild => {
  42. // This event triggers when the bot joins a guild.
  43. console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
  44. client.user.setActivity(`Serving ${client.guilds.size} servers`);
  45. });
  46.  
  47. client.on("guildDelete", guild => {
  48. // this event triggers when the bot is removed from a guild.
  49. console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
  50. client.user.setActivity(`Serving ${client.guilds.size} servers`);
  51. });
  52.  
  53. client.on("message", async message => {
  54. // This event will run on every single message received, from any channel or DM.
  55.  
  56. // It's good practice to ignore other bots. This also makes your bot ignore itself
  57. // and not get into a spam loop (we call that "botception").
  58. if(message.author.bot) return;
  59.  
  60. // Also good practice to ignore any message that does not start with our prefix,
  61. // which is set in the configuration file.
  62. if(message.content.indexOf(config.prefix) !== 0) return;
  63.  
  64. // Here we separate our "command" name, and our "arguments" for the command.
  65. // e.g. if we have the message "+say Is this the real life?" , we'll get the following:
  66. // command = say
  67. // args = ["Is", "this", "the", "real", "life?"]
  68. const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  69. const command = args.shift().toLowerCase();
  70.  
  71. // Comando para que la gente se apunte como reclutas
  72. if(command === "reclutar") {
  73. const originalMessage = message;
  74.  
  75. const createdByID = message.author.id;
  76. const createdByUsername = message.author.username;
  77. const createdByDiscriminator = message.author.discriminator;
  78.  
  79. var sql = "SELECT id FROM reclutamientos WHERE user_id = ?";
  80. con.query(sql, [createdByID] ,function (err, result) {
  81. if (err) {
  82. originalMessage.author.send("No podemos unirte a la banda debido a que estamos de mantenimiento, no te preocupes y vuelve a intentarlo mas tarde");
  83. } else {
  84. if (result.length == 0){
  85. var sql = "INSERT INTO reclutamientos (user_id, user_name, user_discriminator) VALUES ? ";
  86. var values = [[createdByID, createdByUsername, createdByDiscriminator]];
  87. con.query(sql, [values], function (err, result) {
  88. if (err) {
  89. originalMessage.author.send("No podemos unirte a la banda debido a que estamos de mantenimiento, no te preocupes y vuelve a intentarlo mas tarde");
  90. } else {
  91. originalMessage.author.send("Te incluimos en nuestro sistema de reclutamiento, cuando tengamos hueco recibiras un mensaje para poder unirte");
  92. }
  93. });
  94. } else {
  95. originalMessage.author.send("No podemos unirte a la banda debido a que ya estas en reclutamiento");
  96. }
  97. }
  98.  
  99. });
  100.  
  101. message.delete();
  102. }
  103.  
  104. // Comando para que podamos ver la lista
  105. if(command === "lista") {
  106.  
  107. if(!message.member.roles.some(r=>["Fundador", "Capitan"].includes(r.name)) )
  108. return message.reply("Tu no puedes hacer esto");
  109.  
  110. const sayMessage = args.join(" ");
  111. quantity = parseInt(sayMessage);
  112.  
  113. var sql = "SELECT user_name, user_discriminator, DATE_FORMAT(joined_at, '%d/%m/%Y - %H:%i:%s') as joined_at FROM reclutamientos WHERE recluted_at IS NULL AND in_band = 0 LIMIT ";
  114. var limit = "20";
  115. var mensaje = '';
  116.  
  117. if (sayMessage.length > 0 && !isNaN(quantity) && quantity < 50){
  118. limit = quantity;
  119. }
  120.  
  121. sql += limit;
  122. console.log(sql);
  123. con.query(sql, function (err, result) {
  124. if (err) {
  125. return message.reply("No hemos podido obtener una lista de reclutados");
  126. } else {
  127. console.log(result);
  128. if(result.length == 0){
  129. return message.reply(mensaje = "Actualmente no existen reclutas esperando");
  130. } else {
  131. result.forEach(function(recluta) {
  132. console.log("recluta");
  133. mensaje += `\nNombre: **${recluta.user_name}#${recluta.user_discriminator}** (__${recluta.joined_at}__)`;
  134. })
  135. return message.reply(mensaje);
  136. }
  137. }
  138. })
  139. }
  140.  
  141. // Comando para aceptar a gente
  142. if(command === "aceptar") {
  143.  
  144. if(!message.member.roles.some(r=>["Fundador", "Capitan"].includes(r.name)) )
  145. return message.reply("Tu no puedes hacer esto");
  146.  
  147. const sayMessage = args.join(" ");
  148.  
  149. var mensaje = '';
  150.  
  151. if (sayMessage.length > 0){
  152. user = sayMessage;
  153. var sql = "SELECT id, user_id FROM reclutamientos WHERE CONCAT(user_name, '#', user_discriminator) = ? AND recluted_at IS NULL AND in_band = 0";
  154. con.query(sql, [user], function (err, result) {
  155. if (err) {
  156. return message.reply("No hemos podido obtener una lista de reclutados");
  157. } else {
  158. if(result.length == 0){
  159. return message.reply("No hemos encontrado un recluta con ese nombre");
  160. } else {
  161. result.forEach(function(recluta) {
  162. var sql = "UPDATE reclutamientos SET recluted_at = NOW() WHERE id = ?";
  163. con.query(sql, [recluta.id], function (err, result) {
  164. if (err) {
  165. mensaje += "No hemos podido actualizar a ese recluta";
  166. } else {
  167. mensaje += "Recluta marcado para ser reclutado, tiene 12 horas para unirse a la banda";
  168. client.users.get(recluta.user_id).send("Bienvenido.");
  169. }
  170. return message.reply(mensaje);
  171. });
  172. })
  173. }
  174. }
  175. })
  176. } else {
  177. return message.reply("Debes introducir un nombre de recluta");
  178. }
  179.  
  180. }
  181.  
  182. if(command === "probar"){
  183. console.log(client.guilds.get(servers_id.FdQ).users.get('428882147961733122').send("hww"));
  184. //console.log(client.users.get('428882147961733122'));
  185. //console.log(client.users.get('242265845127053312'));
  186. }
  187.  
  188. // Comando para ver lista de pendientes
  189. if(command === "pendientes") {
  190.  
  191. if(!message.member.roles.some(r=>["Fundador", "Capitan"].includes(r.name)) )
  192. return message.reply("Tu no puedes hacer esto");
  193.  
  194. const sayMessage = args.join(" ");
  195. quantity = parseInt(sayMessage);
  196.  
  197. var sql = "SELECT user_name, user_discriminator, DATE_FORMAT(recluted_at, '%d/%m/%Y - %H:%i:%s') as recluted_at FROM reclutamientos WHERE recluted_at IS NOT NULL AND in_band = 0 LIMIT ";
  198. var limit = "20";
  199. var mensaje = '';
  200.  
  201. if (sayMessage.length > 0 && !isNaN(quantity) && quantity < 50){
  202. limit = quantity;
  203. }
  204.  
  205. sql += limit;
  206. con.query(sql, function (err, result) {
  207. if (err) {
  208. return message.reply("No hemos podido obtener una lista de reclutados pendientes");
  209. } else {
  210. if(result.length == 0){
  211. return message.reply(mensaje = "Actualmente no existen reclutas pendientes de confirmar en banda");
  212. } else {
  213. result.forEach(function(recluta) {
  214. mensaje += `\nNombre: **${recluta.user_name}#${recluta.user_discriminator}** (ACEPTADO: __${recluta.recluted_at}__)`;
  215. })
  216. return message.reply(mensaje);
  217. }
  218. }
  219. })
  220. }
  221. /*if(command === "say") {
  222. // makes the bot say something and delete the message. As an example, it's open to anyone to use.
  223. // To get the "message" itself we join the `args` back into a string with spaces:
  224. const sayMessage = args.join(" ");
  225. // Then we delete the command message (sneaky, right?). The catch just ignores the error with a cute smiley thing.
  226. message.delete().catch(O_o=>{});
  227. // And we get the bot to say the thing:
  228. message.channel.send(sayMessage);
  229. }
  230.  
  231. if(command === "kick") {
  232. // This command must be limited to mods and admins. In this example we just hardcode the role names.
  233. // Please read on Array.some() to understand this bit:
  234. // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/some?
  235. if(!message.member.roles.some(r=>["Administrator", "Moderator"].includes(r.name)) )
  236. return message.reply("Sorry, you don't have permissions to use this!");
  237.  
  238. // Let's first check if we have a member and if we can kick them!
  239. // message.mentions.members is a collection of people that have been mentioned, as GuildMembers.
  240. // We can also support getting the member by ID, which would be args[0]
  241. let member = message.mentions.members.first() || message.guild.members.get(args[0]);
  242. if(!member)
  243. return message.reply("Please mention a valid member of this server");
  244. if(!member.kickable)
  245. return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?");
  246.  
  247. // slice(1) removes the first part, which here should be the user mention or ID
  248. // join(' ') takes all the various parts to make it a single string.
  249. let reason = args.slice(1).join(' ');
  250. if(!reason) reason = "No reason provided";
  251.  
  252. // Now, time for a swift kick in the nuts!
  253. await member.kick(reason)
  254. .catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`));
  255. message.reply(`${member.user.tag} has been kicked by ${message.author.tag} because: ${reason}`);
  256.  
  257. }
  258.  
  259. if(command === "ban") {
  260. // Most of this command is identical to kick, except that here we'll only let admins do it.
  261. // In the real world mods could ban too, but this is just an example, right? ;)
  262. if(!message.member.roles.some(r=>["Administrator"].includes(r.name)) )
  263. return message.reply("Sorry, you don't have permissions to use this!");
  264.  
  265. let member = message.mentions.members.first();
  266. if(!member)
  267. return message.reply("Please mention a valid member of this server");
  268. if(!member.bannable)
  269. return message.reply("I cannot ban this user! Do they have a higher role? Do I have ban permissions?");
  270.  
  271. let reason = args.slice(1).join(' ');
  272. if(!reason) reason = "No reason provided";
  273.  
  274. await member.ban(reason)
  275. .catch(error => message.reply(`Sorry ${message.author} I couldn't ban because of : ${error}`));
  276. message.reply(`${member.user.tag} has been banned by ${message.author.tag} because: ${reason}`);
  277. }
  278.  
  279. if(command === "purge") {
  280. // This command removes all messages from all users in the channel, up to 100.
  281.  
  282. // get the delete count, as an actual number.
  283. const deleteCount = parseInt(args[0], 10);
  284.  
  285. // Ooooh nice, combined conditions. <3
  286. if(!deleteCount || deleteCount < 2 || deleteCount > 100)
  287. return message.reply("Please provide a number between 2 and 100 for the number of messages to delete");
  288.  
  289. // So we get our messages, and delete them. Simple enough, right?
  290. const fetched = await message.channel.fetchMessages({limit: deleteCount});
  291. message.channel.bulkDelete(fetched)
  292. .catch(error => message.reply(`Couldn't delete messages because of: ${error}`));
  293. }*/
  294. });
  295.  
  296. client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement