use of net.kodehawa.mantarobot.core.modules.commands.SimpleTreeCommand 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);
}
});
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleTreeCommand in project MantaroBot by Mantaro.
the class OsuStatsCmd method osustats.
@Subscribe
public void osustats(CommandRegistry cr) {
ITreeCommand osuCommand = (SimpleTreeCommand) cr.register("osustats", new SimpleTreeCommand(Category.GAMES) {
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "osu! command").setDescription("**Retrieves information from osu! (Players and scores)**.").addField("Usage", "`~>osu best <player>` - **Retrieves best scores of the user specified in the specified game mode**.\n" + "`~>osu recent <player>` - **Retrieves recent scores of the user specified in the specified game mode.**\n" + "`~>osu user <player>` - **Retrieves information about a osu! player**.\n", false).addField("Parameters", "`player` - **The osu! player to look info for.**", false).build();
}
});
osuCommand.addSubCommand("best", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Retrieving information from osu! server...").queue(sentMessage -> {
Future<String> task = pool.submit(() -> best(content));
try {
sentMessage.editMessage(task.get(16, TimeUnit.SECONDS)).queue();
} catch (Exception e) {
if (e instanceof TimeoutException) {
task.cancel(true);
sentMessage.editMessage(EmoteReference.ERROR + "The osu! api seems to be taking a nap. Maybe try again later?").queue();
} else {
SentryHelper.captureException("Error retrieving results from osu!API", e, OsuStatsCmd.class);
}
}
});
}
});
osuCommand.addSubCommand("recent", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Retrieving information from server...").queue(sentMessage -> {
Future<String> task = pool.submit(() -> recent(content));
try {
sentMessage.editMessage(task.get(16, TimeUnit.SECONDS)).queue();
} catch (Exception e) {
if (e instanceof TimeoutException) {
task.cancel(true);
sentMessage.editMessage(EmoteReference.ERROR + "The osu! api seems to be taking a nap. Maybe try again later?").queue();
} else
log.warn("Exception thrown while fetching data", e);
}
});
}
});
osuCommand.addSubCommand("user", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
event.getChannel().sendMessage(user(content)).queue();
}
});
cr.registerAlias("osustats", "osu");
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleTreeCommand in project MantaroBot by Mantaro.
the class MiscCmds method misc.
@Subscribe
public void misc(CommandRegistry cr) {
ITreeCommand miscCommand = (ITreeCommand) cr.register("misc", new SimpleTreeCommand(Category.MISC) {
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Misc Commands").setDescription("**Miscellaneous funny/useful commands.**").addField("Usage", "`~>misc reverse <sentence>` - **Reverses any given sentence.**\n" + "`~>misc rndcolor` - **Gives you a random hex color.**\n", false).addField("Parameter Explanation", "`sentence` - **A sentence to reverse.**\n" + "`@user` - **A user to mention.**", false).build();
}
}.addSubCommand("reverse", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
if (content.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't provide any message to reverse!").queue();
return;
}
new MessageBuilder().append(new StringBuilder(content).reverse().toString()).stripMentions(event.getGuild(), Message.MentionType.EVERYONE, Message.MentionType.HERE).sendTo(event.getChannel()).queue();
}
}).addSubCommand("rndcolor", new SubCommand() {
@Override
protected void call(GuildMessageReceivedEvent event, String content) {
event.getChannel().sendMessage(String.format(EmoteReference.TALKING + "The random color is %s", randomColor())).queue();
}
}));
miscCommand.createSubCommandAlias("rndcolor", "randomcolor");
}
Aggregations