From fed7b4d4070c15b43acb231f14267065d7f868da Mon Sep 17 00:00:00 2001 From: Chris Haig Date: Sat, 29 Jun 2019 07:02:41 +0100 Subject: [PATCH 1/4] unabn feature has been added. --- config.json | 2 +- funcs.js | 161 +++++++++++++++++++++++++++++++-------------- intents.json | 6 ++ userdatastack.json | 2 +- 4 files changed, 120 insertions(+), 51 deletions(-) diff --git a/config.json b/config.json index b7ed693..be3c7de 100644 --- a/config.json +++ b/config.json @@ -1 +1 @@ -{"lang":"en","NSFW Filter":false,"Translation":false,"Probability Muting":false,"Statistical Slow-Mode":true,"Word Blacklisting":false} \ No newline at end of file +{"lang":"en","NSFW Filter":false,"Translation":true,"Probability Muting":false,"Statistical Slow-Mode":true,"Word Blacklisting":false} \ No newline at end of file diff --git a/funcs.js b/funcs.js index dda2659..811a10b 100644 --- a/funcs.js +++ b/funcs.js @@ -17,7 +17,8 @@ module.exports = { var count = 0; arr.forEach(function (intent) { var word = intent.Word; - if (msg.content.toLowerCase().includes(word)) { + if (msg.content.toLowerCase().includes(" " + word + " ")) { + console.log("word " + word + " is used." ); count++; } }); @@ -27,13 +28,20 @@ module.exports = { }else if(count == 1){ arr.forEach(function (intent) { var word = intent.Word; - if (msg.content.toLowerCase().includes(word)) { + if (msg.content.toLowerCase().includes(" " + word + " ")) { + switch (word) { case "ban": if(hasPermission(msg.member,"BAN_MEMBERS")){ banUser(word, msg, client); } break; + + case "unban": + if(hasPermission(msg.member,"BAN_MEMBERS")){ + unbanUser(msg, client); + } + break; case "kick": if(hasPermission(msg.member,"KICK_MEMBERS")){ @@ -80,6 +88,12 @@ module.exports = { roleAlteration(msg, client); } break; + + case "language": + if(hasPermission(msg.member,"ADMINISTRATOR")){ + setLanguage(msg); + } + break; } } }); @@ -149,7 +163,8 @@ module.exports = { request(options, function (error, response, body) { if (error) throw new Error(error); var obj = JSON.parse(body); - if (obj.lang != "en" && obj.lang != "") { + console.log(obj.lang ) + if (obj.lang != config["lang"] && obj.lang != "") { getTranslatedText(msg, (function (text) { msg.channel.send(translateEmbed(msg, text)); msg.delete(); @@ -184,7 +199,7 @@ module.exports = { } function banUser(word, msg, client) { - + var count = 0; var ids = msg.mentions.users; var bans = []; var splitter; @@ -202,31 +217,47 @@ function banUser(word, msg, client) { // member.ban().then(() => console.log(`Banned ${member.toString()}`)).catch(console.error); member.send("You have been banned from **" + client.guilds.get(msg.guild.id).name + "**."); } - + count++; } }); + if(count > 0){ + setTimeout(function () { + bans = bans.toString().replace(/,/g, ' & '); + if (msg.content.toLowerCase().includes("for") || msg.content.toLowerCase().includes("because")) { + var splitter = msg.content.toLowerCase().includes("for") ? "for" : "because"; + msg.channel.send("Hello " + msg.author + ", I see you wish to " + word + " " + bans.toString() + ", they are now banned :wave: :point_right:.\n**Reason**: *" + msg.content.toLowerCase().slice(msg.content.toLowerCase().indexOf(splitter), msg.content.length) + "*"); + } else { + msg.channel.send("Hello " + msg.author + ", I see you wish to " + word + " " + bans.toString() + ", they are now banned :wave: :point_right:."); + } + + + }, 75); + } + } - setTimeout(function () { - bans = bans.toString().replace(/,/g, ' & '); - if (msg.content.toLowerCase().includes("for") || msg.content.toLowerCase().includes("because")) { - var splitter = msg.content.toLowerCase().includes("for") ? "for" : "because"; - msg.channel.send("Hello " + msg.author + ", I see you wish to " + word + " " + bans.toString() + ", they are now banned :wave: :point_right:.\n**Reason**: *" + msg.content.toLowerCase().slice(msg.content.indexOf(splitter), msg.content.length) + "*"); - } else { - msg.channel.send("Hello " + msg.author + ", I see you wish to " + word + " " + bans.toString() + ", they are now banned :wave: :point_right:."); - } - +} - }, 75); +function unbanUser(msg, client) { - } + client.guilds.get(msg.guild.id).fetchBans().then(bans => { + bans.forEach(user => { + if(msg.content.toLowerCase().includes(user.username.toLowerCase())){ + msg.guild.unban(user); + //user.send('You have been unbanned from ' + client.guilds.get(msg.guild.id).name + ""); + msg.channel.send(msg.author + ", The user known as " + user.tag + " has been unbanned"); + } + + }); + }); } -function kickUser(word, msg, client) { +function kickUser(word, msg, client) { + var count = 0; var ids = msg.mentions.users; var splitter; var kicks = []; @@ -241,28 +272,28 @@ function kickUser(word, msg, client) { if (msg.content.toLowerCase().includes("for") || msg.content.toLowerCase().includes("because")) { splitter = msg.content.toLowerCase().includes("for") ? "for" : "because"; // member.ban({ reason: msg.content.slice(msg.content.toLowerCase().indexOf(splitter), msg.content.length)}).then(() => console.log(`Banned ${member.toString()}`)).catch(console.error); - member.send("You have been kicked from **" + client.guilds.get(msg.guild.id).name + "** " + msg.content.toLowerCase().slice(msg.content.indexOf(splitter), msg.content.length) + ""); + member.send("You have been kicked from **" + client.guilds.get(msg.guild.id).name + "** " + msg.content.toLowerCase().slice(msg.content.toLowerCase().indexOf(splitter), msg.content.length) + ""); } else { // member.ban().then(() => console.log(`Banned ${member.toString()}`)).catch(console.error); member.send("You have been kicked from **" + client.guilds.get(msg.guild.id).name + "**." ); } - + count++; } }); - - setTimeout(function () { - kicks = kicks.toString().replace(/,/g, ' & '); - if (msg.content.toLowerCase().includes(splitter)) { - msg.channel.send("Hello " + msg.author + ", I see you wish to " + word + " " + kicks.toString() + ", they are now kicked :wave: :point_right:.\n**Reason**: *" + msg.content.slice(msg.content.toLowerCase().indexOf(splitter), msg.content.length) + "*"); - } else { - msg.channel.send("Hello " + msg.author + ", I see you wish to " + word + " " + kicks.toString() + ", they are now kicked :wave: :point_right:."); - } - - - }, 75); - + if(count > 0){ + setTimeout(function () { + kicks = kicks.toString().replace(/,/g, ' & '); + if (msg.content.toLowerCase().includes(splitter)) { + msg.channel.send("Hello " + msg.author + ", I see you wish to " + word + " " + kicks.toString() + ", they are now kicked :wave: :point_right:.\n**Reason**: *" + msg.content.slice(msg.content.toLowerCase().indexOf(splitter), msg.content.length) + "*"); + } else { + msg.channel.send("Hello " + msg.author + ", I see you wish to " + word + " " + kicks.toString() + ", they are now kicked :wave: :point_right:."); + } + + + }, 75); + } } } @@ -274,11 +305,9 @@ function timeoutUser(word, msg, client) { mintues: [], seconds: [] }; - + var count = 0; var ids = msg.mentions.users; - var timeouts = []; - var end = ""; if (ids != null) { @@ -314,17 +343,19 @@ function timeoutUser(word, msg, client) { member.send("You have been timed out from **" + client.guilds.get(msg.guild.id).name + "**, you will be able to chat again in **" + end + "**"); } } + count++; } }); - if (end != 0) { - timeouts = timeouts.toString().replace(/,/g, ' & '); - msg.channel.send("Hello " + msg.author + ", I see you wish to timeout " + timeouts.toString() + ", their timeout will end in **" + end + "**"); - } else { - msg.channel.send("Hello " + msg.author + ", It appears you have entered an invalid length of time."); - } + if(count > 0){ + if (end != 0) { + timeouts = timeouts.toString().replace(/,/g, ' & '); + msg.channel.send("Hello " + msg.author + ", I see you wish to timeout " + timeouts.toString() + ", their timeout will end in **" + end + "**"); + } else { + msg.channel.send("Hello " + msg.author + ", It appears you have entered an invalid length of time."); + } + } } - } function calculateTimeoutEnd(did, times) { @@ -560,6 +591,7 @@ function roleAlteration(msg){ var people = []; var type = ""; var roleName = ""; + var count = 0; var userlist = msg.mentions.users; userlist.forEach(function(user){ @@ -579,19 +611,50 @@ function roleAlteration(msg){ type = "removed" member.removeRole(role).catch(console.error); } + count++; } } ); + } }); - - if(people.size != 0){ - people = people.toString().replace(/,/g, ' & '); - if(type == "given"){ - msg.channel.send("The following user(s) " + people + " have been given the role of " + roleName + "."); - }else if(type == "removed"){ - msg.channel.send("The following user(s) " + people + " no longer have the role " + roleName + "."); + if(count > 0){ + if(people.size != 0){ + people = people.toString().replace(/,/g, ' & '); + if(type == "given"){ + msg.channel.send("The following user(s) " + people + " have been given the role of " + roleName + "."); + }else if(type == "removed"){ + msg.channel.send("The following user(s) " + people + " no longer have the role " + roleName + "."); + } + } - } + } + +function setLanguage(msg){ + + var filedata = fs.readFileSync('./lang.json', { encoding: 'utf8' }); + var langs = JSON.parse(filedata); + var language = ""; + var set = false; + + langs.forEach((function(lang){ + if(set == false && msg.content.toLowerCase().includes(lang.name.toLowerCase())){ + configFile["lang"] = lang.code; + language = lang.name; + set = true; + + } + })); + if(set == true){ + msg.channel.send(msg.author + ", The server's language has been set to " + language + "."); + + fs.writeFileSync('./config.json', JSON.stringify(configFile), { encoding: "utf8" }, function (err) { + if (err) throw err; + }); + }else{ + msg.channel.send(msg.author + ", Please specify a language that you want to set"); + } + +} \ No newline at end of file diff --git a/intents.json b/intents.json index 239cf86..4bfc340 100644 --- a/intents.json +++ b/intents.json @@ -3,6 +3,9 @@ { "Word" : "ban" }, + { + "Word" : "unban" + }, { "Word" : "kick" }, @@ -29,6 +32,9 @@ }, { "Word": "role" + }, + { + "Word": "language" } ] diff --git a/userdatastack.json b/userdatastack.json index 3b20b33..35b2d05 100644 --- a/userdatastack.json +++ b/userdatastack.json @@ -1 +1 @@ -[{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"imbot remove the role of admin from <@287423028147781654> and <@334891302758121474>","msgId":"594377275869233152","createdAt":"2019-06-29T04:03:05.563Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"better ?","msgId":"594377289903374346","createdAt":"2019-06-29T04:03:08.909Z"},{"name":"Gisgar3","channel":"592866062698151936","id":"287423028147781654","msg":"yea","msgId":"594377297948311563","createdAt":"2019-06-29T04:03:10.827Z"},{"name":"Gisgar3","channel":"592866062698151936","id":"287423028147781654","msg":"looks good","msgId":"594377310547869719","createdAt":"2019-06-29T04:03:13.831Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"https://tenor.com/u5Qc.gif","msgId":"594377343473025044","createdAt":"2019-06-29T04:03:21.681Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"me rn","msgId":"594377354441129995","createdAt":"2019-06-29T04:03:24.296Z"},{"name":"Gisgar3","channel":"592866062698151936","id":"287423028147781654","msg":"fax","msgId":"594377368039325726","createdAt":"2019-06-29T04:03:27.538Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"had 3 nosebleeds","msgId":"594377407633424442","createdAt":"2019-06-29T04:03:36.978Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"dying i think 😉","msgId":"594377440776945684","createdAt":"2019-06-29T04:03:44.880Z"},{"name":"Gisgar3","channel":"592866062698151936","id":"287423028147781654","msg":"IMBot give the role of admin to <@287423028147781654> and <@334891302758121474>","msgId":"594378350513094656","createdAt":"2019-06-29T04:07:21.778Z"}] \ No newline at end of file +[{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"Hello my name is chris","msgId":"594392866197995540","createdAt":"2019-06-29T05:05:02.587Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"<@287423028147781654> Try it out my friend","msgId":"594392936008122368","createdAt":"2019-06-29T05:05:19.231Z"},{"name":"Gisgar3","channel":"592866062698151936","id":"287423028147781654","msg":"My ballsack itches","msgId":"594393168561176577","createdAt":"2019-06-29T05:06:14.676Z"},{"name":"Gisgar3","channel":"592866062698151936","id":"287423028147781654","msg":"dab and nae nae","msgId":"594393234030198784","createdAt":"2019-06-29T05:06:30.285Z"},{"name":"Gisgar3","channel":"592866062698151936","id":"287423028147781654","msg":"wiener","msgId":"594393290397450251","createdAt":"2019-06-29T05:06:43.724Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"imbot set language to english","msgId":"594393356172394526","createdAt":"2019-06-29T05:06:59.406Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"hallo","msgId":"594393365932408833","createdAt":"2019-06-29T05:07:01.733Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"hello","msgId":"594393387516428299","createdAt":"2019-06-29T05:07:06.879Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"there","msgId":"594393400577622037","createdAt":"2019-06-29T05:07:09.993Z"}] \ No newline at end of file From dacb50d3fd2f6000891587c5afbb305c2f031750 Mon Sep 17 00:00:00 2001 From: Chris Haig Date: Sat, 29 Jun 2019 07:14:08 +0100 Subject: [PATCH 2/4] final commit --- funcs.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/funcs.js b/funcs.js index 8604bc0..5eecb70 100644 --- a/funcs.js +++ b/funcs.js @@ -245,7 +245,6 @@ function unbanUser(msg, client) { bans.forEach(user => { if(msg.content.toLowerCase().includes(user.username.toLowerCase())){ msg.guild.unban(user); - //user.send('You have been unbanned from ' + client.guilds.get(msg.guild.id).name + ""); msg.channel.send(msg.author + ", The user known as " + user.tag + " has been unbanned"); } @@ -615,7 +614,6 @@ function roleAlteration(msg){ } }); -<<<<<<< HEAD if(count > 0){ if(people.size != 0){ people = people.toString().replace(/,/g, ' & '); @@ -625,14 +623,6 @@ function roleAlteration(msg){ msg.channel.send("The following user(s) " + people + " no longer have the role " + roleName + "."); } -======= - if(people.size != 0){ - people = people.toString().replace(/,/g, ' & '); - if(type == "given"){ - msg.channel.send("The following user(s) " + people + " have been given the role of " + roleName + "."); - }else if(type == "removed"){ - msg.channel.send("The following user(s) " + people + " no longer have the role " + roleName + "."); ->>>>>>> 267d94d188ff21eeded3074b224b7d0e5abaaa06 } } From c08b43b1e5d55027fca30cb576ce642b2228f8d5 Mon Sep 17 00:00:00 2001 From: Chris Haig Date: Sat, 29 Jun 2019 07:14:41 +0100 Subject: [PATCH 3/4] final commit --- userdatastack.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/userdatastack.json b/userdatastack.json index 449bcda..84d9baf 100644 --- a/userdatastack.json +++ b/userdatastack.json @@ -1,5 +1 @@ -<<<<<<< HEAD [{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"Hello my name is chris","msgId":"594392866197995540","createdAt":"2019-06-29T05:05:02.587Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"<@287423028147781654> Try it out my friend","msgId":"594392936008122368","createdAt":"2019-06-29T05:05:19.231Z"},{"name":"Gisgar3","channel":"592866062698151936","id":"287423028147781654","msg":"My ballsack itches","msgId":"594393168561176577","createdAt":"2019-06-29T05:06:14.676Z"},{"name":"Gisgar3","channel":"592866062698151936","id":"287423028147781654","msg":"dab and nae nae","msgId":"594393234030198784","createdAt":"2019-06-29T05:06:30.285Z"},{"name":"Gisgar3","channel":"592866062698151936","id":"287423028147781654","msg":"wiener","msgId":"594393290397450251","createdAt":"2019-06-29T05:06:43.724Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"imbot set language to english","msgId":"594393356172394526","createdAt":"2019-06-29T05:06:59.406Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"hallo","msgId":"594393365932408833","createdAt":"2019-06-29T05:07:01.733Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"hello","msgId":"594393387516428299","createdAt":"2019-06-29T05:07:06.879Z"},{"name":"ChrisFH","channel":"592866062698151936","id":"334891302758121474","msg":"there","msgId":"594393400577622037","createdAt":"2019-06-29T05:07:09.993Z"}] -======= - ->>>>>>> 267d94d188ff21eeded3074b224b7d0e5abaaa06 From 5e4445eea21b5c1032cd651c03e379eb25a73ca3 Mon Sep 17 00:00:00 2001 From: Chris Haig Date: Sat, 29 Jun 2019 07:48:42 +0100 Subject: [PATCH 4/4] final commit --- donotopen/tokens.json | 2 +- funcs.js | 85 +++++++++++++++++++++++++++++++++++++------ index.js | 6 ++- regex.js | 2 +- 4 files changed, 80 insertions(+), 15 deletions(-) diff --git a/donotopen/tokens.json b/donotopen/tokens.json index 9865a39..06778b2 100644 --- a/donotopen/tokens.json +++ b/donotopen/tokens.json @@ -1,4 +1,4 @@ { - "token" : "NTkyNzgzNTc5OTk4NTg0ODY4.XRa4QQ.8hIVtCSu29a5bzasJPOueF6qqKQ" + "token" : "" } \ No newline at end of file diff --git a/funcs.js b/funcs.js index 5eecb70..c7a2536 100644 --- a/funcs.js +++ b/funcs.js @@ -10,7 +10,8 @@ var userinfoattachmentstack = []; var configFile; module.exports = { - + //Checks if any intents have been used and launches the corrisponding function. and limits it to 1 intent per + //message listen: function (msg, client, configF) { configFile = configF; var arr = (intents.intents); @@ -18,7 +19,7 @@ module.exports = { arr.forEach(function (intent) { var word = intent.Word; if (msg.content.toLowerCase().includes(" " + word + " ")) { - console.log("word " + word + " is used." ); + count++; } }); @@ -101,6 +102,7 @@ module.exports = { }, recordUserInfo: function (msg) { + //for storing user data. if (msg.attachments.size > 0) { for (const value of msg.attachments.array().values()) { userinfoattachmentstack.push({ attachments: [{ filename: value.filename, url: value.url }] }); @@ -113,6 +115,7 @@ module.exports = { } }, appendUserInfo: function () { + //for storing user data. try { fs.writeFileSync("./userdatastack.json", JSON.stringify(userinfostack), { encoding: "utf8" }); } @@ -121,6 +124,7 @@ module.exports = { } }, isTimedout: function (msg) { + //This is used to timeout a user if they are not already timedout. var isTimedout = false; var filedata = fs.readFileSync('./timeouts.json', { encoding: 'utf8' }); var timeouts = JSON.parse(filedata); @@ -145,6 +149,7 @@ module.exports = { return isTimedout; }, detectLanguage: function (msg) { + //detects the language in the message that has been typed. if different it will translate it and display it var filedata = fs.readFileSync('./config.json', { encoding: 'utf8' }); var config = JSON.parse(filedata); @@ -174,6 +179,7 @@ module.exports = { } }, isNSFW: function (url, callback) { + //Checks if any images are nsfw. var nsfw = false; var options = { method: 'GET', url: 'https://api.uploadfilter.io/v1/nudity', qs: { apikey: 'f7827a90-9604-11e9-a4fd-d54073694519', url: url }, headers: { 'cache-control': 'no-cache', Host: 'api.uploadfilter.io', Accept: '*/*' } }; @@ -193,11 +199,15 @@ module.exports = { } }); },statSlowmode : function(){ - statSlowmode(); + //Not working + //statSlowmode(); }, userinfostack } +/* +This function bans a user when the "ban" intent has been used. +*/ function banUser(word, msg, client) { var count = 0; var ids = msg.mentions.users; @@ -211,10 +221,10 @@ function banUser(word, msg, client) { bans.push(member.toString()); if (msg.content.toLowerCase().includes("for") || msg.content.toLowerCase().includes("because")) { splitter = msg.content.toLowerCase().includes("for") ? "for" : "because"; - // member.ban({ reason: msg.content.slice(msg.content.indexOf("for"), msg.content.length)}).then(() => console.log(`Banned ${member.toString()}`)).catch(console.error); + member.ban({ reason: msg.content.slice(msg.content.indexOf("for"), msg.content.length)}).then(() => console.log(`Banned ${member.toString()}`)).catch(console.error); member.send("You have been banned from **" + client.guilds.get(msg.guild.id).name + "** " + msg.content.toLowerCase().slice(msg.content.toLowerCase.indexOf(splitter), msg.content.length) + "."); } else { - // member.ban().then(() => console.log(`Banned ${member.toString()}`)).catch(console.error); + member.ban().then(() => console.log(`Banned ${member.toString()}`)).catch(console.error); member.send("You have been banned from **" + client.guilds.get(msg.guild.id).name + "**."); } count++; @@ -239,6 +249,9 @@ function banUser(word, msg, client) { } +/* +This function unbans a user when the "unban" intent has been used. +*/ function unbanUser(msg, client) { client.guilds.get(msg.guild.id).fetchBans().then(bans => { @@ -253,7 +266,9 @@ function unbanUser(msg, client) { } - +/* +This function is used to kick a user when the "kick" intent is used and finds any users that have been mentioned. +*/ function kickUser(word, msg, client) { var count = 0; @@ -270,10 +285,10 @@ function kickUser(word, msg, client) { kicks.push(member.toString()); if (msg.content.toLowerCase().includes("for") || msg.content.toLowerCase().includes("because")) { splitter = msg.content.toLowerCase().includes("for") ? "for" : "because"; - // member.ban({ reason: msg.content.slice(msg.content.toLowerCase().indexOf(splitter), msg.content.length)}).then(() => console.log(`Banned ${member.toString()}`)).catch(console.error); + member.ban({ reason: msg.content.slice(msg.content.toLowerCase().indexOf(splitter), msg.content.length)}).then(() => console.log(`Banned ${member.toString()}`)).catch(console.error); member.send("You have been kicked from **" + client.guilds.get(msg.guild.id).name + "** " + msg.content.toLowerCase().slice(msg.content.toLowerCase().indexOf(splitter), msg.content.length) + ""); } else { - // member.ban().then(() => console.log(`Banned ${member.toString()}`)).catch(console.error); + member.ban().then(() => console.log(`Banned ${member.toString()}`)).catch(console.error); member.send("You have been kicked from **" + client.guilds.get(msg.guild.id).name + "**." ); } count++; @@ -297,6 +312,11 @@ function kickUser(word, msg, client) { } +/* +This function times out a user the the intent "timeout" is called and also grabs any times that is found by the +time regex array +*/ + function timeoutUser(word, msg, client) { var timer = { days: [], @@ -357,6 +377,10 @@ function timeoutUser(word, msg, client) { } } +/* +This function is used to calculate the time in milleseconds between two date objects so that it can be broken down +to get the days, hours , minutes and seconds. +*/ function calculateTimeoutEnd(did, times) { var now = new Date(); var duc = 0; @@ -412,6 +436,11 @@ function calculateTimeoutEnd(did, times) { return timeDiff; } +/* +This function is used to determin the time difference between 2 date objects, this is used in conjunction with +the timeout function. +*/ + function MtoHMS(time) { var ms = time % 1000; time = (time - ms) / 1000; @@ -439,7 +468,9 @@ function MtoHMS(time) { return time; } - +/* +This function is used to get the text that is translated using the Yandex api. +*/ function getTranslatedText(msg, callback) { var translated; @@ -466,6 +497,9 @@ function getTranslatedText(msg, callback) { } } +/* +This function is used to display the text that is translated using the Yandex api. +*/ function translateEmbed(msg, translation) { const embed = new Discord.RichEmbed() .setColor('#0099ff') @@ -479,10 +513,15 @@ function translateEmbed(msg, translation) { return embed; } +/* +This function is use to enable and disable functions inside the config file. +*/ function featureToggle(msg, toggleType) { var types = ["translation", "nsfw", "cooldown", "blacklisting"] + //Detects if the user has said "turn off" or "turn on" + if (msg.content.toLowerCase().includes(" off ")) { toggleType = false; } else if (msg.content.toLowerCase().includes(" on ")) { @@ -496,6 +535,7 @@ function featureToggle(msg, toggleType) { if (toggleType == null) { msg.channel.send(msg.author + ", it appears you are trying to enabled and disable a feature at the same time."); } else { + //Enables or disables the feature that was specified. types.forEach(function (type) { if (msg.content.toLowerCase().includes(type)) { var state; @@ -535,6 +575,9 @@ function featureToggle(msg, toggleType) { } } +/* +This functions purpose is to purge all messages by a specific user or text channel +*/ function purgeChannel(msg, client) { if (msg.mentions.channels.size > 0) { msg.mentions.channels.forEach((function (channel) { @@ -564,6 +607,9 @@ function purgeChannel(msg, client) { } } +/* +This function checks the timeouts json file and detects if the user has an existing timeout. +*/ function isTimedout(id) { var isTimedout = false; var filedata = fs.readFileSync('./timeouts.json', { encoding: 'utf8' }); @@ -578,24 +624,32 @@ function isTimedout(id) { return isTimedout; } +/* +This function is used to check if user as a set permission. +*/ function hasPermission(member, permission) { return member.hasPermission(permission) ? true : false; } +/* + This function is used to allow users to add and remove roles from the users that have been mentioned. +*/ function roleAlteration(msg){ var people = []; var type = ""; var roleName = ""; var count = 0; - var userlist = msg.mentions.users; + + //Loops through all users mentioned userlist.forEach(function(user){ if (user.id != "592783579998584868") { - var member = msg.guild.members.get(user.id); people.push(member.toString()); var hasRole = false; + + //Checks if any of the roles that are valid have been mentioned and assigns them msg.guild.roles.find(role => { if(hasRole == false && msg.content.toLowerCase().includes(role.name.toLowerCase())){ hasRole = true; @@ -614,6 +668,7 @@ function roleAlteration(msg){ } }); + //If any alterations have been made it will alert the author. if(count > 0){ if(people.size != 0){ people = people.toString().replace(/,/g, ' & '); @@ -628,6 +683,10 @@ function roleAlteration(msg){ } +/* +Function sets the langauge that the user has chosen, this is used in conjunction with the translation function +so that any text that is not in the same language as the servers default will be translated. +*/ function setLanguage(msg){ var filedata = fs.readFileSync('./lang.json', { encoding: 'utf8' }); @@ -635,6 +694,8 @@ function setLanguage(msg){ var language = ""; var set = false; + //Loops through all languages to check if any have been mentioned. + langs.forEach((function(lang){ if(set == false && msg.content.toLowerCase().includes(lang.name.toLowerCase())){ configFile["lang"] = lang.code; @@ -643,6 +704,8 @@ function setLanguage(msg){ } })); + + //Sets the language in the config file and notifies the author. if(set == true){ msg.channel.send(msg.author + ", The server's language has been set to " + language + "."); diff --git a/index.js b/index.js index b30f737..e7cf664 100644 --- a/index.js +++ b/index.js @@ -33,11 +33,13 @@ var config = require("./config.json"); client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); - + //Stores the users messages every 5 minutes will be used for future features. setInterval(funcs.appendUserInfo, 300000); }); +//Checks if the user is timedout, if the bot is called with a specific action and also if features such as the nsfw filer +//has been activated. client.on('message', msg => { if (msg.author.bot) return; @@ -99,5 +101,5 @@ rl.on("line", function (input) { }); - +//Client login. client.login(token.token); \ No newline at end of file diff --git a/regex.js b/regex.js index 9eb8adc..9aae03e 100644 --- a/regex.js +++ b/regex.js @@ -1,4 +1,4 @@ - +//Regex list module.exports = { templates : {