-
- Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix for Issue #191 #200
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
Fix for Issue #191 #200
Conversation
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.
Don't set a hard limit. what if people has rolenames longer than that?
| It is similar to what Dyno does when using whois on a user with a lot of roles. |
| i dont think that is relevant to modmail? |
| It will at least solve the issue, so best to deploy this now, if needed changes can be made later |
| For your question @fourjr if any user has more roles, then just change value in |
| I suggest checking the size of the description and ensure it does not cross the limit. |
| Instead of using a role number limit it would be more robust to use a character limit. |
| Will see what can be done and report back. |
In separate server mode, the Max character count for Discord roles is 100. So this is where character count is important unlike the non separate mode where it uses mentions so only IDs take up the character count. But pretty sure no one is gonna max that limit. I guess the average max amount of characters for a role is around 40, and bot can handle up to 1024 characters. But at the same time, need to make space for other characters in the embed so I decided to allow up to 20 roles that can be displayed, up to around 800 characters so there is enough room for the other characters in the embed, including the full username. ModMail devs can adjust this amount if needed.
| After doing some extended testing and modifications, here is the final version of the thread.py file. Some things to point out:
This is the best that could be done, hope this is sufficient. Below is a screenshot on what the thread creation embed looks like when a user has more than 40 roles, in non-separate server mode. Role count is also there. |
| Wouldn't a simple |
| You were right. I just checked the Discord developer docs and the field.value, which is where all the roles are displayed can't exceed more than 1024 characters. I edited the file and set the character limit to 1024 for both separate and non-separare server modes. Now I'm fully confident it is ready to merge and deploy the update. |
core/thread.py Outdated
| role_names = ' '.join(r.mention for r in roles | ||
| if r.name != "@everyone") | ||
| for r in roles: | ||
| count = count + 1 |
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.
count += 1
core/thread.py Outdated
| inline=True) | ||
| if role_names: | ||
| embed.add_field(name='Roles', | ||
| count = count - 1 |
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.
count -= 1
core/thread.py Outdated
| if r.name != "@everyone") | ||
| for r in roles: | ||
| count = count + 1 | ||
| charCounter = ', '.join(r.name for r in roles |
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.
use snake_case
core/thread.py Outdated
| role_names = ', '.join(r.name for r in roles | ||
| if r.name != "@everyone") | ||
| else: | ||
| role_names = "Due to Discord limitations the bot can't display roles that contain more than 1024 characters in total." |
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 think it's best to show what we can & put ellipsis after
This would mess up role mentions, I think it'd be better to iteratively concatenate role names/mentions until the length of the string is just under 1024. e.g. roles = [] for role in user.roles: fmt = role.name if sep_server else role.mention if sum(len(r) for r in roles) + len(fmt) > 1000: roles.append('...') break roles.append(fmt) seperator = ', ' if sep_server else ' ' roles = seperator.join(roles) |
| What about commands.Paginator? It implements that iirc |
| @fourjr My opinion is you create a new pull request by your own implementation and show that to us would be great for you & everyone :D |
| What else can be done differently? My latest commit I have tested it in both separate and non-separate mode and I believe it is fine the way it is. The problem was the field.value where the role lists are displayed can only go up to 1024 characters according to Discord developer docs. So I made it only display up to 1024 characters if it goes more than that it will say can't show roles but it will at least not crash and cause problems for some servers. Please test it by creating a thread for a user that has a lot of roles and see if anything needs to be changed but I'm pretty sure there's nothing else that need to be done and ready for deployment. |
| And before starting to edit the thread.py file I checked what the original problem was by reproducing the bug and seeing what comes up in the logs: You can see it was the field.value exceeding 1024 characters and due to this the thread creation embed won't show at all. With my latest commit this problem doesn't happen anymore. |
| We don't develop modmail just for "it to work" and getting the fastest solution. It is also for style and the cleanest possible code. If you feel that you want to stick to your messy code, feel free to do so in your own fork. |
| Here's a cleaner code. If you said you wanted clean code we could have done it before. Anyway here it is. Let us know if there's anything else. |
3.7.3 is yet to be supported by Heroku.
Update bot
| A bit late but I implemented this in 2db8b85 |

Here is the fix for Issue #191. The problem was caused due to Discord's character limit, if the user has too many roles the thread creation process won't work properly. This PR sets a limit on how many roles the bot can display before it says "Too many roles to show" therefore not exceeding Discord's character limit. I have set the value to 21, meaning it can display up to 20 roles before it says too many roles.
Initially I tried setting the value to 41, but then the embed message of where the user info and roles are shown wasn't sending at all, so I reduced the value to 21 and now it's working fine.