Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

TymianekPL
Copy link

🔧 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!

src/events/autoMod.js Outdated Show resolved Hide resolved
src/events/autoMod.js Outdated Show resolved Hide resolved
@the94air
Copy link

the94air commented Apr 6, 2022

@TymianekPL lol, any plans on making it performant?

@the94air
Copy link

the94air commented Apr 6, 2022

nice first draft tho

@lostdesign
Copy link
Member

The three comments you got there are not needed, can you remove them?

@TymianekPL
Copy link
Author

Sure, I through they were useful

Copy link

@maybeanerd maybeanerd left a 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]));

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 consts, or even a oneliner if you feel like it

Copy link
Author

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

Copy link

@maybeanerd maybeanerd Apr 6, 2022

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();

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

Copy link
Author

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!

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 🤷🏻‍♂️

@maybeanerd
Copy link

maybeanerd commented Apr 6, 2022

Unrelated to the PR review comments, I just noticed this will only delete messages that are only the URL
Not really resilient as scammers would just need to add some spaces before or after the URL 🤔
Might want to upgrade this to some fuzzier match later on?

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

@TymianekPL
Copy link
Author

Hm.. I will try to solve this problem today, but I can code at around 4PM. Thanks for all reports!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants