use of com.sx4.bot.core.Sx4CommandEvent in project Sx4 by sx4-discord-bot.
the class FreeGamesCommand method add.
@Command(value = "add", description = "Add a channel to get free game notifications from Epic Games")
@CommandId(474)
@Examples({ "free games add", "free games add #channel" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
@Canary
public void add(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true, endless = true) TextChannel channel) {
TextChannel effectiveChannel = channel == null ? event.getTextChannel() : channel;
Document data = new Document("channelId", effectiveChannel.getIdLong()).append("guildId", event.getGuild().getIdLong());
event.getMongo().insertFreeGameChannel(data).whenComplete((result, exception) -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause instanceof MongoWriteException && ((MongoWriteException) cause).getError().getCategory() == ErrorCategory.DUPLICATE_KEY) {
event.replyFailure("You already have a free games channel in " + effectiveChannel.getAsMention()).queue();
return;
}
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess("Free game notifications will now be sent in " + effectiveChannel.getAsMention()).queue();
});
}
use of com.sx4.bot.core.Sx4CommandEvent in project Sx4 by sx4-discord-bot.
the class PickaxeCommand method info.
@Command(value = "info", aliases = { "information" }, description = "View information on a users pickaxe")
@CommandId(362)
@Examples({ "pickaxe info", "pickaxe info @Shea#6653", "pickaxe info Shea" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void info(Sx4CommandEvent event, @Argument(value = "user", endless = true, nullDefault = true) Member member) {
Member effectiveMember = member == null ? event.getMember() : member;
User user = member == null ? event.getAuthor() : effectiveMember.getUser();
Bson filter = Filters.and(Filters.eq("userId", effectiveMember.getIdLong()), Filters.eq("item.type", ItemType.PICKAXE.getId()));
Document data = event.getMongo().getItem(filter, Projections.include("item"));
if (data == null) {
event.replyFailure("That user does not have a pickaxe").queue();
return;
}
Pickaxe pickaxe = Pickaxe.fromData(event.getBot().getEconomyManager(), data.get("item", Document.class));
EmbedBuilder embed = new EmbedBuilder().setAuthor(user.getName() + "'s " + pickaxe.getName(), null, user.getEffectiveAvatarUrl()).setColor(effectiveMember.getColorRaw()).setThumbnail("https://emojipedia-us.s3.amazonaws.com/thumbs/120/twitter/131/pick_26cf.png").addField("Durability", pickaxe.getDurability() + "/" + pickaxe.getMaxDurability(), false).addField("Current Price", String.format("$%,d", pickaxe.getCurrentPrice()), false).addField("Price", String.format("$%,d", pickaxe.getPrice()), false).addField("Yield", String.format("$%,d to $%,d", pickaxe.getMinYield(), pickaxe.getMaxYield()), false).addField("Multiplier", NumberUtility.DEFAULT_DECIMAL_FORMAT.format(pickaxe.getMultiplier()), false);
event.reply(embed.build()).queue();
}
use of com.sx4.bot.core.Sx4CommandEvent in project Sx4 by sx4-discord-bot.
the class PickaxeCommand method upgrade.
@Command(value = "upgrade", description = "Upgrade your pickaxe by a certain attribute")
@CommandId(427)
@Examples({ "pickaxe upgrade money", "pickaxe upgrade multiplier 10", "pickaxe upgrade durability 5" })
public void upgrade(Sx4CommandEvent event, @Argument(value = "upgrade") Upgrade upgrade, @Argument(value = "upgrades") @DefaultNumber(1) @Limit(min = 1, max = 100) int upgrades) {
if (!upgrade.containsType(ItemType.PICKAXE)) {
event.replyFailure("You can not use that upgrade on a pickaxe").queue();
return;
}
event.getMongo().withTransaction(session -> {
Document data = event.getMongo().getItems().find(session, Filters.and(Filters.eq("userId", event.getAuthor().getIdLong()), Filters.eq("item.type", ItemType.PICKAXE.getId()))).first();
if (data == null) {
event.replyFailure("You do not have a pickaxe").queue();
session.abortTransaction();
return null;
}
Document item = data.get("item", Document.class);
Pickaxe defaultPickaxe = event.getBot().getEconomyManager().getItemById(item.getInteger("id"), Pickaxe.class);
Pickaxe pickaxe = new Pickaxe(item, defaultPickaxe);
int currentUpgrades = pickaxe.getUpgrades();
long price = 0;
for (int i = 0; i < upgrades; i++) {
price += Math.round(0.015D * defaultPickaxe.getPrice() * currentUpgrades++ + 0.025D * defaultPickaxe.getPrice());
}
UpdateResult result = event.getMongo().getUsers().updateOne(session, Filters.eq("_id", event.getAuthor().getIdLong()), List.of(EconomyUtility.decreaseBalanceUpdate(price)));
if (result.getModifiedCount() == 0) {
event.replyFormat("You do not have **$%,d** %s", price, event.getConfig().getFailureEmote()).queue();
session.abortTransaction();
return null;
}
List<Bson> update = new ArrayList<>();
update.add(Operators.set("item.upgrades", Operators.add(Operators.ifNull("$item.upgrades", 0), upgrades)));
update.add(Operators.set("item.price", Operators.add("$item.price", Math.round(defaultPickaxe.getPrice() * 0.015D) * upgrades)));
if (upgrade == Upgrade.MONEY) {
int increase = (int) Math.round(defaultPickaxe.getMinYield() * upgrade.getValue()) * upgrades;
update.add(Operators.set("item.minYield", Operators.add("$item.minYield", increase)));
update.add(Operators.set("item.maxYield", Operators.add("$item.maxYield", increase)));
} else if (upgrade == Upgrade.DURABILITY) {
int increase = (int) upgrade.getValue() * upgrades;
update.add(Operators.set("item.durability", Operators.add("$item.durability", increase)));
update.add(Operators.set("item.maxDurability", Operators.add("$item.maxDurability", increase)));
} else if (upgrade == Upgrade.MULTIPLIER) {
double increase = defaultPickaxe.getMultiplier() * upgrade.getValue() * upgrades;
update.add(Operators.set("item.multiplier", Operators.add("$item.multiplier", increase)));
}
event.getMongo().getItems().updateOne(session, Filters.and(Filters.eq("userId", event.getAuthor().getIdLong()), Filters.eq("item.id", pickaxe.getId())), update);
return String.format("You just upgraded %s %d time%s for your `%s` for **$%,d**", upgrade.getName().toLowerCase(), upgrades, (upgrades == 1 ? "" : "s"), pickaxe.getName(), price);
}).whenComplete((message, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception) || message == null) {
return;
}
event.replySuccess(message).queue();
});
}
use of com.sx4.bot.core.Sx4CommandEvent in project Sx4 by sx4-discord-bot.
the class PickaxeCommand method repair.
@Command(value = "repair", description = "Repair your current pickaxe with the material it is made from")
@CommandId(363)
@Examples({ "pickaxe repair 10", "pickaxe repair all" })
public void repair(Sx4CommandEvent event, @Argument(value = "durability") @AlternativeOptions("all") Alternative<Integer> option) {
Bson filter = Filters.and(Filters.eq("userId", event.getAuthor().getIdLong()), Filters.eq("item.type", ItemType.PICKAXE.getId()));
Document data = event.getMongo().getItem(filter, Projections.include("item"));
if (data == null) {
event.replyFailure("You do not have a pickaxe").queue();
return;
}
Pickaxe pickaxe = Pickaxe.fromData(event.getBot().getEconomyManager(), data.get("item", Document.class));
CraftItem item = pickaxe.getRepairItem();
if (item == null) {
event.replyFailure("That pickaxe is not repairable").queue();
return;
}
int maxDurability = pickaxe.getMaxDurability() - pickaxe.getDurability();
if (maxDurability <= 0) {
event.replyFailure("Your pickaxe is already at full durability").queue();
return;
}
int durability;
if (option.isAlternative()) {
durability = maxDurability;
} else {
int amount = option.getValue();
if (amount > maxDurability) {
event.reply("You can only repair your pickaxe by **" + maxDurability + "** durability :no_entry:").queue();
return;
}
durability = amount;
}
String acceptId = new CustomButtonId.Builder().setType(ButtonType.PICKAXE_REPAIR_CONFIRM).setTimeout(60).setOwners(event.getAuthor().getIdLong()).setArguments(item.getId(), pickaxe.getId(), pickaxe.getDurability(), durability).getId();
String rejectId = new CustomButtonId.Builder().setType(ButtonType.GENERIC_REJECT).setTimeout(60).setOwners(event.getAuthor().getIdLong()).getId();
List<Button> buttons = List.of(Button.success(acceptId, "Yes"), Button.danger(rejectId, "No"));
int itemCount = (int) Math.ceil((((double) pickaxe.getPrice() / item.getPrice()) / pickaxe.getMaxDurability()) * durability);
event.reply("It will cost you `" + itemCount + " " + item.getName() + "` to repair your pickaxe by **" + durability + "** durability, are you sure you want to repair it?").setActionRow(buttons).queue();
}
use of com.sx4.bot.core.Sx4CommandEvent in project Sx4 by sx4-discord-bot.
the class PickaxeCommand method upgrades.
@Command(value = "upgrades", description = "View all the upgrades you can use on a pickaxe")
@CommandId(428)
@Examples({ "pickaxe upgrades" })
public void upgrades(Sx4CommandEvent event) {
EnumSet<Upgrade> upgrades = Upgrade.getUpgrades(ItemType.PICKAXE);
PagedResult<Upgrade> paged = new PagedResult<>(event.getBot(), Arrays.asList(upgrades.toArray(Upgrade[]::new))).setPerPage(3).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder().setTitle("Pickaxe Upgrades");
page.forEach((upgrade, index) -> embed.addField(upgrade.getName(), upgrade.getDescription(), false));
return new MessageBuilder().setEmbeds(embed.build());
});
paged.execute(event);
}
Aggregations