Created the RandomErrorHandler to send randomized error messages from a list to the author if the message could not be found

This commit is contained in:
mathias 2021-10-02 17:41:50 +02:00
parent ab0da5e43d
commit f754b87b73
No known key found for this signature in database
GPG Key ID: 8950DF62139C852A

View File

@ -0,0 +1,28 @@
package de.gnmyt.autoresponder.handler;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class RandomErrorHandler extends NotFoundHandler {
private final ArrayList<String> messages = new ArrayList<>();
/**
* Constructor of the {@link RandomErrorHandler}.
*
* It sends a random error message to the author if the message could not be found
* @param randomErrorMessages The error messages you want to add
*/
public RandomErrorHandler(String... randomErrorMessages) {
messages.addAll(Arrays.asList(randomErrorMessages));
}
@Override
public List<String> handleRequest(String sender, String message) {
Collections.shuffle(messages);
return Collections.singletonList(messages.get(0));
}
}