Repository navigation
tag qol - #602
tag qol#602illuminator3 wants to merge 14 commits into
Conversation
illuminator3
commented
Oct 3, 2022

its a little different, the auto-complete provides option before the command usage, but lets say the user still writes and invalid id (which is possible) then the reply will contain some buttons for possible suggestions |
|
i see. fair. |
|
Kudos, SonarCloud Quality Gate passed! |
| /** | ||
| * @return the component id generator used by {@link #generateComponentId(String...)} and | ||
| * {@link #generateComponentId(Lifespan, String...)} | ||
| */ |
There was a problem hiding this comment.
This is a core API class, it needs outstanding and full Javadoc.
Maybe write:
/**
* Gets the generator used to create component IDs.
* <p>
* In general, prefer using {@link ...} and {@link ...} instead of interacting with the generator directly.
*
* @return the generator
*/ | } | ||
|
|
||
| /** | ||
| * Sends the reply for a successfull /tag use (i.e. the given tag exists) |
| private void sendTagReply(IReplyCallback callback, String userName, String tag, | ||
| @Nullable String commandString, @Nullable String replyToUser) { |
There was a problem hiding this comment.
I have some trouble with some variable names. Some of them dont really say what they are about.
callback- callback of what? I think it would be easier and more idiomatic if you just call itevent(even if the type is a level higher).- its easy to confuse the two users that play a role here, since both are called "user". maybe keep
userName, but renamereplyToUsertoreplyTargetUser. if u want, renameuserNametoinvokerUserNamemaybe, then its super clear.
| } | ||
| message.queue(); | ||
| .build()) | ||
| .setContent(replyToUserOpt.orElse("")) |
There was a problem hiding this comment.
dont know the javadoc of setContent, but many JDA methods accept null. If thats the case, this could be a nice improvement, since u dont need the optional anymore then
| .comparingInt(candidate -> StringDistances.editDistance(id, candidate))) | ||
| .limit(TAG_SUGGESTIONS_AMOUNT) | ||
| .toList(); | ||
| List<List<String>> partition = ListUtils.partition(candidates, 5); |
There was a problem hiding this comment.
move that down a few lines, to where its used first
| : ", did you perhaps mean any of the following?")) | ||
| .setEphemeral(true); | ||
|
|
||
| for (List<String> part : partition) { |
There was a problem hiding this comment.
naming issue: partition and partitions, would be easier to understand.
Or batch and batches
|
|
||
| for (List<String> part : partition) { | ||
| action.addActionRow(part.stream() | ||
| .map(i -> Button.secondary(componentIdGenerator.generate(new ComponentId( |
There was a problem hiding this comment.
i is confusing, sounds like an index, but its actually the suggestion. please write it out
| .map(i -> Button.secondary(componentIdGenerator.generate(new ComponentId( | ||
| UserInteractorPrefix.getPrefixedNameFromClass(TagCommand.class, "tag"), | ||
| Arrays.asList(i, | ||
| userToReplyTo != null ? userToReplyTo.getAsUser().getAsMention() | ||
| : null)), | ||
| Lifespan.REGULAR), i)) |
There was a problem hiding this comment.
This whole thing reads a bit complex, being nested in the map and loop. Id move this button creation out to a quick private helper method. sth like map(this::createSuggestionButton) or similar.
| for (List<String> part : partition) { | ||
| action.addActionRow(part.stream() | ||
| .map(i -> Button.secondary(componentIdGenerator.generate(new ComponentId( | ||
| UserInteractorPrefix.getPrefixedNameFromClass(TagCommand.class, "tag"), |
There was a problem hiding this comment.
the usage of "tag" here is a bit dangerous. if someone renames the command, they will for sure forget to adjust it here as well.
try to link it somehow. either by giving it as method argument (like u did with the component ID genererator), or by having a constant between here and TagCommand.
| * @return the generator | ||
| */ | ||
| protected final ComponentIdGenerator getComponentIdGenerator() { | ||
| protected final @Nullable ComponentIdGenerator getComponentIdGenerator() { |
There was a problem hiding this comment.
the method is not supposed to return a nullable.
its a mistake to call the method before intiialization, not allowed. the method should fail-fast if its called before.
should probably also be added to its javadoc. thanks
|
this pr is not valid anymore, we use auto-complete feature now, and while using this feature a user can only put the registered option, u can close this pr now |
|
thank you for appreciating all of the work I put into this already |
This is false, the user can still put any text that they want, autocomplete doesn't force anything. |
|
This PR is being closed due to inactivity, can be opened later if need be. |







