-
Notifications
You must be signed in to change notification settings - Fork 48
Parse channel and message urls with SnowflakeParser #355
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
base: main
Are you sure you want to change the base?
Conversation
6dbef75 to
0785c79
Compare
|
The parser should also handle the subdomains of other client versions (ptb, canary) if this is to be accepted, imo e.g., I use canary, and thus message and channel links are |
|
Hm, I had no idea that is a thing. How do you obtain such urls though? The one I used in the parser is obtained by right clicking and copying a link |
0785c79 to
95fedea
Compare
|
By using Discord's beta clients (e.g. for Windows ); ptb is available via the webpage; both can be used in the browser by just prepending |
|
If such urls are to be allowed, I will switch to regex matching with a group, and also check for only numbers, as at that point, it doesn't really matter. I didn't do it just because I haven't used regex for this simple case. |
Oh you mean like if you copy the url from the bar, right |
|
No; the beta clients give links that match; e.g. https://canary.discord.com/channels/789912892426027039/789924168837365810/1389617555861143764 edit: I meant that PTB (Public Test Beta) can be downloaded via Discord's website |
|
Give... how? |
|
Right clicking a message like normal Discord -> Same goes for all links that can be |
|
So Copy link button okay. I also see Discord parses all of them, so I agree with your proposal. I will probably not be able to make it today, though. |
95fedea to
7c20456
Compare
|
So, as proposed, I added ptb and canary support. I used regex from MessageParser and changed it a little. I made message id optional, and also changed * with + for the individual snowflake parts of the url. Tbh I don't understand why messageparser uses * instead of +, it seems to me that https://discord.com/// would match... But I haven't tried it yet. Let me know what you think. |
| public override ValueTask<Result<Snowflake>> TryParseAsync(string value, CancellationToken ct = default) | ||
| { | ||
| var channelLinkMatch = _channelLinkRegex.Match(value); | ||
| if (channelLinkMatch.Success) |
Check warning
Code scanning / InspectCode
Invert 'if' statement to reduce nesting Warning
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 get this tbh.
If user sends a link to a channel, it's not being parsed by Remora. On the other hand the client understands this link and visually there is no difference between a mention and a channel link. Add parsing of a channel links, without checking the whole string, only beginning 'https://discord.com/channels/' is used to check this is a url, and only the last part of the string is then used, all other parts are ignored.
7c20456 to
b36653b
Compare
Hey, a user of my bot tried to use a link in a command. It wasn't working and it causes bit of a confusion as the mention looks the same a sent link in the client. I will use this in my bot if it won't be accepted here for sure, but wanted to check with you here for feedback / to merge this to Remora.Discord directly if others will appreciate this behavior as well. I can add more validation if needed, ie. to check if there are only 2 or 3 parts after the url (guild, channel, message), and to check if they consist of all numbers if you think that is necessary. But I don't see any risks if wrong links, such as https://discord.com/channels/XYZ/XYZ/XYZ/XYZ/ are accepted.
If user sends a link to a channel, it's not being parsed by Remora. On the other hand the client understands this link and visually there is no difference between a mention and a channel link.
Add parsing of a channel links, without checking the whole string, only beginning 'https://discord.com/channels/' is used to check this is a url, and only the last part of the string is then used, all other parts are ignored.