use of tk.ardentbot.utils.rpg.TriviaGame in project Ardent by adamint.
the class TriviaChecker method check.
static void check(MessageReceivedEvent event) throws Exception {
if (event.isFromType(ChannelType.TEXT)) {
User user = event.getAuthor();
Guild guild = event.getGuild();
Shard shard = GuildUtils.getShard(guild);
TextChannel channel = event.getTextChannel();
for (Iterator<TriviaGame> iterator = Trivia.gamesInSession.iterator(); iterator.hasNext(); ) {
TriviaGame triviaGame = iterator.next();
if (triviaGame.getGuildId().equalsIgnoreCase(guild.getId()) && triviaGame.getTextChannelId().equalsIgnoreCase(channel.getId())) {
if (!triviaGame.isAnsweredCurrentQuestion()) {
if (triviaGame.isSolo() && !triviaGame.getCreator().equalsIgnoreCase(user.getId()))
return;
String content = event.getMessage().getContent();
if (triviaGame.getCurrentTriviaQuestion() != null) {
final boolean[] correct = { false };
triviaGame.getCurrentTriviaQuestion().getAnswers().forEach(a -> {
if (a.equalsIgnoreCase(content))
correct[0] = true;
});
if (correct[0]) {
triviaGame.addPoint(user);
shard.help.sendEditedTranslation("{0} got it right!", user, channel, user.getAsMention());
if (triviaGame.getRound() != triviaGame.getTotalRounds()) {
Trivia.dispatchRound(guild, channel, guild.getMemberById(triviaGame.getCreator()).getUser(), triviaGame, triviaGame.getEx());
} else
triviaGame.finish(shard, shard.help);
}
}
}
}
}
}
}
use of tk.ardentbot.utils.rpg.TriviaGame in project Ardent by adamint.
the class Trivia method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("Start a new trivia game", "start", "start") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
for (TriviaGame triviaGame : gamesInSession) {
if (triviaGame.getGuildId().equalsIgnoreCase(guild.getId())) {
sendTranslatedMessage("There's already a game in session in this server!", channel, user);
return;
}
}
if (gamesSettingUp.contains(guild.getId())) {
sendTranslatedMessage("There's already a game in session in this server!", channel, user);
return;
}
gamesSettingUp.add(guild.getId());
sendTranslatedMessage("Do you want to play this solo? Type `yes` if so, or `no` if not", channel, user);
interactiveOperation(channel, message, (soloMessage) -> {
String content = soloMessage.getContent();
boolean solo;
solo = content.equalsIgnoreCase("yes");
TriviaGame currentGame = new TriviaGame(user, solo, (TextChannel) channel, 15);
gamesInSession.add(currentGame);
sendTranslatedMessage("The game is starting! Type your answers in this channel. You have **15** seconds to answer " + "each question.", channel, user);
commenceRounds(guild, (TextChannel) channel, user, currentGame);
gamesSettingUp.remove(guild.getId());
});
}
});
subcommands.add(new Subcommand("Stop a currently active trivia game", "stop", "stop") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
if (gamesInSession.stream().filter(game -> game.getGuildId().equals(guild.getId())).count() > 0 || gamesSettingUp.contains(guild.getId())) {
gamesSettingUp.remove(guild.getId());
gamesInSession.removeIf(g -> g.getGuildId().equals(guild.getId()));
sendTranslatedMessage("Stopped the trivia game in session.", channel, user);
} else {
sendTranslatedMessage("There isn't a trivia game running!", channel, user);
}
} else
sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
}
});
}
Aggregations