2

I want my bot to delete the URLs posted by the members. Im not sure about how to detect that a URL has been posted as they could start from https or www. Or something else altogether... And insight is appreciated !

EDIT: Found similar question to mine.

Regular expression for URL validation (in JavaScript)

Successfully tackled the same using a npm plugin called Linkify.

Consider this closed.

Ken Senpai
  • 46
  • 1
  • 7
  • What have you tried so far? Do you know how to make a basic bot? – Blundering Philosopher Apr 23 '18 at 11:11
  • I've a well made bot with complex features like Giveaway , MySQL based XP levels etc.. I just want to know what should I compare the message to identify it as a url – Ken Senpai Apr 23 '18 at 21:58
  • Ok good to know - I'd recommend adding more detail to your question (like what you've tried - a.k.a. a super simple basic bot with a section that shows where your URL-checking code *COULD* go). Since right now your question has 3 votes to be closed... FYI – Blundering Philosopher Apr 23 '18 at 22:41
  • Have you looked at regex expressions? Here's an interesting SO question about URL Validation (in javascript) via regex: https://stackoverflow.com/questions/1410311/regular-expression-for-url-validation-in-javascript – Blundering Philosopher Apr 23 '18 at 22:46
  • Thats great help, I will see where to go from there, all I wanted was a starting point ... How do I close /mark this a answered – Ken Senpai Apr 24 '18 at 04:12
  • Cool, hope it gets you where you need to go. I added that comment in an answer below, so you can mark it accepted and that pretty much closes it up. – Blundering Philosopher Apr 24 '18 at 10:39

1 Answers1

2

I'd recommend looking into regular expressions (regex) for URL Validation.

Here's another SO question that you can use as a starting point: Regular expression for URL validation (in JavaScript)

One recommended approach is using a regex string like this (from an answer in that question):

/^(ftp|http|https):\/\/[^ "]+$/.test(url)

This expression matches a full string, so you'll have to either edit this regex to match any place inside a string, or do some message content manipulation before using that regex.

Blundering Philosopher
  • 6,245
  • 2
  • 43
  • 59