Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum TrickCMDType {
LIST("-l", "-list"),
TRANSFER("-t", "-transfer"),
LOCK("-lock"),
FIND("-f", "-find"),
NONE();

private String[] strings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

public class TrickCommand implements IBasicCommand {
private static final boolean ALLOW_SCRIPT_TRICKS = true;
Expand Down Expand Up @@ -497,13 +498,40 @@ public CommandResult execute(Message message, Arguments args) {
}
} else if (type == TrickCMDType.TRANSFER) {
// TODO: Add transfer ability...
} else if (type == TrickCMDType.FIND) {
var tricks = getTricksForGuild(guildID);
if (trickID == null) trickID = ".*"; // Match any on error
String finalTrickID = trickID;
tricks = tricks.stream().filter((trick) ->
trick.getTrickID().contains(finalTrickID)
|| trick.getTrickID().matches(finalTrickID)).collect(Collectors.toList());
MessageChannelUnion channel = message.getChannel();
if (!tricks.isEmpty()) {
PagedList<String> trickList = createTricks(guildID, tricks);
channel.sendMessage("""
Finding matching tricks...
""").queue((m -> {
PAGES.put(m.getId(), trickList);
TaskScheduler.getExecutor().schedule(new RunnableTask<>(m, (d) -> removeTricksList(d.get())), 10, TimeUnit.MINUTES);
updateTrickListMessage(trickList, m, true);
})
);


} else {
channel.sendMessage("""
No matching tricks found
""").queue();
}
return CommandResult.PASS;
}

/*
!trick -s trickID
!trick -r trickID
!trick -i trickID
!trick -l <10>
!trick -f <trickname or regex>

!trick -e trickID -suppress -content Hello There!
!trick -e trickID -script msg.reply(''Hello!');
Expand Down Expand Up @@ -568,7 +596,7 @@ public String commandId() {

@Override
public List<String> commandAliases() {
return CommandAlias.create(this, "tricks", "tr");
return CommandAlias.create(this, "tricks", "tr", "trick");
}

@Override
Expand Down Expand Up @@ -602,6 +630,10 @@ public String usage() {

## How to show a list of tricks:
`!tricks -l 10`

## How to find tricks:
`!tricks -f installerlogs`
`!tricks -f create.*`
""";
}

Expand Down Expand Up @@ -658,6 +690,15 @@ private PagedList<String> createTricks(long guildID, int entries) {
return tricks;
}

private PagedList<String> createTricks(long guildID, List<Trick> tricks) {
PagedList<String> trickList = new PagedList<>();

Object[] LIST = tricks.stream().map(Trick::getTrickID).toArray();
trickList.rebuild(Arrays.copyOf(LIST, LIST.length, String[].class), tricks.size());

return trickList;
}

public void onButton(DiscordEvent<ButtonInteractionEvent> event) {
var interaction = event.getInstance();

Expand Down