use of net.kodehawa.mantarobot.utils.commands.NewRateLimiter in project MantaroBot by Mantaro.
the class GameCmds method game.
@Subscribe
public void game(CommandRegistry cr) {
final NewRateLimiter rateLimiter = new NewRateLimiter(Executors.newSingleThreadScheduledExecutor(), 4, 6, TimeUnit.SECONDS, 450, true) {
@Override
protected void onSpamDetected(String key, int times) {
log.warn("[Game] Spam detected for {} ({} times)!", key, times);
}
};
SimpleTreeCommand gameCommand = (SimpleTreeCommand) cr.register("game", new SimpleTreeCommand(Category.GAMES) {
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Guessing games.").addField("Games", "`~>game character` - **Starts an instance of Guess the character (anime)**.\n" + "`~>game pokemon` - **Starts an instance of who's that pokemon?**\n" + "`~>game number` - **Starts an instance of Guess The Number**`\n" + "`~>game lobby` - **Starts a chunk of different games, for example `~>game lobby pokemon, trivia` will start pokemon and then trivia.**\n" + "`~>game multiple` - **Starts multiple instances of one game, for example `~>game multiple trivia 5` will start trivia 5 times.**\n" + "`~>game wins` - **Shows how many times you've won in games**", false).addField("Considerations", "The pokemon guessing game has around *900 different pokemon* to guess, " + "where the anime guessing game has around 60. The number in the number guessing game is a random number between 0 and 150.\n" + "To start multiple trivia sessions please use `~>game trivia multiple`, not `~>trivia multiple`", false).build();
}
}.addSubCommand("character", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
startGame(new Character(), event);
}
}).addSubCommand("pokemon", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
startGame(new Pokemon(), event);
}
}).addSubCommand("number", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
startGame(new GuessTheNumber(), event);
}
}));
gameCommand.setPredicate(event -> Utils.handleDefaultNewRatelimit(rateLimiter, event.getAuthor(), event));
gameCommand.createSubCommandAlias("pokemon", "pokémon");
gameCommand.createSubCommandAlias("number", "guessthatnumber");
gameCommand.addSubCommand("wins", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
Member member = Utils.findMember(event, event.getMember(), content);
if (member == null)
return;
event.getChannel().sendMessage(EmoteReference.POPPER + member.getEffectiveName() + " has won " + MantaroData.db().getPlayer(member).getData().getGamesWon() + " games").queue();
}
});
gameCommand.addSubCommand("lobby", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
if (content.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't specify anything to play!").queue();
return;
}
// Stripe all mentions from this.
String[] split = mentionPattern.matcher(content).replaceAll("").split(", ");
if (split.length < 1 || split.length == 1) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify two games at least!").queue();
return;
}
LinkedList<Game> gameList = new LinkedList<>();
for (String s : split) {
switch(s.replace(" ", "")) {
case "pokemon":
gameList.add(new Pokemon());
break;
case "trivia":
gameList.add(new Trivia(null));
break;
case "number":
gameList.add(new GuessTheNumber());
break;
case "character":
gameList.add(new Character());
break;
}
}
if (gameList.isEmpty() || gameList.size() == 1) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify two games at least (Valid games: character, pokemon, number, trivia)!").queue();
return;
}
startMultipleGames(gameList, event);
}
});
gameCommand.addSubCommand("multiple", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
String[] values = SPLIT_PATTERN.split(content, 2);
if (values.length < 2) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify the game and the number of times to run it").queue();
return;
}
int number;
try {
number = Integer.parseInt(values[1]);
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Invalid number of times!").queue();
return;
}
if (number > 10) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You can only start a maximum of 10 games of the same type at a time!").queue();
return;
}
LinkedList<Game> gameList = new LinkedList<>();
for (int i = 0; i < number; i++) {
switch(values[0].replace(" ", "")) {
case "pokemon":
gameList.add(new Pokemon());
break;
case "trivia":
gameList.add(new Trivia(null));
break;
case "number":
gameList.add(new GuessTheNumber());
break;
case "character":
gameList.add(new Character());
break;
}
}
if (gameList.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify a valid game! (Valid games: character, pokemon, number, trivia)").queue();
return;
}
startMultipleGames(gameList, event);
}
});
}
Aggregations