use of tk.ardentbot.core.misc.logging.BotException in project Ardent by adamint.
the class Blackjack method showResults.
public void showResults(int bet, Hand yourHand, Hand dealerHand, Guild guild, MessageChannel channel, User user, Message message, String[] args) {
try {
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor("Blackjack | Game over", user.getEffectiveAvatarUrl(), user.getEffectiveAvatarUrl());
while (dealerHand.total() < 17) dealerHand.generate();
if (yourHand.total() > 21) {
builder.setDescription("You busted and lost {0} :frowning:".replace("{0}", RPGUtils.formatMoney(bet)));
Profile.get(user).removeMoney(bet);
} else if (dealerHand.total() > 21) {
builder.setDescription("I busted! You won {0}".replace("{0}", RPGUtils.formatMoney(bet)));
Profile.get(user).addMoney(bet);
} else if (dealerHand.total() == yourHand.total())
builder.setDescription("We tied! You don't win or lose anything >.>");
else if (dealerHand.total() < yourHand.total()) {
builder.setDescription("You had a higher numbered hand than me! You win {0}".replace("{0}", RPGUtils.formatMoney(bet)));
Profile.get(user).addMoney(bet);
} else {
builder.setDescription("I had a higher numbered hand! You lose {0}".replace("{0}", RPGUtils.formatMoney(bet)));
Profile.get(user).removeMoney(bet);
}
builder.addField("Your hand", yourHand.readable(), true);
builder.addField("My hand", dealerHand.readable(), true);
sendEmbed(builder, channel, user);
sessions.remove(user.getId());
} catch (Exception e) {
new BotException(e);
}
}
use of tk.ardentbot.core.misc.logging.BotException in project Ardent by adamint.
the class Trivia method dispatchRound.
public static void dispatchRound(Guild guild, TextChannel channel, User creator, TriviaGame currentGame, ScheduledExecutorService ex) {
try {
Shard shard = GuildUtils.getShard(guild);
currentGame.incrementRounds();
if (currentGame.getRound() >= currentGame.getTotalRounds()) {
currentGame.finish(shard, shard.help);
return;
}
if (!gamesInSession.contains(currentGame))
return;
channel.sendMessage(currentGame.displayScores(shard, shard.help).build()).queue();
TriviaQuestion triviaQuestion = triviaQuestions.get(new SecureRandom().nextInt(triviaQuestions.size()));
currentGame.setCurrentTriviaQuestion(triviaQuestion);
StringBuilder question = new StringBuilder();
question.append("**" + triviaQuestion.getCategory() + "**: " + triviaQuestion.getQuestion());
shard.help.sendTranslatedMessage(question.toString(), channel, creator);
int currentRound = currentGame.getRound();
ex.schedule(() -> {
if (!currentGame.isAnsweredCurrentQuestion() && currentRound == currentGame.getRound() && !(currentRound == currentGame.getTotalRounds())) {
try {
shard.help.sendEditedTranslation("No one got it right! The correct answer was {0}", creator, channel, triviaQuestion.getAnswers().get(0));
if (currentGame.getRound() + 1 < currentGame.getTotalRounds())
dispatchRound(guild, channel, creator, currentGame, ex);
else
currentGame.finish(shard, shard.help);
} catch (Exception e) {
new BotException(e);
}
}
}, 17, TimeUnit.SECONDS);
} catch (Exception ignored) {
}
}
use of tk.ardentbot.core.misc.logging.BotException in project Ardent by adamint.
the class Botname method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length == 1) {
sendTranslatedMessage("Enter what you want me to nickname myself", channel, user);
interactiveOperation(channel, message, howLongMessage -> {
String howLong = howLongMessage.getRawContent();
try {
guild.getController().setNickname(guild.getSelfMember(), howLong).queue(aVoid -> {
sendTranslatedMessage("Changed my nickname!", channel, user);
});
} catch (Exception e) {
new BotException(e);
}
});
} else {
String name = message.getContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "");
if (name.equalsIgnoreCase("reset")) {
name = "";
}
try {
guild.getController().setNickname(guild.getSelfMember(), name).queue(aVoid -> {
try {
sendTranslatedMessage("Changed my nickname!", channel, user);
} catch (Exception e) {
new BotException(e);
}
});
} catch (PermissionException ex) {
sendTranslatedMessage("I couldn't change my nickname, make sure I have permission to do that", channel, user);
}
}
}
use of tk.ardentbot.core.misc.logging.BotException in project Ardent by adamint.
the class Admin method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (Ardent.developers.contains(user.getId())) {
if (args.length > 1) {
if (args[1].equalsIgnoreCase("update")) {
update(this, channel);
} else if (args[1].equalsIgnoreCase("softupdate")) {
ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor();
ex.scheduleAtFixedRate(() -> {
long connections = InternalStats.collect().getMusicPlayers();
if (connections <= 1 || (secondsWaitedForRestart >= (60 * 60 * 3))) {
if (connections <= 3) {
try {
update(Admin.this, channel);
} catch (Exception e) {
new BotException(e);
}
}
}
secondsWaitedForRestart += 5;
}, 5, 5, TimeUnit.SECONDS);
} else if (args[1].equalsIgnoreCase("getloc")) {
sendTranslatedMessage(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), channel, user);
} else if (args[1].equalsIgnoreCase("usage")) {
Map<Guild, Integer> guildsByUsage = UsageUtils.sortedGuildsByCommandUsage(10);
StringBuilder sb = new StringBuilder();
guildsByUsage.forEach((key, value) -> {
sb.append(key.getName() + " (" + key.getId() + ") : " + value + "\n");
});
sendTranslatedMessage(sb.toString(), channel, user);
} else if (args[1].equalsIgnoreCase("announce")) {
String msg = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " " + args[1] + " ", "");
if (Ardent.announcement != null)
Ardent.sentAnnouncement.clear();
Ardent.announcement = "** == Important Announcement ==**\n" + msg;
for (Shard shard : getShards()) {
shard.jda.getGuilds().forEach(g -> {
Ardent.sentAnnouncement.put(g.getId(), false);
});
}
} else if (args[1].equalsIgnoreCase("addpatron")) {
List<User> mentioned = message.getMentionedUsers();
if (mentioned.size() == 1) {
User u = mentioned.get(0);
String[] uArgs = message.getRawContent().split(" ");
if (uArgs.length == 4) {
String role = uArgs[3];
if (role.equalsIgnoreCase("tier1") || role.equalsIgnoreCase("tier2") || role.equalsIgnoreCase("tier3")) {
r.table("patrons").insert(r.hashMap("user_id", u.getId()).with("tier", role)).run(connection);
channel.sendMessage("done").queue();
}
}
}
} else if (args[1].equalsIgnoreCase("addstaff")) {
List<User> mentioned = message.getMentionedUsers();
User u = mentioned.get(0);
String roleToAdd = args[3];
r.table("staff").insert(r.json(gson.toJson(new Staff(u.getId(), roleToAdd)))).run(connection);
channel.sendMessage("done").queue();
} else if (args[1].equalsIgnoreCase("stop")) {
for (Shard shard : getShards()) {
shard.jda.shutdown(true);
}
System.exit(0);
} else if (args[1].equalsIgnoreCase("restart")) {
for (Shard shard : getShards()) {
shard.jda.shutdown(true);
}
channel.sendMessage("This subcommand is untested and could fail.").queue();
Runtime.getRuntime().exec("java -jar " + getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
System.exit(0);
} else if (args[1].equalsIgnoreCase("setgameurl")) {
Ardent.gameUrl = args[2];
sendTranslatedMessage("Updated the game URL", channel, user);
} else if (args[1].equalsIgnoreCase("addmoney")) {
String[] raw = message.getRawContent().split(" ");
if (raw.length == 4) {
try {
User mentioned1 = message.getMentionedUsers().get(0);
double amount = Double.parseDouble(raw[3]);
Profile.get(mentioned1).addMoney(amount);
sendTranslatedMessage("added " + amount + " to " + mentioned1.getName(), channel, user);
} catch (Exception e) {
sendTranslatedMessage("bad", channel, user);
}
} else
sendTranslatedMessage("bad", channel, user);
} else if (args[1].equalsIgnoreCase("disable")) {
if (args.length == 2) {
StringBuilder disabledCommands = new StringBuilder();
disabledCommands.append("**Disabled Commands/Features:**\n");
Ardent.disabledCommands.forEach(s -> {
disabledCommands.append(" **>** ").append(s).append("\n");
});
sendTranslatedMessage(disabledCommands.toString(), channel, user);
} else if (args.length == 4) {
try {
boolean disable = Boolean.parseBoolean(args[2]);
System.out.println(disable);
String identifier = args[3];
if (disable) {
if (Ardent.disabledCommands.contains(identifier))
sendTranslatedMessage("This feature is already disabled", channel, user);
else {
Ardent.disabledCommands.add(identifier);
sendTranslatedMessage("disabled " + identifier, channel, user);
}
} else {
if (!Ardent.disabledCommands.contains(identifier)) {
sendTranslatedMessage("This feature is already enabled", channel, user);
} else {
Ardent.disabledCommands.remove(identifier);
sendTranslatedMessage("enabled " + identifier, channel, user);
}
}
} catch (Exception e) {
sendTranslatedMessage("/admin restrict true/false command_identifier", channel, user);
}
} else
sendTranslatedMessage("/admin restrict true/false command_identifier", channel, user);
}
}
}
}
use of tk.ardentbot.core.misc.logging.BotException in project Ardent by adamint.
the class SoftBan method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
Member userMember = guild.getMember(user);
if (userMember.hasPermission(Permission.BAN_MEMBERS)) {
List<User> mentioned = message.getMentionedUsers();
try {
User u = mentioned.get(0);
String userString = u.toString();
String uToSend = UserUtils.getNameWithDiscriminator(userString);
try {
guild.getController().ban(u, 7).queue();
guild.getController().unban(u).queue();
sendTranslatedMessage("Soft-banned **" + uToSend + "**", channel, user);
} catch (PermissionException ex) {
sendTranslatedMessage("I don't have permissions to ban!", channel, user);
}
} catch (Exception e) {
new BotException(e);
}
} else {
sendTranslatedMessage("You don't have the: `Ban Members` permission", channel, user);
}
}
Aggregations