gaber-elsayed

TOP VOICE & TEXT LIKE PROBOT

Aug 20th, 2019
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.76 KB | None | 0 0
  1. const pretty = require("pretty-ms");
  2.  
  3. const Discord = require("discord.js");
  4. const moment = require('moment');
  5. const client = new Discord.Client();
  6. const bot = new Discord.Client();
  7. const hero = client;
  8. const fs = require("fs");
  9. botconfig = JSON.parse(fs.readFileSync('./jsonfile/botconfig.json', 'utf8'));
  10. client.login(botconfig.token)
  11. const ms = require("ms");
  12. client.on('ready', () => {
  13. console.log(`Logged in as ${client.user.tag}!`);
  14. });
  15. const prefix = botconfig.prefix
  16.  
  17.  
  18.  
  19. var mysql = require("mysql")
  20.  
  21. var db_config = {
  22. host: "localhost",
  23. user: "root",
  24. password: "SSbboott11",
  25. database: "SBot"
  26. }
  27. var con;
  28. client.on('warn', console.warn);
  29.  
  30. client.on('error', console.error);
  31.  
  32. function handleDisconnect() {
  33. con = mysql.createConnection(db_config);
  34.  
  35. con.connect(function(err) {
  36. if(err) {
  37. console.log("IJS Found error to connect to the database: ", err);
  38. setTimeout(handleDisconnect, 2000);
  39. } else {
  40. console.log("\033[92m%s\x1b[0m", "Success: " + "\x1b[0mIJS - Database connected successfully!");
  41. }
  42.  
  43. });
  44. con.on('error', function(err) {
  45. console.log('db error');
  46. if(err.code === 'PROTOCOL_CONNECTION_LOST') {
  47. handleDisconnect();
  48. } else {
  49. throw err;
  50. }
  51. });
  52. }
  53.  
  54. handleDisconnect();
  55.  
  56. client.on('message', async function(message) {
  57. const cmd = (a,b,c,d) => {
  58. return;
  59. }
  60. if(message.author.bot) return;
  61. if(message.channel.type === 'dm') return;
  62. con.query(`SELECT * FROM top WHERE gid = '${message.guild.id}' AND id = '${message.author.id}'`, (e, rows) => {
  63. if(e) throw e;
  64. if(!rows || !rows[0] || rows.lenght < 0) {
  65. con.query(`INSERT INTO top (id, gid, txp) VALUES ('${message.author.id}', '${message.guild.id}', 1)`);
  66. } else {
  67. if(message.content === "confirm") return;
  68. con.query(`UPDATE top SET txp = ${parseInt(rows[0].txp)+1} WHERE id = '${message.author.id}' AND gid = '${message.guild.id}'`)
  69. }
  70. })
  71. if(message.content.toLowerCase() === prefix + "top") {
  72. cmd("top", "Send a leaderboard for all active members in the server", "top", "Info");
  73. //
  74. con.query(`SELECT * FROM top WHERE gid = '${message.guild.id}' ORDER BY txp DESC`, (e, rows) => {
  75. con.query(`SELECT * FROM top WHERE gid = '${message.guild.id}' ORDER BY vxp DESC`, (e, rowa) => {
  76. var text = '';
  77. var voice = '';
  78. for(var i = 0; i < 5; i++) {
  79. if(rows[i]) {
  80. let user = client.users.get(rows[i].id);
  81.  
  82. let is = '';
  83. if(rows[i].id == message.author.id) {
  84. is = "**"
  85. } else {
  86. is = '';
  87. }
  88.  
  89. text += `${is}#${parseInt(i)+1} | <@${rows[i].id}> XP: \`${rows[i].txp}\`${is}\n`
  90.  
  91. }
  92. }
  93. for(var i = 0; i < 5; i++) {
  94. if(rowa[i]) {
  95. let user = client.users.get(rowa[i].id);
  96.  
  97. let is = '';
  98. if(rowa[i].id == message.author.id) {
  99. is = "**"
  100. } else {
  101. is = '';
  102. }
  103. voice += `${is}#${parseInt(i)+1} | <@${rowa[i].id}> XP: \`${rowa[i].vxp}\`${is}\n`
  104.  
  105. }
  106. }
  107.  
  108.  
  109. const embed2 = new Discord.RichEmbed()
  110.  
  111. .setAuthor("📋 | Guild Score Leaderboards", message.guild.iconURL)
  112. .setColor(" #191919")
  113. .addField(`**:speech_balloon: | TOP 5 TEXT**`, `${text} \n **:thinking: | For More: \`${prefix}top text\`**`, true)
  114. .addField("**:microphone2: | TOP 5 VOICE**", `${voice} \n **:thinking: | For More: \`${prefix}top voice\`**`, true)
  115. .setFooter(message.author.tag, message.author.displayAvatarURL)
  116.  
  117. message.channel.send(embed2)
  118.  
  119. })
  120. })
  121. }
  122. if(message.content.toLowerCase() === (prefix + 'top text')) {
  123. cmd("top text", "Send a leaderboard for all active members in the server", "top text", "Info");
  124. con.query(`SELECT * FROM top WHERE gid = '${message.guild.id}' ORDER BY txp DESC`, (e, rows) => {
  125. var text = '';
  126.  
  127. {
  128. for (var i = 0; i < 10; i++) {
  129.  
  130. if(rows[i]) {
  131. let user = client.users.get(rows[i].id);
  132.  
  133. let is = '';
  134. if(rows[i].id == message.author.id) {
  135. is = "**"
  136. } else {
  137. is = '';
  138. }
  139.  
  140.  
  141. text += `${is}#${parseInt(i)+1} <@${rows[i].id}> XP: \`${rows[i].txp}\`${is}\n`
  142.  
  143. }
  144. }
  145.  
  146. const embed2 = new Discord.RichEmbed()
  147.  
  148. .setAuthor("📋 | Guild Score Leaderboards", message.guild.iconURL)
  149. .setColor(" #191919")
  150. .addField(`**:speech_balloon: | TEXT LEADERBOARD**`, `${text}`, true)
  151.  
  152. .setFooter(message.author.tag, message.author.displayAvatarURL)
  153.  
  154. message.channel.send(embed2)
  155. }
  156. })
  157. }
  158. if(message.content.toLowerCase() === (prefix + 'top voice')) {
  159. cmd("top voice", "Send a leaderboard for all active members in the server", "top voice", "Info");
  160. con.query(`SELECT * FROM top WHERE gid = '${message.guild.id}' ORDER BY vxp DESC`, (e, rows) => {
  161. var text = '';
  162. var voice = '';
  163. for(var i = 0; i < 10; i++){
  164. if(rows[i]) {
  165. let user = client.users.get(rows[i].id);
  166.  
  167. let is = '';
  168. if(rows[i].id == message.author.id) {
  169. is = "**"
  170. } else {
  171. is = '';
  172. }
  173.  
  174.  
  175. text += `${is}#${parseInt(i)+1} <@${rows[i].id}> XP: \`${rows[i].vxp}\`${is}\n`
  176.  
  177. }
  178. }
  179. const embed2 = new Discord.RichEmbed()
  180.  
  181. .setAuthor("📋 | Guild Score Leaderboards", message.guild.iconURL)
  182. .setColor(" #191919")
  183. .addField(`**:microphone2: | VOICE LEADERBOARD**`, `${text}`, true)
  184.  
  185. .setFooter(message.author.tag, message.author.displayAvatarURL)
  186.  
  187. message.channel.send(embed2)
  188.  
  189. })
  190. }
  191.  
  192. con.query(`SELECT * FROM top WHERE gid='${message.guild.id}'`, (err, rows) => {
  193. if(message.content === prefix + "reset all") {
  194. if(!message.member.hasPermission("MANAGE_GUILD")) return;
  195. message.channel.send("**:warning: | لتأكيد عملية تصفير جميع النقاط , قم بكتابة : ```confirm```**").then(async msg => {
  196. try{
  197. let conf = await message.channel.awaitMessages(m => m.content === "confirm", { max: 1, time: 20000, errors: ["time"]}).then(c => {
  198. message.delete();
  199. msg.edit(`** | تم تصفير جميع النقاط**`);
  200. con.query(`UPDATE top SET txp=0 WHERE gid = '${message.guild.id}'`)
  201. con.query(`UPDATE top SET txp=0 WHERE gid = '${message.guild.id}' AND id='${message.author.id}'`)
  202. con.query(`UPDATE top SET vxp=0 WHERE gid = '${message.guild.id}'`)
  203. con.query(`UPDATE top SET vxp=0 WHERE gid = '${message.guild.id}' AND id='${message.author.id}'`)
  204.  
  205. })
  206. } catch(e) {
  207. message.delete();
  208. }
  209. })
  210. }
  211. if(message.content === prefix + "reset text") {
  212. if(!message.member.hasPermission("MANAGE_MESSAGES")) return;
  213. message.channel.send("**:warning: | لتأكيد عملية تصفير جميع النقاط الكتابية , قم بكتابة : ```confirm```**").then(async msg => {
  214. try{
  215. let conf = await message.channel.awaitMessages(m => m.content === "confirm", { max: 1, time: 20000, errors: ["time"]}).then(c => {
  216. message.delete();
  217. msg.edit(`** | تم تصفير جميع النقاط**`);
  218. con.query(`UPDATE top SET txp=0 WHERE gid = '${message.guild.id}'`)
  219. con.query(`UPDATE top SET txp=0 WHERE gid = '${message.guild.id}' AND id='${message.author.id}'`)
  220.  
  221.  
  222. })
  223. } catch(e) {
  224. message.delete();
  225. }
  226. })
  227. }
  228. if(message.content === prefix + "reset voice") {
  229. if(!message.member.hasPermission("MANAGE_CHANNELS")) return;
  230. message.channel.send("**:warning: | لتأكيد عملية تصفير جميع النقاط الكتابية , قم بكتابة : ```confirm```**").then(async msg => {
  231. try{
  232. let conf = await message.channel.awaitMessages(m => m.content === "confirm", { max: 1, time: 20000, errors: ["time"]}).then(c => {
  233. message.delete();
  234. msg.edit(`** | تم تصفير جميع النقاط**`);
  235.  
  236. con.query(`UPDATE top SET vxp=0 WHERE gid = '${message.guild.id}'`)
  237. con.query(`UPDATE top SET vxp=0 WHERE gid = '${message.guild.id}' AND id='${message.author.id}'`)
  238.  
  239. })
  240. } catch(e) {
  241. message.delete();
  242. }
  243. })
  244. }
  245. })
  246. })
Advertisement
Add Comment
Please, Sign In to add comment