Guest User

Untitled

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