Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const bot = new Discord.Client();
- const weather = require('weather-js'); //Make sure you call the packages you install.
- const fs = require('fs'); //But we also need to require the fs package.
- const Langs = ['afrikaans','albanian','amharic','arabic','armenian','azerbaijani','bangla','basque','belarusian','bengali','bosnian','bulgarian','burmese','catalan','cebuano','chichewa','chinese-simplified','chinese-traditional','corsican','croatian','czech','danish','dutch','english','esperanto','estonian','filipino','finnish','french','frisian','galician','georgian','german','greek','gujarati','haitian creole','hausa','hawaiian','hebrew','hindi','hmong','hungarian','icelandic','igbo','indonesian','irish','italian','japanese','javanese','kannada','kazakh','khmer','korean','kurdish (kurmanji)','kyrgyz','lao','latin','latvian','lithuanian','luxembourgish','macedonian','malagasy','malay','malayalam','maltese','maori','marathi','mongolian','myanmar (burmese)','nepali','norwegian','nyanja','pashto','persian','polish','portugese','punjabi','romanian','russian','samoan','scottish gaelic','serbian','sesotho','shona','sindhi','sinhala','slovak','slovenian','somali','spanish','sundanese','swahili','swedish','tajik','tamil','telugu','thai','turkish','ukrainian','urdu','uzbek','vietnamese','welsh','xhosa','yiddish','yoruba','zulu'];
- const translate = require('google-translate-api');
- const ms = require("ms");
- let warns = JSON.parse(fs.readFileSync("Storage/warnings.json", "utf8"));
- //We can call the JSON file here
- const commands = JSON.parse(fs.readFileSync('Storage/commands.json', 'utf8'));
- //Bot settings - Global settings this file can use.
- const prefix = '!'; //This is the prefix, you can changeg it to whatever you want.
- bot.msgs = require ("./Storage/msgs.json");
- let streams = JSON.parse(fs.readFileSync("./Storage/streams.json", "utf8"));
- //Listener Event: Runs whenever a message is received.
- bot.on('message', message => {
- //Variables - Variables make it easy to call things, since it requires less typing.
- let msg = message.content.toUpperCase(); // This variable takes the messages, and turns it all into uppercase so it isn't case sensitive.
- let sender = message.author; // This variable takes the message, and finds who the author is.
- let cont = message.content.slice(prefix.length).split(" "); //This variable slices off the prefix then puts the rest in an array based off the spaces
- let args = cont.slice(1); //This slices off the command in a cont, only leaving the arguments.
- //time command
- if (msg.startsWith(prefix + 'TIME')) {
- let timeZone = args[0];
- // if (timeZone === 'NEOPIA/STANDARD') timeZone = 'AMERICA/VANCOUVER';
- try {
- const time = new Date().toLocaleTimeString('en-US', {timeZone});
- return message.channel.send(`The current time in ${timeZone} is ${time}.`);
- } catch (err) {
- return message.channel.send('Invalid time zone. Refer to <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>.');
- }
- }
- //Usefull links Command
- if (msg === prefix + 'LINKS') {
- let linksEmbed = new Discord.RichEmbed()
- .setDescription("Useful LoA2 Links")
- .setColor("#e56b00")
- .addField("LoA2 GTA main Page: http://loa2.gtarcade.com/", "Main Page for LOA2")
- .addField("LoA2 Support Page: https://support.gtarcade.com/search?gid=160", "GTA Support Page for Tickets")
- .addField("LoA2 Facebook Page: https://www.facebook.com/LeagueOfAngels2/", "LOA2 Facebook Fanpage")
- message.author.send(linksEmbed)
- }
- if (msg === prefix + 'LINKSA') {
- let test = new Discord.RichEmbed()
- .setDescription("Streaming Info")
- .setColor("#e56b00")
- .addField("Streamer", "Ulothar GTA Sr Modr")
- .addField("Total Streams", "3")
- .addField("Total Duration", "270")
- message.author.send(test)
- }
- //Ping Command
- if (msg === prefix + 'PING') { // This checks if msg (the message but in all caps), is the same as the prefix ++ the command in all caps
- //Now, let's send a response.
- message.channel.send('Pong!'); // This 'sends' a ping
- }
- // mute starts here
- //!tempmute @user 1s/m/h/d
- if (msg.startsWith(prefix + 'MUTE')) {
- let muterole = message.guild.roles.find(`name`, "muted");
- let tomute = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
- if(!muterole){ // we start creating a role for the muted people
- try{
- muterole = message.guild.createRole({ // we must create a role for the muted people
- name: "muted",
- color: "#000000",
- permissions:[]
- })
- message.guild.channels.forEach(async (channel, id) => {
- await channel.overwritePermission(muterole, {
- SEND_MESSAGES: false, // Muted people should not be able to send messages
- ADD_REACTIONS: false // Muted people should not be able to add reactions
- });
- });
- }catch(e){
- console.log(e.stack);
- }
- }
- //end of create role
- let mutetime = args[1];
- if(!mutetime) return message.reply("You didn't specify a time!");
- tomute.addRole(muterole.id);
- message.reply(`<@${tomute.id}> has been muted for ${ms(mutetime)}`);
- setTimeout(function(){
- tomute.removeRole(muterole.id);
- message.channel.send(`<@${tomute.id}> has been unmuted!`);
- }, ms(mutetime));
- }
- // end of module
- // mute ends here
- // Translator starts here
- if (msg.startsWith(prefix + 'TRANSLATE')) {
- let transArg = args[0];
- args = args.join(' ').slice(prefix.length);
- let translation;
- if (!Langs.includes(transArg)) return message.channel.send(`**There was an error. Command syntax is !translate <language> <text> .**`);
- args = args.slice(transArg.length);
- translate(args, {to: transArg}).then(res => {
- const embed = new Discord.RichEmbed()
- .setDescription(res.text)
- .setFooter(`english -> ${transArg}`)
- .setColor(`RANDOM`);
- return message.channel.send(embed);
- })
- }
- // Translator ends here
- // Test with new stuff starts here
- if (msg.startsWith(prefix + 'RUNESTONE TRANSMUTE')) {
- let thumbb = "https://image.ibb.co/fnJ5WJ/runestone.png"
- let runtranEmbed = new Discord.RichEmbed()
- .setDescription("Runestone Transmute Materials")
- .setAuthor(message.author.username)
- .setColor("#5858FA")
- .setThumbnail(thumbb)
- .addField("R1-2 ", "Min 31, Max 35")
- .addField("R2-3 ", "Min 67, Max 84")
- .addField("R3-4 ", "Min 151, Max 179")
- .addField("R4-5 ", "Min 290, Max 345")
- .addField("R5-6 ", "Min 521, Max 568")
- .addField("R6-7 ", "Min 962, Max 1.054")
- .addField("R7-8 ", "Min 1.766, Max 2.090")
- .addField("R8-9 ", "Min 3.002, Max 3.573")
- .addField("R8-9 ", "Min 5.439, Max 6.488")
- .addField("R9-10 ", "Min 5.349, Max 6.488")
- .addField("R10-11 ", "Min 8.470, Max 9.743")
- .addField("R11-12 ", "Min 11.797, Max 14.567")
- .addField("R12-13 ", "Min 15.500, Max 19.080")
- .addField("R13-14 ", "Min 19.842, Max 23.326")
- .addField("R14-15 ", "Min 24.661, Max 24.661")
- .addField("R15-16 ", "Min 30.622, Max 30.622")
- .addField("Total ", "Min 123.031, Max 136.415")
- .addField("Team ", "Min 615.155, Max 682.075")
- message.author.send(runtranEmbed)
- }
- // test with new stuff ends here
- //Warn command starts here
- //!warn @user <reason>
- if (msg.startsWith(prefix + 'WARN')) {
- let wUser = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0])
- if(!wUser) return message.reply("Couldn't find the user");
- if(wUser.hasPermission("MANAGE_MESSAGES")) return message.reply("The user has permissions that avoid to be warned!");
- let reason = args.join(" ").slice(22);
- if(!warns[wUser.id]) warns[wUser.id] = {
- warns: 0
- };
- warns[wUser.id].warns++;
- fs.writeFile("Storage/warnings.json", JSON.stringify(warns), (err) => {
- if (err) console.log(err)
- });
- let warnEmbed = new Discord.RichEmbed()
- .setDescription("Warns")
- .setAuthor(message.author.username)
- .setColor("#fc6400")
- .addField("Warned User", wUser)
- .addField("Warned In", message.channel)
- .addField("Number of Warnings", warns[wUser.id].warns)
- .addField("Reason", reason);
- let warnchannel = message.guild.channels.find(`name`, "incidents");
- if(!warnchannel) return message.reply("Couldn't find channel");
- warnchannel.send(warnEmbed);
- if(warns[wUser.id].warns == 2){
- let muterole = message.guild.roles.find(`name`, "muted");
- if(!muterole) return message.reply("You should create that role first");
- let mutetime = "30s";
- wUser.addRole(muterole.id);
- message.channel.send(`<@${wUser.id}> has been temporarily muted`);
- setTimeout(function(){
- wUser.removeRole(muterole.id);
- message.channel.send(`<@${wUser.id}> has been unmuted`);
- })
- }
- if(warns[wUser.id].warns == 3){
- message.guild.member(wUser).ban(reason);
- message.channel.send(`${wUser.tag} has been banned.`)
- }
- }
- //Warn Command Stop here
- //Command Kick
- if (msg.startsWith(prefix + 'KICK')) { //This checks if msg has the prefix and the kick command right after. The syntax will be !kick @name <reason>
- let kUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
- if(!kUser) return message.channel.send("Can't find user!");
- let kReason = args.join(" ").slice(22);
- if(!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("No permissions for that command!"); //This checks the permissions for the user can change to whatever you want.
- if(kUser.hasPermission("MANAGE_MESSAGES")) return message.channel.send("That person can't be kicked!"); //This option checks if the user to be kicked has MANAGE_MESSAGES permission and in this case he can't be kicked.
- let kickEmbed = new Discord.RichEmbed()
- .setDescription("~Kick~")
- .setColor("#e56b00")
- .addField("Kicked User", `${kUser} with ID ${kUser.id}`)
- .addField("Kicked By", `<@${message.author.id}> with ID ${message.author.id}`)
- .addField("Kicked in", message.channel)
- .addField("Time", message.createdAt)
- .addField("Reason", kReason)
- let kickChannel = message.guild.channels.find(`name`, "incidents"); //This will post the kick message in the channel named Incidents you can change that.
- if(!kickChannel) return message.channel.send("Can't find incidents channel.");
- message.guild.member(kUser).kick(kReason);
- kickChannel.send(kickEmbed);
- return;
- }
- //Ban command start here
- if (msg.startsWith(prefix + 'BAN')) {
- let bUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
- if(!bUser) return message.channel.send("Can't find user!");
- let bReason = args.join(" ").slice(22);
- if(!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("No permissions for that command!"); //This checks the permissions for the user can change to whatever you want.
- if(bUser.hasPermission("MANAGE_MESSAGES")) return message.channel.send("That person can't be kicked!"); //This option checks if the user to be kicked has MANAGE_MESSAGES permission and in this case he can't be kicked.
- let banEmbed = new Discord.RichEmbed()
- .setDescription("~Ban~")
- .setColor("#bc0000")
- .addField("Banned User", `${bUser} with ID ${bUser.id}`)
- .addField("Banned By", `<@${message.author.id}> with ID ${message.author.id}`)
- .addField("Banned in", message.channel)
- .addField("Time", message.createdAt)
- .addField("Reason", bReason)
- let incidentChannel = message.guild.channels.find(`name`, "incidents"); //This will post the kick message in the channel named Incidents you can change that.
- if(!incidentChannel) return message.channel.send("Can't find incidents channel.");
- message.guild.member(bUser).ban(bReason);
- incidentChannel.send(banEmbed);
- return;
- }
- //Weather Command
- if (msg.startsWith(prefix + 'WEATHER')) { //This checks to see if the beginning of the message is calling the weather command.
- //you can find some of the code used here on the weather-js npm page in the description
- weather.find({search: args.join(" "), degreeType: 'F'}, function(err, result) { // Make sure you get that args.join part, since it adds everything after weather.
- if (err) message.channel.send(err);
- //We also want them to know if a place they enter is invalid.
- if (result.length === 0) {
- message.channel.send('**Please enter a valid location.**') //This tells them in chat that the place they entered is invalid.
- }
- //Variables
- var current = result[0].current; //This is a variable for the current part of the JSON output
- var location = result[0].location; //This is a variable for the location part of the JSON output
- //Let's use an embed for this.
- const embed = new Discord.RichEmbed()
- .setDescription(`**${current.skytext}**`) //This is the text of what the sky looks like, remember you can find all of this on the weather-js npm page.
- .setAuthor(`Weather for ${current.observationpoint}`) //This shows the current location of the weather.
- .setThumbnail(current.imageUrl) //This sets the thumbnail of the embed.
- .setColor(0x00AE86) //This sets the color of the embed, you cna set this to anything if you look put a hex color picker, just make sure you put 0x infront of the hex
- .addField('Timezone',`UTC${location.timezone}`, true) //This is the first field, it shows the timezone, and the true means `inline`, you can read more about this on the official discord.js documentation
- .addField('Degree Type', location.degreetype, true) //This is the field that shows the degree type, and is inline
- .addField('Temperature',`${current.temperature} Degrees`, true)
- .addField('Feels Like', `${current.feelslike} Degrees`, true)
- .addField('Winds', current.winddisplay, true)
- .addField('Humidity', `${current.humidity}%`, true)
- //Now, let's display it when called
- message.channel.send({embed}); //This posts the Current part of the First result.
- });
- }
- //Purge Command
- if (msg.startsWith(prefix + 'PURGE')) { // This time we have to use startsWith, since we will be adding a number to the end of the command.
- // We have to wrap this in an async since awaits only work in them.
- async function purge() {
- message.delete(); // Lets delete the command message, so it doesn't interfere with the messages we are going to delete.
- // Now, we want to check if the user has the 'bot-commander' role, you can change this to whatever yo uwant.
- if(!message.member.roles.find("name", "bot-commander")) { // This checks to see if they DONT have it, the "!" inverts the true/false
- message.channel.send('You need the \`bot-commander\` role to use this command.'); //This tells the user in chat that they need the role.
- return; // this returns the code, so the rest doesn't run.
- }
- // we want ot check if the argument is a number
- if (isNaN(args[0])) {
- // sends a message to the channel.
- message.channel.send('Please use a number as your arguments. \n Usage: ' + prefix + 'purge <amount>'); //\n means new line.
- //Cancels out of the script, so the rest doesn't run.
- return;
- }
- const fetched = await message.channel.fetchMessages({limit: args[0]}); //Tis grabs the last number(args) of messages in the channel.
- console.log(fetched.size + ' messages found, deleting...'); // lets post into console how many messages we are deleting
- //Deleting the fetchMessages
- message.channel.bulkDelete(fetched)
- .catch(error => message.channel.send(`Error: ${error}`)); //If it finds an error, it post it into the channel.
- }
- //we want to make sure we call the function whenever the purge command is run.
- purge(); //make sure this is inside the if(msg.startsWith)
- //We also have two more things to do:
- //1) make sure their variable is a number
- //2) Limit only people you want to use the command
- }
- //This is for help command. We will also add a category system for the commands, for example !help mod (shows moderator commands), !help admin (shows admin commands), as well as !help <command> shows more info
- //Help Command
- if (msg.startsWith(prefix + 'HELP')) { //We're also going to use a seperate JSON file, so we need to call it.
- //Let's see if the only thing they typed in chat was !help
- if (msg === `${prefix}HELP`) { //If they only type this, let's only show the commands for regular users
- // Start of the embed
- const embed = new Discord.RichEmbed()
- .setColor(0x1D82B6) //You can set this color to whatever you want.
- //Variables
- let commandsFound = 0; //We also want to tell them how many commands there are for that specific group.
- //Lets create the for loop that loops through the commands
- for (var cmd in commands) { //we should start creating the commands json first.
- //Checks if the group is "users"
- if (commands[cmd].group.toUpperCase() === 'USER') {
- //Lets also count commandsFound +1 every time it finds a command in the newGroup
- commandsFound++
- //LETS ADD THE COMMAND FIELD TO THE EMBED
- embed.addField(`${commands[cmd].name}`, `**Description:** ${commands[cmd].desc}\n**Usage:** ${prefix + commands[cmd].usage}`); //This will output something like <commandname>[title] [newline] desc: <description> [newline] usage: <usage
- }
- }
- //add some more to the EMBED
- embed.setFooter(`Currently showing user commands. To view another group do ${prefix}help [group / command]`)
- embed.setDescription(`**${commandsFound} commands found** - <> means required, [] means optional`)
- //We can output it two ways 1 - send to DMs, and tell them that they sent to DMs in chat. 2 - Post commands in chat. [since commands take up a lot let's send to DMs]
- message.author.send({embed})
- //post in chat they sent to DMs
- message.channel.send({embed: {
- color: 0x1D8286,
- description: `**Check your DMs ${message.author}!**`
- }})
- } else if (args.join(" ").toUpperCase() === 'GROUPS') {
- //Variables
- let groups = '';
- for (var cmd in commands) {
- if (!groups.includes(commands[cmd].group)) {
- groups += `${commands[cmd].group}\n`
- }
- }
- message.channel.send({embed: {
- description: `**${groups}**`,
- title:"Groups",
- color: 0x1D82B6,
- }})
- return;
- }else {
- //Now lets do something when they do !help [cmd / group]
- //Variables
- let groupFound = '';
- for (var cmd in commands) { //we should start creating the commands json first.
- if (args.join(" ").trim().toUpperCase() === commands[cmd].group.toUpperCase()) {
- groupFound = commands[cmd].group.toUpperCase(); //Lets set the ground found, then break out of the loop.
- break;
- }
- }
- if (groupFound != '') { //If a group is found, run this statement.
- // Start of the embed
- const embed = new Discord.RichEmbed()
- .setColor(0x1D82B6) //You can set this color to whatever you want.
- //Variables
- let commandsFound = 0; //We also want to tell them how many commands there are for that specific group.
- for (var cmd in commands) { //we should start creating the commands json first.
- //Checks if the group is "users" and replace type with group
- if (commands[cmd].group.toUpperCase() === groupFound) {
- //Lets also count commandsFound +1 every time it finds a command in the newGroup
- commandsFound++
- //LETS ADD THE COMMAND FIELD TO THE EMBED
- embed.addField(`${commands[cmd].name}`, `**Description:** ${commands[cmd].desc}\n**Usage:** ${prefix + commands[cmd].usage}`); //This will output something like <commandname>[title] [newline] desc: <description> [newline] usage: <usage
- }
- }
- //add some more to the EMBED
- embed.setFooter(`Currently showing ${groupFound} commands. To view another group do ${prefix}help [group / command]`)
- embed.setDescription(`**${commandsFound} commands found** - <> means required, [] means optional`)
- //We can output it two ways 1 - send to DMs, and tell them that they sent to DMs in chat. 2 - Post commands in chat. [since commands take up a lot let's send to DMs]
- message.author.send({embed})
- //post in chat they sent to DMs
- message.channel.send({embed: {
- color: 0x1D8286,
- description: `**Check your DMs ${message.author}!**`
- }})
- //make sure you copy and paste into the right place, lets test it now!
- return; //we want to make sure we return so it doesn't run the rest of the script after it finds a group! lets test it
- //Now lets show groups.
- }
- //although, if a group is not found, lets see if it is a command
- let commandFound = '';
- let commandDesc = '';
- let commandUsage = '';
- let commandGroup = '';
- for (var cmd in commands) { //we should start creating the commands json first.
- if (args.join(" ").trim().toUpperCase() === commands[cmd].name.toUpperCase()) {
- commandFound = commands[cmd].name; //Lets set the ground found, then break out of the loop. And not to uppcase this time
- commandDesc = commands[cmd].desc;
- commandUsage = commands[cmd].usage;
- commandGroup = commands[cmd].group;
- break;
- }
- }
- //lets post in chat if nothing is found!
- if (commandFound === '') {
- message.channel.send({embed: {
- description: `"**No group or command found titled \`${args.join(" ")}\`**`,
- color: 0x1D8286,
- }})
- }
- message.channel.send({embed: {
- title: '<> means required, [] means optional',
- color: 0x1D82B6,
- fields: [{
- name:commandFound,
- value:`**Description:** ${commandDesc}\n**Usage:** ${commandUsage}\n**Group ${commandGroup}`
- }]
- }})
- }
- }
- if (!streams[message.author.username]) streams[message.author.username] = {
- streams: 0,
- duration: 0,
- };
- if (message.content.startsWith ("write")) {
- editeddate = message.content.slice (6, 16);
- editedtime = message.content.slice (17, 22);
- editedgame = message.content.slice (23, 27);
- editedduration = message.content.slice (28, 30);
- editedname = message.content.slice (31);
- currentdate = Date();
- bot.msgs [message.author.username] =
- signdate: currentdate,
- streamdate: editeddate,
- start: editedtime,
- game: editedgame,
- duration: editedduration,
- name: editedname
- fs.writeFile ("./msgs.json", JSON.stringify (bot.msgs, null, 4), {flag: a}, err => {
- if (err) throw error
- message.channel.send ("message written");
- });
- }
- if (message.content.startsWith ("get")) {
- let _message = bot.msgs[message.author.username].duration;
- message.channel.send("Duration is: " + _message);
- }
- });
- //Listener Event: Runs whenever the bot sends a ready event (when it first starts for example)
- bot.on('ready', () => {
- //we can post into console that the bot launched.
- console.log('Bot started.')
- });
- //We need to login also, this can be done using this
- bot.login('BLAH');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement