use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.
the class PremiumCommand method perks.
@Command(value = "perks", description = "View the perks you get when you or a server has premium")
@CommandId(462)
@Examples({ "premium perks" })
public void perks(Sx4CommandEvent event) {
List<String> userPerks = event.getConfig().getPremiumUserPerks(), serverPerks = event.getConfig().getPremiumServerPerks();
EmbedBuilder embed = new EmbedBuilder().setAuthor("Premium Perks", null, event.getSelfUser().getEffectiveAvatarUrl()).addField("Personal Perks", "• " + String.join("\n• ", userPerks), false).addField("Server Perks", "• " + String.join("\n• ", serverPerks), false);
event.reply(embed.build()).queue();
}
use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.
the class PremiumCommand method check.
@Command(value = "check", description = "Checks when the current premium in the server expires")
@CommandId(178)
@Examples({ "premium check" })
public void check(Sx4CommandEvent event) {
long endAt = event.getMongo().getGuildById(event.getGuild().getIdLong(), Projections.include("premium.endAt")).getEmbedded(List.of("premium", "endAt"), 0L);
if (endAt == 0) {
event.replyFailure("This server currently doesn't have premium, you can give it premium with credit <https://patreon.com/Sx4>").queue();
return;
}
OffsetDateTime expire = OffsetDateTime.ofInstant(Instant.ofEpochSecond(endAt), ZoneOffset.UTC);
if (expire.isBefore(OffsetDateTime.now(ZoneOffset.UTC))) {
event.replyFailure("Premium for this server expired on the **" + String.format(expire.format(this.formatter), NumberUtility.getSuffix(expire.getDayOfMonth())) + "**, you can renew it with more credit <https://patreon.com/Sx4>").queue();
return;
}
event.replyFormat("Premium for this server will expire on the **" + String.format(expire.format(this.formatter), NumberUtility.getSuffix(expire.getDayOfMonth())) + "**").queue();
}
use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.
the class PremiumCommand method leaderboard.
@Command(value = "leaderboard", aliases = { "lb" }, description = "Leaderboard for Sx4s biggest donors")
@CommandId(446)
@Redirects({ "lb premium", "leaderboard premium" })
@Examples({ "premium leaderboard" })
public void leaderboard(Sx4CommandEvent event, @Option(value = "server", aliases = { "guild" }, description = "Filters the results to only people in the current server") boolean guild) {
List<Bson> pipeline = List.of(Aggregates.project(Projections.computed("total", "$premium.total")), Aggregates.match(Filters.and(Filters.exists("total"), Filters.ne("total", 0))), Aggregates.sort(Sorts.descending("total")));
event.getMongoMain().aggregateUsers(pipeline).whenCompleteAsync((documents, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
List<Map.Entry<String, Integer>> users = new ArrayList<>();
AtomicInteger userIndex = new AtomicInteger(-1);
int i = 0;
for (Document data : documents) {
long id = data.getLong("_id");
User user = event.getShardManager().getUserById(data.getLong("_id"));
if ((user == null || !event.getGuild().isMember(user)) && guild) {
continue;
}
i++;
users.add(Map.entry(user == null ? "Anonymous#0000 (" + id + ")" : MarkdownSanitizer.escape(user.getAsTag()), data.getInteger("total")));
if (user != null && user.getIdLong() == event.getAuthor().getIdLong()) {
userIndex.set(i);
}
}
if (users.isEmpty()) {
event.replyFailure("There are no users which fit into this leaderboard").queue();
return;
}
PagedResult<Map.Entry<String, Integer>> paged = new PagedResult<>(event.getBot(), users).setPerPage(10).setCustomFunction(page -> {
int rank = userIndex.get();
EmbedBuilder embed = new EmbedBuilder().setTitle("Donors Leaderboard").setFooter(event.getAuthor().getName() + "'s Rank: " + (rank == -1 ? "N/A" : NumberUtility.getSuffixed(rank)) + " | Page " + page.getPage() + "/" + page.getMaxPage(), event.getAuthor().getEffectiveAvatarUrl());
page.forEach((entry, index) -> embed.appendDescription(String.format("%d. `%s` - $%,.2f\n", index + 1, entry.getKey(), entry.getValue() / 100D)));
return new MessageBuilder().setEmbeds(embed.build());
});
paged.execute(event);
});
}
use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.
the class WhitelistCommand method reset.
@Command(value = "reset", description = "Reset the whitelist for a specific role/user in a channel")
@CommandId(186)
@Examples({ "whitelist reset #channel", "whitelist reset all" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void reset(Sx4CommandEvent event, @Argument(value = "channel | all", endless = true) @AlternativeOptions("all") Alternative<TextChannel> option) {
List<Bson> update = List.of(Operators.set("holders", Operators.reduce(Operators.ifNull("$holders", Collections.EMPTY_LIST), Collections.EMPTY_LIST, Operators.concatArrays("$$value", Operators.cond(Operators.isEmpty(Operators.ifNull(Operators.first(Operators.map(List.of("$$this"), "$$holder.blacklisted", "holder")), Collections.EMPTY_LIST)), Collections.EMPTY_LIST, List.of(Operators.removeObject("$$this", "whitelisted")))))));
if (option.isAlternative()) {
event.getMongo().updateManyBlacklists(Filters.eq("guildId", event.getGuild().getIdLong()), update, new UpdateOptions()).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("Nothing was whitelisted in this server").queue();
return;
}
event.replySuccess("Reset **" + result.getModifiedCount() + "** channels of their whitelist configurations").queue();
});
} else {
TextChannel channel = option.getValue();
event.getMongo().updateBlacklist(Filters.eq("channelId", channel.getIdLong()), update, new UpdateOptions()).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("Nothing was whitelisted in that channel").queue();
return;
}
event.replySuccess("That channel no longer has any whitelists").queue();
});
}
}
use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.
the class FactoryCommand method buy.
@Command(value = "buy", description = "Buy a factory with some materials")
@CommandId(396)
@Examples({ "factory buy 5 Shoe Factory", "factory buy Shoe Factory", "factory buy all" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void buy(Sx4CommandEvent event, @Argument(value = "factories", endless = true) @AlternativeOptions("all") Alternative<ItemStack<Factory>> option) {
ItemStack<Factory> stack = option.getValue();
event.getMongo().withTransaction(session -> {
Bson userFilter = Filters.eq("userId", event.getAuthor().getIdLong()), filter;
List<Factory> factories;
if (stack == null) {
filter = Filters.and(userFilter, Filters.eq("item.type", ItemType.MATERIAL.getId()));
factories = event.getBot().getEconomyManager().getItems(Factory.class);
} else {
Factory factory = stack.getItem();
filter = Filters.and(userFilter, Filters.eq("item.id", factory.getCost().getItem().getId()));
factories = List.of(factory);
}
List<Document> materials = event.getMongo().getItems().find(session, filter).projection(Projections.include("amount", "item.id")).into(new ArrayList<>());
List<ItemStack<Factory>> boughtFactories = new ArrayList<>();
Factories: for (Factory factory : factories) {
ItemStack<Material> cost = factory.getCost();
Material costMaterial = cost.getItem();
for (Document material : materials) {
int id = material.getEmbedded(List.of("item", "id"), Integer.class);
if (costMaterial.getId() == id) {
long buyableAmount = (long) Math.floor((double) material.getLong("amount") / cost.getAmount());
long amount = stack == null ? buyableAmount : stack.getAmount();
if (amount == 0 || amount > buyableAmount) {
continue Factories;
}
event.getMongo().getItems().updateOne(session, Filters.and(userFilter, Filters.eq("item.id", id)), Updates.inc("amount", -amount * cost.getAmount()));
List<Bson> update = List.of(Operators.set("item", factory.toData()), Operators.set("amount", Operators.add(Operators.ifNull("$amount", 0L), amount)));
event.getMongo().getItems().updateOne(session, Filters.and(userFilter, Filters.eq("item.id", factory.getId())), update, new UpdateOptions().upsert(true));
boughtFactories.add(new ItemStack<>(factory, amount));
}
}
}
return boughtFactories;
}).whenComplete((factories, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (factories.isEmpty()) {
event.replyFailure("You cannot afford " + (stack == null ? "any factories" : "`" + stack.getAmount() + " " + stack.getItem().getName() + "`")).queue();
return;
}
String factoriesBought = factories.stream().sorted(Collections.reverseOrder(Comparator.comparingLong(ItemStack::getAmount))).map(ItemStack::toString).collect(Collectors.joining("\n• "));
EmbedBuilder embed = new EmbedBuilder().setColor(event.getMember().getColor()).setAuthor(event.getAuthor().getName(), null, event.getAuthor().getEffectiveAvatarUrl()).setDescription("With all your materials you have bought the following factories\n\n• " + factoriesBought);
event.reply(embed.build()).queue();
});
}
Aggregations