-
-
Notifications
You must be signed in to change notification settings - Fork 101
tag qol #602
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
tag qol #602
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. |
application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/BotCommandAdapter.java
Show resolved
Hide resolved
application/src/test/java/org/togetherjava/tjbot/commands/SlashCommandAdapterTest.java
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java
Outdated
Show resolved
Hide resolved
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
*/
application/src/main/java/org/togetherjava/tjbot/commands/BotCommandAdapter.java
Show resolved
Hide resolved
} | ||
|
||
/** | ||
* Sends the reply for a successfull /tag use (i.e. the given tag exists) |
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.
missing dot
private void sendTagReply(IReplyCallback callback, String userName, String tag, | ||
@Nullable String commandString, @Nullable String replyToUser) { |
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 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 renamereplyToUser
toreplyTargetUser
. if u want, renameuserName
toinvokerUserName
maybe, then its super clear.
} | ||
message.queue(); | ||
.build()) | ||
.setContent(replyToUserOpt.orElse("")) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |