UNPKG

bugly.js

Version:

Bugly.js helps beginners and time-pressed people!

61 lines (52 loc) 1.85 kB
const { Log } = require("./log"); const lg = new Log(); class AntiSwear { constructor() { this.interaction = null; this.words = {}; } setInteraction(interaction) { this.interaction = interaction; return this; } setBlockedWords(words) { if (!Array.isArray(words)) return lg.error("Please provide an array for the banned words."); this.words = words.map(w => w.toLowerCase()); } start() { if (!this.interaction) return lg.error("You need to enter interaction for the system to work."); if (!this.words || this.words.length === 0) return lg.error("You need to enter a word index object for the system to work."); const client = this.interaction.client; client.on("messageCreate", (message) => { const date = new Date(); const fullTime = `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`; const content = message.content.toLowerCase(); const found = this.words.some(word => content.includes(word)); if (found) { message.delete() .then(() => { console.log({ message: "The message deleted successfully.", message_author: message.author, content: message.content, message_object: message, time: fullTime, code: 200 }); }) .catch((err) => { console.log({ message: "An error occurred while trying to delete the message.", message_author: message.author, content: message.content, message_object: message, time: fullTime, error: err, code: 503 }); }); } }); } } module.exports = { AntiSwear };