Add /insult command
This commit is contained in:
parent
a8562a288f
commit
edae155934
@ -0,0 +1,40 @@
|
|||||||
|
package eu.mikroskeem.bot.maerahn.commands;
|
||||||
|
|
||||||
|
import eu.mikroskeem.bot.maerahn.Bot;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.telegram.telegrambots.TelegramApiException;
|
||||||
|
import org.telegram.telegrambots.api.methods.send.SendMessage;
|
||||||
|
import org.telegram.telegrambots.api.objects.Chat;
|
||||||
|
import org.telegram.telegrambots.api.objects.User;
|
||||||
|
import org.telegram.telegrambots.bots.AbsSender;
|
||||||
|
import org.telegram.telegrambots.bots.commands.BotCommand;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class InsultCommand extends BotCommand {
|
||||||
|
private Random randomGenerator = new Random();
|
||||||
|
Logger logger;
|
||||||
|
private final List<String> insults = Arrays.asList(
|
||||||
|
"https://i.imgur.com/Tg7Ayp6.png",
|
||||||
|
"https://i.imgur.com/wovZxfq.png",
|
||||||
|
"https://i.imgur.com/7h4CQoH.png",
|
||||||
|
"https://i.imgur.com/4aRm55r.png"
|
||||||
|
);
|
||||||
|
public InsultCommand(Bot bot){
|
||||||
|
super("insult", "Send random insult");
|
||||||
|
logger = bot.logger;
|
||||||
|
}
|
||||||
|
@Override public void execute(AbsSender absSender, User user, Chat chat, String[] strings) {
|
||||||
|
SendMessage message = new SendMessage();
|
||||||
|
message.setChatId(chat.getId().toString());
|
||||||
|
message.setText(insults.get(randomGenerator.nextInt(insults.size())));
|
||||||
|
try {
|
||||||
|
absSender.sendMessage(message);
|
||||||
|
} catch (TelegramApiException e){
|
||||||
|
logger.error("Failed to send reply for /insult command!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user