gaber-elsayed

antiSpam (JS)

Jun 7th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. const antispam = JSON.parse(fs.readFileSync("./antispam.json", "utf8"));
  2.  
  3. client.on("message", async message => {
  4. if (antispam[message.author.id] == undefined) {
  5. antispam[message.author.id] = {
  6. lastmessage: "none"
  7. };
  8. fs.writeFile("./antispam.json", JSON.stringify(antispam), function(err) {
  9. if (err) throw err;
  10. });
  11. }else if (antispam[message.guild.id] == undefined) {
  12. antispam[message.guild.id] = {
  13. onoff: "off"
  14. };
  15. fs.writeFile("./antispam.json", JSON.stringify(antispam), function(err) {
  16. if (err) throw err;
  17. });
  18. }
  19. let args = message.content.split(" ");
  20. let command = args[0]
  21. if(command === prefix + "antispam"){
  22. if(!args[1])return message.channel.send("**Error | Use `antispam on/off`**");
  23. if(args[1] === "on"){
  24. message.channel.send("**Done Sir Anti Spam Changed To ON**")
  25. antispam[message.guild.id].onoff = "on";
  26. fs.writeFile("./antispam.json", JSON.stringify(antispam), function(
  27. err
  28. ) {
  29. if (err) throw err;
  30. });
  31. }else if(args[1] === "off"){
  32. antispam[message.guild.id].onoff = "off";
  33. fs.writeFile("./antispam.json", JSON.stringify(antispam), function(
  34. err
  35. ) {
  36. if (err) throw err;
  37. });
  38. message.channel.send("**Done Sir Anti Spam Changed To OFF**")
  39. }
  40. }
  41. });
  42.  
  43. client.on("message", async message => {
  44. if (antispam[message.author.id] == undefined) {
  45. antispam[message.author.id] = {
  46. lastmessage: "none"
  47. };
  48. fs.writeFile("./antispam.json", JSON.stringify(antispam), function(err) {
  49. if (err) throw err;
  50. });
  51. }else if (antispam[message.guild.id] == undefined) {
  52. antispam[message.guild.id] = {
  53. onoff: "off"
  54. };
  55. fs.writeFile("./antispam.json", JSON.stringify(antispam), function(err) {
  56. if (err) throw err;
  57. });
  58. }else if(antispam[message.author.id].lastmessage === "none") {
  59. return;
  60. }else if(antispam[message.guild.id].onoff === "off"){
  61. return;
  62. }else if(antispam[message.author.id].lastmessage === message.content){
  63. return message.delete();
  64. }
  65.  
  66. antispam[message.author.id].lastmessage = message.content;
  67. fs.writeFile("./antispam.json", JSON.stringify(antispam), function(
  68. err
  69. ) {
  70. if (err) throw err;
  71. });
  72.  
  73. });
Add Comment
Please, Sign In to add comment