-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(/profile) add Lichess username auto complete fixes #43
- Loading branch information
Showing
10 changed files
with
92 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/Discord/HandlerModules/AutoCompleteContextModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package Discord.HandlerModules; | ||
|
||
import Abstraction.Context.ContextHandler; | ||
import Discord.HelperModules.AutoCompleteHelperModule; | ||
import Discord.MainHandler.AntiSpam; | ||
import chariot.Client; | ||
import com.github.bhlangonijr.chesslib.Board; | ||
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; | ||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; | ||
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; | ||
|
||
public class AutoCompleteContextModule implements ContextHandler { | ||
|
||
|
||
@Override | ||
public void handleLogic(MessageContextInteractionEvent context, SlashCommandInteractionEvent slashEvent, ButtonInteractionEvent buttonEvent, ModalInteractionEvent eventModal, CommandAutoCompleteInteractionEvent autoEvent, Client client, Board board, Board blackboard, AntiSpam spam, AntiSpam dailyspam, AntiSpam watchlimit) { | ||
|
||
AutoCompleteHelperModule autoHelper = new AutoCompleteHelperModule(); | ||
|
||
if(autoEvent.getName().equalsIgnoreCase("profile")){ | ||
autoHelper.onLichessProfileAutoComplete(autoEvent, client); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/Discord/HelperModules/AutoCompleteHelperModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package Discord.HelperModules; | ||
|
||
import Lichess.UserProfile; | ||
import chariot.Client; | ||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import net.dv8tion.jda.api.interactions.commands.Command; | ||
import java.util.List; | ||
|
||
public class AutoCompleteHelperModule { | ||
|
||
public AutoCompleteHelperModule(){ | ||
|
||
} | ||
|
||
|
||
public void onLichessProfileAutoComplete(CommandAutoCompleteInteractionEvent event, Client client){ | ||
|
||
if(event.getName().equalsIgnoreCase("profile") && event.getFocusedOption().getName().equalsIgnoreCase("search-user")){ | ||
List<Command.Choice> options = client.users().autocompleteNames(event.getFocusedOption().getValue()).stream() | ||
.filter(username -> username.startsWith(event.getFocusedOption().getValue())) | ||
.map(username -> new Command.Choice(username, username)) | ||
.toList(); | ||
event.replyChoices(options).queue(); | ||
} | ||
|
||
} | ||
|
||
|
||
public void onSelectLichessUserNameHandleRequest(SlashCommandInteractionEvent event, Client client){ | ||
|
||
String userID = event.getOptionsByName("search-user").get(0).getAsString(); | ||
UserProfile userProfile = new UserProfile(client, userID); | ||
event.deferReply(false).queue(); | ||
event.getHook().sendMessage(userProfile.getUserProfile()).setEphemeral(false).queue(); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters