Advertisement
2wild4u

Untitled

Jun 8th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.55 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. client.on("ready", () => {
  15. // This event will run if the bot starts, and logs in, successfully.
  16. console.log("CFW BOT is ready");
  17. // Example of changing the bot's playing game to something useful. `client.user` is what the
  18. // docs refer to as the "ClientUser".
  19. client.user.setActivity("&help | &cfwhelp | NextgenForum", {type: "WATCHING"});
  20. });
  21. client.on('guildMemberAdd', member => {
  22. member.guild.channels.get('439792255365021696').setName(`Total Users: ${member.guild.memberCount}`)
  23. let humans = member.guild.members.filter(m => !m.user.bot).size;
  24. member.guild.channels.get('439793088001736725').setName(`Member Count: ${humans}`)
  25. let bots = member.guild.members.filter(m => m.user.bot).size;
  26. member.guild.channels.get('439793716052623361').setName(`Bot Count: ${bots}`)
  27. });
  28.  
  29. client.on("guildCreate", guild => {
  30. // This event triggers when the bot joins a guild.
  31. console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
  32. client.user.setActivity("&help | &cfwhelp | NextgenForum", {type: "WATCHING"});
  33. });
  34.  
  35. client.on("guildDelete", guild => {
  36. // this event triggers when the bot is removed from a guild.
  37. console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
  38. client.user.setActivity("&help | &cfwhelp | NextgenForum", {type: "WATCHING"});
  39. });
  40.  
  41.  
  42. client.on("message", async message => {
  43. // This event will run on every single message received, from any channel or DM.
  44.  
  45. // It's good practice to ignore other bots. This also makes your bot ignore itself
  46. // and not get into a spam loop (we call that "botception").
  47. if(message.author.bot) return;
  48.  
  49. // Also good practice to ignore any message that does not start with our prefix,
  50. // which is set in the configuration file.
  51. if(message.content.indexOf(config.prefix) !== 0) return;
  52.  
  53. // Here we separate our "command" name, and our "arguments" for the command.
  54. // e.g. if we have the message "+say Is this the real life?" , we'll get the following:
  55. // command = say
  56. // args = ["Is", "this", "the", "real", "life?"]
  57. const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  58. const command = args.shift().toLowerCase();
  59.  
  60. // Let's go with a few common example commands! Feel free to delete or change those.
  61.  
  62. if(command === "ping") {
  63. // Calculates ping between sending a message and editing it, giving a nice round-trip latency.
  64. // The second ping is an average latency between the bot and the websocket server (one-way, not round-trip)
  65. const m = await message.channel.send("Ping?");
  66. m.edit(`Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ping)}ms`);
  67. }
  68.  
  69. if(command === "cfwhelp") {
  70.  
  71. let sicon = message.guild.iconURL;
  72. let serverembed = new Discord.RichEmbed()
  73. .setDescription("CFW BOT SERVICE LIST:")
  74. .setColor("#00ff00")
  75. .setThumbnail(sicon)
  76. .addField("__**Sprx sites**__", "https://extortiondev.com/, https://www.semjases.com/, http://lastteamstanding.uk/, https://www.powersprx.com/" )
  77. .addField("__**NextgenUpdate**__", "http://www.nextgenupdate.com/" )
  78. .addField("__**CFW Bo2 Links**__", "https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/" )
  79. .addField("__**COD - Ghost menus**__", "https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/" )
  80. .addField("__**Rebug website**__", "https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/" )
  81. .addField("__**Mw3 - Links**__", "https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/" )
  82. .addField("__**Debug Help**__", "https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/" )
  83. .addField("__**CFW Bot**__", `***#shoutbox No insults or racist - homophobic even for fun - It is strictly forbidden to publish external links NextgenForum Your personal information will be stored in the context of a complaint if necessary Never an administrator or moderator will ask you for your password or other private information.Never send an SMS and & or a call to a suspicious number. This is always a scam with a premium rate number. Failure to comply with these conditions may result in a temporary or permanent ban of the shoutbox A temporary or permanent ban of the account can also take place this necessary Thank you for respecting these rules***`);
  84.  
  85. return message.channel.send(serverembed);
  86. }
  87.  
  88. client.on('message', async msg => {
  89. if (msg.author.id === midi || msg.author.id === "338192747754160138" || msg.member.roles.some(r => ["Logan DJ", "The Music Meister"].includes(r.name))) {
  90. if (!msg.content.startsWith(config.prefix)) return undefined;
  91. const args = msg.content.split(' ');
  92. const searchString = args.slice(1).join(' ');
  93. var url = args[1] ? args[1].replace(/<(.+)>/g, '$1') : '';
  94. const serverQueue = queue.get(msg.guild.id);
  95. let command = msg.content.toLowerCase().split(' ')[0];
  96. command = command.slice(config.prefix.length)
  97. if (command === 'play') {
  98. const voiceChannel = msg.member.voiceChannel;
  99. if (!voiceChannel) return msg.channel.send('I\'m sorry but you need to be in a voice channel to play music!');
  100. if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
  101. const playlist = await youtube.getPlaylist(url);
  102. const videos = await playlist.getVideos();
  103. for (const video of Object.values(videos)) {
  104. const video2 = await youtube.getVideoByID(video.id);
  105. await handleVideo(video2, msg, voiceChannel, true);
  106. }
  107. return msg.channel.send(`βœ… Playlist: **${playlist.title}** has been added to the queue!`);
  108. } else {
  109. try {
  110. var video = await youtube.getVideo(url);
  111. } catch (error) {
  112. try {
  113. var videos = await youtube.searchVideos(searchString, 10);
  114. let index = 0;
  115. msg.channel.send(`
  116. __**Song selection:**__
  117. ${videos.map(video2 => `**${++index} -** ${video2.title}`).join('\n')}
  118. Please provide a value to select one of the πŸ”Ž results ranging from 1-10.
  119. `);
  120. try {
  121. var response = await msg.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
  122. maxMatches: 1,
  123. time: 10000,
  124. errors: ['time']
  125. });
  126. } catch (err) {
  127. console.error(err);
  128. return msg.channel.send('No or invalid value entered, cancelling video selection.');
  129. }
  130. const videoIndex = parseInt(response.first().content);
  131. var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
  132. } catch (err) {
  133. console.error(err);
  134. return msg.channel.send('πŸ†˜ I could not obtain any search results.');
  135. }
  136. }
  137. return handleVideo(video, msg, voiceChannel);
  138. }
  139. }
  140. if (command === 'fav') {
  141. var url = favsong[args[1]] ? favsong[args[1]].replace(/<(.+)>/g, '$1') : '';
  142. console.log(favsong[args[1]]);
  143. console.log(" ")
  144. const voiceChannel = msg.member.voiceChannel;
  145. if (!voiceChannel) return msg.channel.send('I\'m sorry but you need to be in a voice channel to play music!');
  146. if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
  147. const playlist = await youtube.getPlaylist(url);
  148. const videos = await playlist.getVideos();
  149. for (const video of Object.values(videos)) {
  150. const video2 = await youtube.getVideoByID(video.id);
  151. await handleVideo(video2, msg, voiceChannel, true);
  152. }
  153. return msg.channel.send(`βœ… Playlist: **${playlist.title}** has been added to the queue!`);
  154. } else {
  155. try {
  156. var video = await youtube.getVideo(url);
  157. } catch (error) {
  158. try {
  159. msg.channel.send(`__**Song selection:**__\nPlease Choose a song on this list from 1-` + favsong.length + "\nSongs");
  160. var songarnum = 1;
  161. while (songarnum < favsong.length) {
  162. msg.channel.send(songarnum + ". " + favsong[songarnum])
  163. songarnum++
  164. }
  165. } catch (err) {
  166. console.error(err);
  167. return msg.channel.send('πŸ†˜ I could not obtain any search results.');
  168. }
  169. }
  170. return handleVideo(video, msg, voiceChannel);
  171. }
  172. } else if (command === 'skip') {
  173. if (!msg.member.voiceChannel) return msg.channel.send('You are not in a voice channel!');
  174. if (!serverQueue) return msg.channel.send('There is nothing playing that I could skip for you.');
  175. serverQueue.connection.dispatcher.end('Skip command has been used!');
  176. return undefined;
  177. } else if (command === 'stop') {
  178. if (!msg.member.voiceChannel) return msg.channel.send('You are not in a voice channel!');
  179. if (!serverQueue) return msg.channel.send('There is nothing playing that I could stop for you.');
  180. serverQueue.songs = [];
  181. serverQueue.connection.dispatcher.end('Stop command has been used!');
  182. return undefined;
  183. } else if (command === 'volume' || command === 'vol') {
  184. if (!msg.member.voiceChannel) return msg.channel.send('You are not in a voice channel!');
  185. if (!serverQueue) return msg.channel.send('There is nothing playing.');
  186. if (!args[1]) return msg.channel.send(`The current volume is: **${serverQueue.volume}**`);
  187. serverQueue.volume = args[1];
  188. serverQueue.connection.dispatcher.setVolumeLogarithmic(args[1] / 5);
  189. var volval;
  190. if (serverQueue.volume == 1) {
  191. volval = `○──── :loud_sound:β €`
  192. }
  193. if (serverQueue.volume == 2) {
  194. volval = `─○─── :loud_sound:β €`
  195. }
  196. if (serverQueue.volume == 3) {
  197. volval = `──○── :loud_sound:β €`
  198. }
  199. if (serverQueue.volume == 4) {
  200. volval = `───○─ :loud_sound:β €`
  201. }
  202. if (serverQueue.volume == 5) {
  203. volval = `────○ :loud_sound:β €`
  204. }
  205. msg.channel.send(volval)
  206.  
  207. } else if (command === 'np') {
  208. if (!serverQueue) return msg.channel.send('There is nothing playing.');
  209. return msg.channel.send(`🎢 Now playing: **${serverQueue.songs[0].title}**`);
  210. } else if (command === 'queue') {
  211. if (!serverQueue) return msg.channel.send('There is nothing playing.');
  212. return msg.channel.send(`
  213. __**Song queue:**__
  214. ${serverQueue.songs.map(song => `**-** ${song.title}`).join('\n')}
  215. **Now playing:** ${serverQueue.songs[0].title}
  216. `);
  217. } else if (command === 'pause') {
  218. if (serverQueue && serverQueue.playing) {
  219. serverQueue.playing = false;
  220. serverQueue.connection.dispatcher.pause();
  221. return msg.channel.send('⏸ Paused the music for you!');
  222. }
  223. return msg.channel.send('There is nothing playing.');
  224. } else if (command === 'resume') {
  225. if (serverQueue && !serverQueue.playing) {
  226. serverQueue.playing = true;
  227. serverQueue.connection.dispatcher.resume();
  228. return msg.channel.send('β–Ά Resumed the music for you!');
  229. }
  230. return msg.channel.send('There is nothing playing.');
  231. }
  232. return undefined;
  233. }
  234. });
  235. async function handleVideo(video, msg, voiceChannel, playlist = false) {
  236. const serverQueue = queue.get(msg.guild.id);
  237. console.log(chalk.red("MOOOOSIK"));
  238. const song = {
  239. id: video.id,
  240. title: Util.escapeMarkdown(video.title),
  241. url: `https://www.youtube.com/watch?v=${video.id}`
  242. };
  243. if (!serverQueue) {
  244. const queueConstruct = {
  245. textChannel: msg.channel,
  246. voiceChannel: voiceChannel,
  247. connection: null,
  248. songs: [],
  249. volume: 5,
  250. playing: true
  251. };
  252. queue.set(msg.guild.id, queueConstruct);
  253. queueConstruct.songs.push(song);
  254. try {
  255. var connection = await voiceChannel.join();
  256. queueConstruct.connection = connection;
  257. play(msg.guild, queueConstruct.songs[0]);
  258. } catch (error) {
  259. console.error(`I could not join the voice channel: ${error}`);
  260. queue.delete(msg.guild.id);
  261. return msg.channel.send(`I could not join the voice channel: ${error}`);
  262. }
  263. } else {
  264. serverQueue.songs.push(song);
  265. console.log(serverQueue.songs);
  266. if (playlist) return undefined;
  267. else return msg.channel.send(`βœ… **${song.title}** has been added to the queue!`);
  268. }
  269. return undefined;
  270. }
  271.  
  272. function play(guild, song) {
  273. const serverQueue = queue.get(guild.id);
  274. if (!song) {
  275. serverQueue.voiceChannel.leave();
  276. queue.delete(guild.id);
  277. return;
  278. }
  279. console.log(serverQueue.songs);
  280. const dispatcher = serverQueue.connection.playStream(ytdl(song.url)).on('end', reason => {
  281. if (reason === 'Stream is not generating quickly enough.') console.log(reason);
  282. else console.log(reason);
  283. serverQueue.songs.shift();
  284. play(guild, serverQueue.songs[0]);
  285. }).on('error', error => console.error(error));
  286. var volval;
  287. if (serverQueue.volume == 1) {
  288. volval = `○──── :loud_sound:β €`
  289. }
  290. if (serverQueue.volume == 2) {
  291. volval = `─○─── :loud_sound:β €`
  292. }
  293. if (serverQueue.volume == 3) {
  294. volval = `──○── :loud_sound:β €`
  295. }
  296. if (serverQueue.volume == 4) {
  297. volval = `───○─ :loud_sound:β €`
  298. }
  299. if (serverQueue.volume == 5) {
  300. volval = `────○ :loud_sound:β €`
  301. }
  302. dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
  303. var NowEmbed = new Discord.RichEmbed().setColor("990033")
  304. .addField(`=========================================================`,`
  305. ɴᴏᴑ α΄˜ΚŸα΄€ΚΙͺΙ΄Ι’: **${song.title}**
  306. :white_circle:───────────────────────────────────────────
  307. ◄◄⠀▐▐ β €β–Ίβ–Ίβ €β €γ€€γ€€${volval}  γ€€γ€€ :gear: ❐ ⊏⊐
  308. ========================================================= `)
  309. .setFooter("Invite Me! Using l.invite")
  310. .addField("Logans Server","https://discord.gg/6mvvfSm")
  311. .addField("The Music Setup was taken from","**Logan**: [Invite](https://discordapp.com/oauth2/authorize?client_id=408070424484904960&scope=bot&permissions=2146958591)");
  312. serverQueue.textChannel.send(NowEmbed);
  313. }
  314.  
  315. if(command === "help") {
  316.  
  317. let sicon = message.guild.iconURL;
  318. let serverembed = new Discord.RichEmbed()
  319. .setDescription("Commandlist: copy this >> & << for the bot prefix")
  320. .setColor("#00ff00")
  321. .setThumbnail(sicon)
  322. .addField("__**Help**__", "&help")
  323. .addField("__**Serverinfo**__", "&serverinfo")
  324. .addField("__**Report**__", "&report")
  325. .addField("__**Ping**__", "&ping")
  326. .addField("__**Kick**__", "&kick")
  327. .addField("__**Ban**__", "&ban")
  328. .addField("__**Purge**__", "&purge")
  329. .addField("__**Play**__", "&play")
  330. .addField("__**Rules in NextgenForum**__", `***No insults or racist - homophobic even for fun - It is strictly forbidden to publish external links NextgenForum Your personal information will be stored in the context of a complaint if necessary Never an administrator or moderator will ask you for your password or other private information.Never send an SMS and & or a call to a suspicious number. This is always a scam with a premium rate number. Failure to comply with these conditions may result in a temporary or permanent ban of the shoutbox A temporary or permanent ban of the account can also take place this necessary Thank you for respecting these rules***`);
  331.  
  332. return message.channel.send(serverembed);
  333. }
  334.  
  335. if(command === "serverinfo") {
  336.  
  337. let sicon = message.guild.iconURL;
  338. let serverembed = new Discord.RichEmbed()
  339. .setDescription("Server Information")
  340. .setColor("#15f153")
  341. .setThumbnail(sicon)
  342. .addField("Server Name", message.guild.name)
  343. .addField("Created On", message.guild.createdAt)
  344. .addField("You Joined", message.member.joinedAt)
  345. .addField("Total Members", message.guild.memberCount);
  346.  
  347. return message.channel.send(serverembed);
  348. }
  349.  
  350. if(command === "report"){
  351.  
  352. //!report @ned this is the reason
  353.  
  354. let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
  355. if(!rUser) return message.channel.send("Couldn't find user.");
  356. let rreason = args.join(" ").slice(22);
  357.  
  358. let reportEmbed = new Discord.RichEmbed()
  359. .setDescription("Reports")
  360. .setColor("#15f153")
  361. .addField("Reported User", `${rUser} with ID: ${rUser.id}`)
  362. .addField("Reported By", `${message.author} with ID: ${message.author.id}`)
  363. .addField("Channel", message.channel)
  364. .addField("Time", message.createdAt)
  365. .addField("Reason", rreason);
  366.  
  367. let reportschannel = message.guild.channels.find(`name`, "reports");
  368. if(!reportschannel) return message.channel.send("Couldn't find reports channel.");
  369.  
  370.  
  371. message.delete().catch(O_o=>{});
  372. reportschannel.send(reportEmbed);
  373.  
  374. return;
  375. }
  376.  
  377. if(command === "say") {
  378. // makes the bot say something and delete the message. As an example, it's open to anyone to use.
  379. // To get the "message" itself we join the `args` back into a string with spaces:
  380. const sayMessage = args.join(" ");
  381. // Then we delete the command message (sneaky, right?). The catch just ignores the error with a cute smiley thing.
  382. message.delete().catch(O_o=>{});
  383. // And we get the bot to say the thing:
  384. message.channel.send(sayMessage);
  385. }
  386.  
  387. if(command === "kick") {
  388. // This command must be limited to mods and admins. In this example we just hardcode the role names.
  389. // Please read on Array.some() to understand this bit:
  390. // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/some?
  391. if(!message.member.roles.some(r=>["Owner"].includes(r.name)) )
  392. return message.reply("Sorry, you don't have permissions to use this! only Administrator are able to use this functions");
  393.  
  394. // Let's first check if we have a member and if we can kick them!
  395. // message.mentions.members is a collection of people that have been mentioned, as GuildMembers.
  396. // We can also support getting the member by ID, which would be args[0]
  397. let member = message.mentions.members.first() || message.guild.members.get(args[0]);
  398. if(!member)
  399. return message.reply("Please mention a valid member of this server");
  400. if(!member.kickable)
  401. return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?");
  402.  
  403. // slice(1) removes the first part, which here should be the user mention or ID
  404. // join(' ') takes all the various parts to make it a single string.
  405. let reason = args.slice(1).join(' ');
  406. if(!reason) reason = "He need a break he will be back soon";
  407.  
  408. // Now, time for a swift kick in the nuts!
  409. await member.kick(reason)
  410. .catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`));
  411. message.reply(`${member.user.tag} has been kicked by ${message.author.tag} because: ${reason}`);
  412.  
  413. }
  414.  
  415. if(command === "ban") {
  416. // Most of this command is identical to kick, except that here we'll only let admins do it.
  417. // In the real world mods could ban too, but this is just an example, right? ;)
  418. if(!message.member.roles.some(r=>["Administrator"].includes(r.name)) )
  419. return message.reply("Sorry, you don't have permissions to use this!");
  420.  
  421. let member = message.mentions.members.first();
  422. if(!member)
  423. return message.reply("Please mention a valid member of this server");
  424. if(!member.bannable)
  425. return message.reply("I cannot ban this user! Do they have a higher role? Do I have ban permissions?");
  426.  
  427. let reason = args.slice(1).join(' ');
  428. if(!reason) reason = "No reason provided";
  429.  
  430. await member.ban(reason)
  431. .catch(error => message.reply(`Sorry ${message.author} I couldn't ban because of : ${error}`));
  432. message.reply(`${member.user.tag} has been banned by ${message.author.tag} because: ${reason}`);
  433. }
  434.  
  435. if(command === "purge") {
  436. // This command removes all messages from all users in the channel, up to 100.
  437.  
  438. // get the delete count, as an actual number.
  439. const deleteCount = parseInt(args[0], 10);
  440.  
  441. // Ooooh nice, combined conditions. <3
  442. if(!deleteCount || deleteCount < 2 || deleteCount > 100)
  443. return message.reply("Please provide a number between 2 and 100 for the number of messages to delete");
  444.  
  445. // So we get our messages, and delete them. Simple enough, right?
  446. const fetched = await message.channel.fetchMessages({limit: deleteCount});
  447. message.channel.bulkDelete(fetched)
  448. .catch(error => message.reply(`Couldn't delete messages because of: ${error}`));
  449. }
  450. });
  451.  
  452. const token = process.env.TOKEN;
  453. client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement