gaber-elsayed

bad word

Aug 23rd, 2021
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. const random = require('random-password-pkg')
  2. const db = require('quick.db')
  3. const Discord = require('discord.js')
  4. const client = new Discord.Client()
  5. class badword {
  6. constructor(options) {
  7. if (!options.client) {
  8. throw new Error('The Discord.Client() integration is required.');
  9. };
  10.  
  11. if(!options.addcmd){
  12. throw new Error(`I Can't Found Add Command`)
  13. }
  14.  
  15. if(!options.list){
  16. throw new Error(`I Can't Found List Command`)
  17. }
  18. if(!options.remove){
  19. throw new Error(`I Can't Found Remove Command`)
  20. }
  21.  
  22. if(!options.remove_all){
  23. throw new Error(`I Can't Found Remove All Command`)
  24. }
  25.  
  26. if (!options.prefix) {
  27. throw new Error('The bot prefix is required.');
  28. };
  29.  
  30. if(!options.permissions){
  31. throw new Error('User Permissions Required')
  32. }
  33.  
  34. this.prefix = options.prefix || options.prefix;
  35.  
  36. this.client = options.client || options.client;
  37.  
  38.  
  39. this.permissions = options.permissions || options.permissions;
  40.  
  41. this.addcmd = options.addcmd || options.addcmd;
  42. this.list = options.list || options.list;
  43.  
  44. this.remove = options.remove || options.remove;
  45.  
  46. this.remove_all = options.remove_all || options.remove_all;
  47.  
  48. }
  49.  
  50.  
  51.  
  52. async onMessage(message) {
  53. if (!message) {
  54. throw new Error('The message is required on the onMessage function.');
  55. };
  56.  
  57. const args = message.content.split(' ')
  58. const command = args[0]
  59. if(command === this.prefix + this.addcmd){
  60. if(!message.member.hasPermission(this.permissions)) return message.channel.send(`You Dont Have Permissions To Use This ${command} Command`)
  61. const aa = message.content.split(' ').slice(1).join(' ')
  62. const id = random(8)
  63. if(!aa) return message.channel.send(`I Can't Found AnyThing?!`)
  64. const data = {
  65. word: aa.toLowerCase(),
  66. id: id.toLowerCase(),
  67. by: message.author.tag
  68.  
  69. }
  70. let database = db.fetch(`word_${message.guild.id}`)
  71. if(database && database.find(x => x.word === aa.toLowerCase())) return message.channel.send(`This Word it's already on database.`)
  72.  
  73. var embed = new Discord.MessageEmbed()
  74. .setAuthor(message.author.tag, message.author.avatarURL({dynimc: true}))
  75. .setTitle(`New Word Add To The List`)
  76. .setDescription(`
  77. Word: ${aa} \n ID: ${id.toLowerCase()} \n By: <@${message.author.id}>
  78. `)
  79. .setTimestamp()
  80. .setFooter(`By: ${message.author.tag}`)
  81.  
  82. message.channel.send(embed).then(() => {
  83. db.push(`word_${message.guild.id}`, data)
  84. })
  85.  
  86. } else {
  87. if(command === this.prefix + this.remove){
  88. if(!message.member.hasPermission(this.permissions)) return message.channel.send(`You Dont Have Permissions To Use This ${command} Command`)
  89.  
  90. const args = message.content.split(' ')
  91.  
  92.  
  93. const wid = args[1]
  94.  
  95. let database = db.get(`word_${message.guild.id}`)
  96. if(database) {
  97. let data = database.find(x => x.id === wid.toLowerCase())
  98. if(!data) return message.channel.send(`That's on invaild ID`)
  99. let value = database.indexOf(data)
  100. delete database[value]
  101.  
  102. var filter = database.filter(x => {
  103. return x != null && x != ''
  104. })
  105.  
  106. db.set(`word_${message.guild.id}`, filter)
  107.  
  108. return message.channel.send("\`1\` Word has been removed ✅")
  109.  
  110. }
  111.  
  112.  
  113. } else {
  114. if(
  115. command === this.prefix +this.list){
  116.  
  117. let database = db.get(`word_${message.guild.id}`)
  118. if(database === null) return message.channel.send(`It's looks ur auto delete bad word it's empty`)
  119. let list = []
  120. if(database && database.length) {
  121. database.forEach(x => {
  122. list.push(`Word: ${x.word}
  123. > By: ${x.by}
  124. > ID: ${x.id}
  125. `)
  126. })
  127. if(list.length === 0) return message.channel.send(`it's looks ur auto delete bad word it's empty`)
  128. let embed = new Discord.MessageEmbed()
  129. .setAuthor(message.author.username , message.author.displayAvatarURL())
  130. .setDescription(list.join("\n"))
  131. .setFooter(message.guild.name , message.guild.iconURL())
  132. .setTimestamp()
  133. return message.channel.send(embed)
  134. }
  135.  
  136.  
  137. } else {
  138. if(command === this.prefix + this.remove_all){
  139. if(!message.member.hasPermission(this.permissions)) return message.channel.send(`You Dont Have Permissions To Use This ${command} Command`)
  140. const data = await db.fetch(`word_${message.guild.id}`)
  141. if(data === null) return message.channel.send(`it's looks ur auto delete bad word it's empty`)
  142.  
  143. message.channel.send(`Dont Remove ${data.length} Words`).then(() => {
  144. db.delete(`word_${message.guild.id}`)
  145.  
  146. })
  147. }
  148. }
  149. }
  150. }
  151. }
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. }
  159.  
  160.  
  161.  
  162.  
  163. module.exports = badword
Advertisement
Add Comment
Please, Sign In to add comment