-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔧Auto mod that deletes scam/misleading URLs #2
base: main
Are you sure you want to change the base?
Conversation
@TymianekPL lol, any plans on making it performant? |
nice first draft tho |
The three comments you got there are not needed, can you remove them? |
Sure, I through they were useful |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already looks a lot better, nice!
just some small things left
constructor(val) { | ||
this.cache = String(val).split(/[\n\r]/); | ||
this.cache = this.cache.filter((url) => url.length > 0); | ||
this.cache = new Map(this.cache.map((url) => [url, true])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a lot better!
maybe don't write all of them in this.cache repeatedly, that looks confusing IMO, just the last value?
the ones before can either be const
s, or even a oneliner if you feel like it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any other way, how would we cache only last line? I mean it would only check for one url :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant something like
const splitStrings = ..
const filteredArray = ..
this.cache= mapFrom(filteredArray)
Instead of writing onto this.cache three times
once: false, | ||
execute(msg) { | ||
if (cache.has(msg.content)) { | ||
msg.delete(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe return this? then it could theoretically be awaited outside of this func
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no reason for awaiting Message.prototype.delete method, but I noted that one!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO since this function is essentially an async function it should return a promise. No matter if we want to actually wait for it, it's just more transparent and intuitive that way 🤷🏻♂️
Unrelated to the PR review comments, I just noticed this will only delete messages that are only the URL Edit: maybe use something like this (https://www.npmjs.com/package/get-urls) to find all URLs in a message, then run the existing test on all of them |
Hm.. I will try to solve this problem today, but I can code at around 4PM. Thanks for all reports! |
🔧 Auto mod
In this PR I added auto mod that deletes messages with forbidden url. Scam URLs are stored in
/data/scam-urls.txt
so feel free to edit them!