Add Guild.acronym
Summary
This PR adds an acronym property to Guild that returns the characters that show up when a server has no icon set.
The property returns a cached version (_acronym) since it rarely, if ever, changes.
I got this idea from the discord.js library. I have converted it to Python as is.
Discussion post: https://canary.discord.com/channels/336642139381301249/1279035934192439388
Checklist
- [x] If code changes were made then they have been tested.
- [x] I have updated the documentation to reflect the changes.
- [ ] This PR fixes an issue.
- [x] This PR adds something new (e.g. new method or parameters).
- [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed)
- [ ] This PR is not a code change (e.g. documentation, README, ...)
I have two main issues with this.
- The current implementation wastes memory for those who do not care about this feature (i.e. most people)
- The current implementation feels dodgy. It's using regex for no good reason and expensively so, it seems like it's a 1:1 port of JS code without porting it to the target language's strength.
Other than that I'm not sure on the overall merit of the PR. Is this a commonly requested feature? If you do a simple search of nameAcronym on GitHub you don't get that many results of people actually using it.
I have two main issues with this.
- The current implementation wastes memory for those who do not care about this feature (i.e. most people)
- The current implementation feels dodgy. It's using regex for no good reason and expensively so, it seems like it's a 1:1 port of JS code without porting it to the target language's strength.
Other than that I'm not sure on the overall merit of the PR. Is this a commonly requested feature? If you do a simple search of
nameAcronymon GitHub you don't get that many results of people actually using it.
1 & 2. Fair points. Unfortunately, I don't know how to fix that, as I am very new to regex usage. Reviews are welcome.
This is not a requested feature, but I thought it would fit in between the other features, as others pointed out, like Message.system_content, Member.top_role, etc.
From what I understood, I believe ''.join(word[0] for word in self.name.split()) suffices as a way without regex?
From what I understood, I believe
''.join(word[0] for word in self.name.split())suffices as a way without regex?
Unfortunately not, there are edge cases that apply to this, such as "X of Y" and "X's thing". It's a bit more involved.
Unfortunately not, there are edge cases that apply to this, such as "X of Y" and "X's thing". It's a bit more involved.
Interesting, I just tested the examples you gave on both my mobile and desktop client, and they show up as "XoY" and "Xt", respectively. I ran my code snippet and it did get it right.