Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
2,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.68 KB | None | 0 0
  1. const Discord = require("discord.js");
  2. let mysql = require('mysql');
  3. const client = new Discord.Client();
  4. const config = require("./config/config.json");
  5. const cities = require("./config/cities.json");
  6. const Fortnite = require("fortnite-api");
  7.  
  8. let fortniteAPI = new Fortnite(
  9. [
  10. "nathanvezina1@gmail.com",
  11. "1999nathanvez123",
  12. "MzRhMDJjZjhmNDQxNGUyOWIxNTkyMTg3NmRhMzZmOWE6ZGFhZmJjY2M3Mzc3NDUwMzlkZmZlNTNkOTRmYzc2Y2Y=",
  13. "ZWM2ODRiOGM2ODdmNDc5ZmFkZWEzY2IyYWQ4M2Y1YzY6ZTFmMzFjMjExZjI4NDEzMTg2MjYyZDM3YTEzZmM4NGQ="
  14. ],
  15. {
  16. debug: true
  17. }
  18. );
  19.  
  20. client.on("ready", () => {
  21. console.log(`Bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`);
  22. client.user.setActivity(`Serving ${client.guilds.size} servers`);
  23. });
  24.  
  25. client.on("guildCreate", guild => {
  26. console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
  27. client.user.setActivity(`Serving ${client.guilds.size} servers`);
  28.  
  29. let con = mysql.createConnection({
  30. host: "localhost",
  31. user: "root",
  32. password: "",
  33. database: "guilds"
  34. });
  35.  
  36. con.connect(function(err) {
  37. if (err) throw err;
  38. con.query(`INSERT INTO config (prefix, serverID) VALUES ('!', ${guild.id})`, (err) => {
  39. if (err) throw err;
  40. });
  41. });
  42. con.end();
  43. });
  44. client.on("guildDelete", guild => {
  45. console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
  46. client.user.setActivity(`Serving ${client.guilds.size} servers`);
  47. let con = mysql.createConnection({
  48. host: "localhost",
  49. user: "root",
  50. password: "",
  51. database: "guilds",
  52. });
  53. con.connect(function(err) {
  54. if (err) throw err;
  55. con.query(`DELETE FROM config WHERE serverID = ${guild.id}`, function (err) {
  56. if (err) throw err;
  57. con.query(`DELETE FROM defis WHERE serverID = ${guild.id}`, function (err) {
  58. if (err) throw err;
  59. });
  60. });
  61. });
  62. con.end();
  63. });
  64.  
  65.  
  66. client.on("message", async message => {
  67. let con = mysql.createConnection({
  68. host: "localhost",
  69. user: "root",
  70. password: "",
  71. database: "guilds"
  72. });
  73.  
  74. con.connect(function(err) {
  75. if (err) throw err;
  76. con.query("SELECT * FROM `config` WHERE `serverID` = '" + client.guilds.get(message.guild.id).id + "'", (err, row) => {
  77. if(message.author.bot) return;
  78. if(message.content.indexOf(row[0].prefix) !== 0) return;
  79. const args = message.content.slice(row[0].prefix.length).trim().split(/ +/g);
  80. const command = args.shift().toLowerCase();
  81.  
  82. if(command === "info") {
  83. if (message.channel.id !== '468464421287624714') return
  84. const embed =
  85. {
  86. title: 'Fortnite Roler Statistics',
  87. fields: [{
  88. name: 'Mem Usage',
  89. value: `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`,
  90. inline: true
  91. }, {
  92. name: 'Users',
  93. value: `${client.users.size}`,
  94. inline: true
  95. }, {
  96. name: 'Servers',
  97. value: `${client.guilds.size}`,
  98. inline: true
  99. }, {
  100. name: 'Channels',
  101. value: `${client.channels.size}`,
  102. inline: true
  103. }, {
  104. name: 'Discord.js',
  105. value: `${Discord.version}`,
  106. }],
  107. footer: {
  108. text: "crée par Uɳιx#3142"
  109. }
  110. }
  111. message.channel.send('', { embed: embed });
  112. }
  113.  
  114. if(command === "stats") {
  115. //stats
  116. if (message.channel.id !== '389512905592274946') return;
  117. if (message.content.endsWith(row[0].prefix + "stats")) {
  118. let con = mysql.createConnection({
  119. host: "localhost",
  120. user: "root",
  121. password: "",
  122. database: "links",
  123. });
  124. let conStr = "SELECT * FROM `users` WHERE `userID` = '" + message.author.id+"'";
  125. con.query(conStr, function(error, row) {
  126. if (row && row.length) {
  127. fortniteAPI.login().then(() => {
  128. fortniteAPI
  129. .getStatsBR(row[0].username, "pc", "alltime")
  130. .then(stats => {
  131. message.channel.send({embed: {
  132. color: 3447003,
  133. title: row[0].username + "'s Stats",
  134. fields: [
  135. { name: "Solo", value: `**K/D** ${stats.group.solo["k/d"]}\n**WINS** ${stats.group.solo.wins}\n**KILLS** ${stats.group.solo.kills}\n**WIN%** ${stats.group.solo["win%"]}\n**MATCHES** ${stats.group.solo.matches}`, inline: true},
  136. { name: "Duo", value: `**K/D** ${stats.group.duo["k/d"]}\n**WINS** ${stats.group.duo.wins}\n**KILLS** ${stats.group.duo.kills}\n**WIN%** ${stats.group.duo["win%"]}\n**MATCHES** ${stats.group.duo.matches}`, inline: true},
  137. { name: "Squad", value: `**K/D** ${stats.group.squad["k/d"]}\n**WINS** ${stats.group.squad.wins}\n**KILLS** ${stats.group.squad.kills}\n**WIN%** ${stats.group.squad["win%"]}\n**MATCHES** ${stats.group.squad.matches}`, inline: true},
  138. { name: "Total", value: `**K/D** ${stats.lifetimeStats["k/d"]}\n**WINS** ${stats.lifetimeStats.wins}\n**KILLS** ${stats.lifetimeStats.kills}\n**WIN%** ${stats.lifetimeStats["win%"]}\n**MATCHES** ${stats.lifetimeStats.matches}`},
  139. ]
  140. }
  141. });
  142. con.end();
  143. })
  144. .catch(err => {
  145. console.log(err);
  146. });
  147. });
  148. }
  149. });
  150. }
  151. else {
  152. let username = args.join().replace(/\,/g, ' ');
  153. fortniteAPI.login().then(() => {
  154. fortniteAPI
  155. .getStatsBR(username, "pc", "alltime")
  156. .then(stats => {
  157. message.channel.send({embed: {
  158. color: 3447003,
  159. title: username + "'s Stats",
  160. fields: [
  161. { name: "Solo", value: `**K/D** ${stats.group.solo["k/d"]}\n**WINS** ${stats.group.solo.wins}\n**KILLS** ${stats.group.solo.kills}\n**WIN%** ${stats.group.solo["win%"]}\n**MATCHES** ${stats.group.solo.matches}`, inline: true},
  162. { name: "Duo", value: `**K/D** ${stats.group.duo["k/d"]}\n**WINS** ${stats.group.duo.wins}\n**KILLS** ${stats.group.duo.kills}\n**WIN%** ${stats.group.duo["win%"]}\n**MATCHES** ${stats.group.duo.matches}`, inline: true},
  163. { name: "Squad", value: `**K/D** ${stats.group.squad["k/d"]}\n**WINS** ${stats.group.squad.wins}\n**KILLS** ${stats.group.squad.kills}\n**WIN%** ${stats.group.squad["win%"]}\n**MATCHES** ${stats.group.squad.matches}`, inline: true},
  164. { name: "Total", value: `**K/D** ${stats.lifetimeStats["k/d"]}\n**WINS** ${stats.lifetimeStats.wins}\n**KILLS** ${stats.lifetimeStats.kills}\n**WIN%** ${stats.lifetimeStats["win%"]}\n**MATCHES** ${stats.lifetimeStats.matches}`},
  165. ]
  166. }
  167. });
  168. })
  169. .catch(err => {
  170. console.log(err);
  171. });
  172. });
  173. }
  174. }
  175.  
  176. if(command === "link") {
  177. if (message.channel.id !== '389512905592274946') return;
  178. let con = mysql.createConnection({
  179. host: "localhost",
  180. user: "root",
  181. password: "",
  182. database: "links",
  183. });
  184. let conStr = "SELECT * FROM `users` WHERE `userID` = '" + message.author.id+"'";
  185. con.query(conStr, function(error, row) {
  186.  
  187. if (row && row.length) {
  188. message.channel.send("Votre discord est déja associer à un autre compte: " + row[0].username)
  189. }
  190. else
  191. {
  192.  
  193. let username = args.join().replace(/\,/g, ' ');
  194. let conStr = "SELECT * FROM `users` WHERE `username` = '" + username +"'";
  195. con.query(conStr, function(error, row) {
  196.  
  197. if (row && row.length) {
  198. message.channel.send(row[0].username + " est déja associer à un autre compte discord")
  199. }
  200. else {
  201. let username = args.join().replace(/\,/g, ' ');
  202. fortniteAPI.login().then(() => {
  203. fortniteAPI
  204. .getStatsBR(username, "pc", "alltime")
  205. .then(stats => {
  206. let sql = "INSERT INTO users (userID, username) VALUES ('" + message.author.id + "', '" + username + "')";
  207. con.query(sql, function(error) {
  208.  
  209. message.channel.send(username + " à bien été associer.")
  210. });
  211. })
  212. .catch(err => {
  213. message.channel.send("Ce joueur n'existe pas ou n'est pas un joueur PC");
  214. });
  215. });
  216. }
  217. });
  218. }
  219. con.end();
  220. });
  221. con.end();
  222. }
  223.  
  224.  
  225.  
  226.  
  227.  
  228. if(command === "unlink") {
  229. if (message.channel.id !== '389512905592274946') return;
  230. let con = mysql.createConnection({
  231. host: "localhost",
  232. user: "root",
  233. password: "",
  234. database: "links",
  235. });
  236. let conStr = "SELECT * FROM `users` WHERE `userID` = '" + message.author.id+"'";
  237. con.query(conStr, function(error, row) {
  238.  
  239. if (row && row.length) {
  240. let sql = "DELETE FROM users WHERE userID = '" + message.author.id + "'";
  241. con.query(sql, function(error) {
  242. message.channel.send("Vous avez bien désassocié votre compte")
  243. });
  244. }
  245. else
  246. {
  247. message.channel.send("Vous n'avez aucun compte d'associer, vous pouvez faire `!link nom` pour associer un compte Fortnite à votre Discord")
  248. }
  249. });
  250. con.end();
  251. }
  252.  
  253.  
  254. if(command === "drop") {
  255. if (message.channel.id !== '468464421287624714') return;
  256. message.channel.send(message.author + ", vous et votre équipe devez descendre à " + cities[Math.floor(Math.random()*cities.length)] + ".");
  257. }
  258.  
  259. if(command === "roulette") {
  260. let con = mysql.createConnection({
  261. host: "localhost",
  262. user: "root",
  263. password: "",
  264. database: "guilds"
  265. });
  266. con.connect(function(err) {
  267. if (err) throw err;
  268. let conStr = "SELECT * from defis WHERE serverID = '" + client.guilds.get(message.guild.id).id + "' ORDER BY RAND() LIMIT 1";
  269. con.query(conStr, function (err, row) {
  270. if (row.length === 0) {
  271. message.channel.send("Ce serveur n'as pas encore de défi, pour en ajouter vous pouvez faire `!defi tuer un ennemi à la pioche`");
  272. }
  273. else {
  274. message.channel.send(message.author + ", vous et votre équipe devez descendre à " + cities[Math.floor(Math.random()*cities.length)] + ", cependant, " + row[0].defi + " (" + row[0].id + ")");
  275. }
  276. });
  277. });
  278. con.end();
  279. }
  280. if(command === "prefix") {
  281. if(message.member.roles.find("name", "Bot")){
  282. let con = mysql.createConnection({
  283. host: "localhost",
  284. user: "root",
  285. password: "",
  286. database: "guilds"
  287. });
  288. con.connect(function(err) {
  289. if (err) throw err;
  290. con.query("SELECT * from config WHERE serverID = '" + client.guilds.get(message.guild.id).id + "'", function (err, row) {
  291. if (err) throw err;
  292. let sql = "UPDATE config SET prefix = '" + args[0] +"' WHERE serverID = '" + client.guilds.get(message.guild.id).id + "'";
  293. con.query(sql, function (err, row) {
  294. message.channel.send("Votre prefix à bien été changer pour " + args[0]);
  295. });
  296. });
  297. });
  298. con.end();
  299. }
  300. else {
  301.  
  302. }
  303. }
  304. /*if(command === "setrank") {
  305. let con = mysql.createConnection({
  306. host: "localhost",
  307. user: "root",
  308. password: "mOdT3r-dh8S(",
  309. database: "links"
  310. });
  311. con.connect(function(err) {
  312. con.query("SELECT * FROM `users` WHERE `userID` = '" + message.author.id+"'", function (err, row) {
  313. if (row && row.length) {
  314. let con = mysql.createConnection({
  315. host: "localhost",
  316. user: "root",
  317. password: "mOdT3r-dh8S(",
  318. database: "guilds"
  319. });
  320. con.connect(function(err) {
  321. con.query("SELECT * FROM `roles` WHERE `serverID` = '" + client.guilds.get(message.guild.id).id +"'", function (err, row) {
  322. if (row && row.length) {
  323. }
  324. else {
  325. message.channel.send("Ce serveur n'as pas encore de rôle, pour en ajouter vous pouvez faire `!arole id kd`");
  326. }
  327. });
  328. });
  329. } else {
  330. message.channel.send("Vous n'avez aucun compte d'associer, vous pouvez faire `!link nom` pour associer un compte Fortnite à votre Discord");
  331. }
  332. });
  333. });
  334. }*/
  335. if(command === "rdefi") {
  336. if(message.member.roles.find("name", "Bot")){
  337. let con = mysql.createConnection({
  338. host: "localhost",
  339. user: "root",
  340. password: "",
  341. database: "guilds"
  342. });
  343. con.connect(function(err) {
  344. if (err) throw err;
  345. con.query("SELECT * from defis WHERE id = '" + args[0] + "'", function (err, row) {
  346. if (row.length === 0) {
  347. message.channel.send("Ce serveur n'as pas encore de défi, pour en ajouter vous pouvez faire `!defi tuer un ennemi à la pioche`");
  348. }
  349. else {
  350. if (client.guilds.get(message.guild.id).id === row[0].serverID) {
  351. con.query("DELETE from defis WHERE id = '" + args[0] + "'", function (err, row) {
  352. message.channel.send("Vous avez bien supprimer le défi: " + args[0]);
  353. });
  354. } else {
  355. message.channel.send("Ce défi ne vous appartient pas, vous pouvez faire !ldefi pour voir vos défis!");
  356. }
  357. }
  358. });
  359.  
  360. });
  361. con.end();
  362. } else {
  363.  
  364. }
  365. }
  366.  
  367. if(command === "ldefi") {
  368. let con = mysql.createConnection({
  369. host: "localhost",
  370. user: "root",
  371. password: "",
  372. database: "guilds"
  373. });
  374. con.connect(function(err) {
  375. if (err) throw err;
  376. con.query("SELECT * from defis WHERE serverID = '" + client.guilds.get(message.guild.id).id + "'", function (err, row) {
  377. if (row.length === 0) {
  378. message.channel.send("Ce serveur n'as pas encore de défi, pour en ajouter vous pouvez faire `!defi tuer un ennemi à la pioche`");
  379. }
  380. else {
  381. let array = '';
  382. row.forEach(function(row) {
  383. array += `${row.id}: ${row.defi}\n`
  384. });
  385. message.channel.send({embed: {
  386. color: 3447003,
  387. title: "Liste des défis pour " + client.guilds.get(message.guild.id).id ,
  388. description: `${array}`,
  389. footer: {
  390. text: "Vous pouvez ajouter vos propre défis avec la commande !defi tuer un ennemi à la pioche"
  391. }
  392. }
  393. });
  394. }
  395. con.end();
  396. });
  397. });
  398. }
  399. if(command === "cmds") {
  400. let con = mysql.createConnection({
  401. host: "localhost",
  402. user: "root",
  403. password: "",
  404. database: "guilds"
  405. });
  406. if (message.channel.id !== '468464421287624714') return;
  407. con.connect(function(err) {
  408. con.query("SELECT * from config WHERE serverID = '" + client.guilds.get(message.guild.id).id + "'", function (err, row) {
  409. message.channel.send({embed: {
  410. color: 3447003,
  411. title: "Commandes",
  412. fields: [
  413. { name: `${row[0].prefix}stats`, value: `donne les stats d'un joueur (${row[0].prefix}stats IveMemory) et ou (seulement ${row[0].prefix}stats si vous avez link votre compte.)`},
  414. { name: `${row[0].prefix}link`, value: `associe votre compte Fortnite à votre Discord (${row[0].prefix}link IveMemory)`},
  415. { name: `${row[0].prefix}unlink`, value: `désassocie votre compte (${row[0].prefix}unlink)`},
  416. { name: `${row[0].prefix}drop`, value: `vous donne une ville aléatoire ou vous et votre équipe devez drop.`},
  417. { name: `${row[0].prefix}roulette`, value: `vous donne une ville aléatoire et un défi.`},
  418. { name: `${row[0].prefix}ldefi`, value: `montre la liste des défis possible`},
  419. { name: `${row[0].prefix}info`, value: `donne des infos supplémentaire sur le bot`},
  420. ]
  421. }
  422. });
  423. });
  424. });
  425. con.end();
  426. }
  427. if(command === "adefi") {
  428. if(message.member.roles.find("name", "Bot")){
  429. let con = mysql.createConnection({
  430. host: "localhost",
  431. user: "root",
  432. password: "",
  433. database: "guilds"
  434. });
  435. con.connect(function(err) {
  436. if (err) throw err;
  437. con.query("INSERT INTO defis (defi, serverID) VALUES ('" + args.join().replace(/\,/g, ' ') + "', '" + client.guilds.get(message.guild.id).id + "')", function (err, row) {
  438. message.channel.send("Vous avez bien ajouter le défi!");
  439. });
  440. });
  441. con.end();
  442. }
  443. else {
  444.  
  445. }
  446. }
  447. });
  448. });
  449. con.end();
  450. });
  451. client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement