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

Regex help #42

Closed
dannymichel opened this issue Nov 19, 2017 · 15 comments
Closed

Regex help #42

dannymichel opened this issue Nov 19, 2017 · 15 comments

Comments

@dannymichel
Copy link

I apologize as im aware that this isn't a help forum, but I really don't know anyone who knows regex.
I was wondering if I can have help with 3 things:
3 separate channels i need to do things in
#channel 1 - delete everything that begins with 'http'
#cannel 2 - delete anything that isn't an image(no text what-so-ever)
#channel 3 - delete anything that isn't an image or starts with 'http'(only links and images allowed - no other text than links)

@skeith
Copy link
Contributor

skeith commented Nov 19, 2017

You should try and play with http://www.regex101.com

@calebj
Copy link
Owner

calebj commented Nov 20, 2017

Channels 1 and 2 should be pretty easy, but you should keep in mind that any attachment can be posted and seen as having no text. I'll have to check to see if empty messages are something that can be matched, but I'm fairly certain they are. Can you give these a try and then message me on Discord?

1: ^http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+, inclusive. This will only match messages that begin with a URL. Replace the ^ at the beginning with .* to match anywhere in the message.
2: ^$, exclusive. Deletes messages that aren't empty.
3: ^(http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+|$), exclusive. Deletes messages have text but don't start with a URL.

@skeith
Copy link
Contributor

skeith commented Nov 20, 2017

caleb, is recensor able to work per channel instead of per server

@calebj
Copy link
Owner

calebj commented Nov 20, 2017

It's capable of both.

@skeith
Copy link
Contributor

skeith commented Nov 20, 2017

ah right, I missed that latter optional argument

@dannymichel
Copy link
Author

thank you. so it would literally be
.recensor add ^http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+ thisiswhereiputthechannelid ?

@dannymichel
Copy link
Author

.recensor add ^(http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+|$ excl 377913250962210816 and .recensor add ^http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+ incl 370169460184580095 doesnt seem to work. do i need to toggle the feature on or something? the bot is admin

@calebj
Copy link
Owner

calebj commented Nov 20, 2017

I'm not sure what you're appending those numbers for, but they'll probably get discarded. You should also be aware that mods and admins are immune to the filter, in case you're testing with yourself.

@skeith
Copy link
Contributor

skeith commented Nov 20, 2017

@calebj I assume those numbers are channel ID

@calebj
Copy link
Owner

calebj commented Nov 20, 2017

Ah, right. I forgot the converters supported that.

Since your pattern has no spaces, it should be working. Like I said, you're immune from the filter yourself.

The way I test things like this is with an alt. If regex101 and/or testing in a python interpreter are good, it's probably because you're immune to the filter.

@dannymichel
Copy link
Author

I'm testing it by having members test it

@calebj calebj mentioned this issue Nov 20, 2017
8 tasks
@calebj
Copy link
Owner

calebj commented Nov 20, 2017

@dannymichel Can you DM me a list of example messages you've tried so I can perform local testing?

@dannymichel
Copy link
Author

sure where/how would i dm you

@calebj
Copy link
Owner

calebj commented Nov 20, 2017

Head to this channel for starters. The cog support server is the best place to ask these kinds of questions in general, really.

@calebj
Copy link
Owner

calebj commented Nov 21, 2017

Solved via Discord

@calebj calebj closed this as completed Nov 21, 2017
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

No branches or pull requests

3 participants