use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.
the class PickaxeCommand method shop.
@Command(value = "shop", description = "View all the pickaxes you are able to buy or craft")
@CommandId(360)
@Examples({ "pickaxe shop" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void shop(Sx4CommandEvent event) {
List<Pickaxe> pickaxes = event.getBot().getEconomyManager().getItems(Pickaxe.class);
PagedResult<Pickaxe> paged = new PagedResult<>(event.getBot(), pickaxes).setPerPage(12).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Pickaxe Shop", null, event.getSelfUser().getEffectiveAvatarUrl()).setTitle("Page " + page.getPage() + "/" + page.getMaxPage()).setDescription("Pickaxes are a good way to gain some extra money aswell as some materials").setFooter(PagedResult.DEFAULT_FOOTER_TEXT);
page.forEach((pickaxe, index) -> {
List<ItemStack<CraftItem>> items = pickaxe.getCraft();
String craft = items.isEmpty() ? "None" : items.stream().map(ItemStack::toString).collect(Collectors.joining("\n"));
embed.addField(pickaxe.getName(), String.format("Price: $%,d\nCraft: %s\nDurability: %,d", pickaxe.getPrice(), craft, pickaxe.getMaxDurability()), true);
});
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 VoteCommand method onCommand.
public void onCommand(Sx4CommandEvent event) {
Request request = new Request.Builder().url(event.getConfig().getVoteWebserverUrl("440996323156819968/votes/user/" + event.getAuthor().getId() + "/unused/use")).addHeader("Authorization", event.getConfig().getVoteApi(true)).build();
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
Document data = Document.parse(response.body().string());
if (!data.getBoolean("success")) {
Request latest = new Request.Builder().url(event.getConfig().getVoteWebserverUrl("440996323156819968/votes/user/" + event.getAuthor().getId() + "/latest")).addHeader("Authorization", event.getConfig().getVoteApi(true)).build();
event.getHttpClient().newCall(latest).enqueue((HttpCallback) latestResponse -> {
Document latestVote = Document.parse(latestResponse.body().string());
OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC);
boolean weekend = now.getDayOfWeek() == DayOfWeek.FRIDAY || now.getDayOfWeek() == DayOfWeek.SATURDAY || now.getDayOfWeek() == DayOfWeek.SUNDAY;
EmbedBuilder embed = new EmbedBuilder().setAuthor("Vote Bonus", null, event.getAuthor().getEffectiveAvatarUrl());
long timeRemaining = 0;
Document vote = latestVote.get("vote", Document.class);
if (vote != null && latestVote.getBoolean("success")) {
timeRemaining = vote.get("time", Number.class).longValue() - Clock.systemUTC().instant().getEpochSecond() + VoteCommand.COOLDOWN;
}
if (timeRemaining > 0) {
embed.addField("Sx4", "**[You have voted recently you can vote for the bot again in " + TimeUtility.LONG_TIME_FORMATTER.parse(timeRemaining) + "](https://top.gg/bot/440996323156819968/vote)**", false);
} else {
embed.addField("Sx4", "**[You can vote for Sx4 for an extra $" + (weekend ? 1600 : 800) + "](https://top.gg/bot/440996323156819968/vote)**", false);
}
event.reply(embed.build()).queue();
});
return;
}
List<Document> votes = data.getList("votes", Document.class, Collections.emptyList());
Map<User, Long> referrers = new HashMap<>();
long money = 0L;
for (Document vote : votes) {
boolean weekend = vote.getBoolean("weekend");
money += weekend ? 1600 : 800;
Document query = vote.get("query", Document.class);
if (query == null) {
continue;
}
Object referral = query.get("referral");
if (referral == null) {
continue;
}
String id = referral instanceof List ? (String) ((List<?>) referral).get(0) : (String) referral;
User user;
try {
user = event.getShardManager().getUserById(id);
} catch (NumberFormatException e) {
continue;
}
if (user == null || user.getIdLong() == event.getAuthor().getIdLong() || user.isBot()) {
continue;
}
long amount = weekend ? 500 : 250;
referrers.compute(user, (key, value) -> value == null ? amount : value + amount);
}
List<WriteModel<Document>> bulkData = new ArrayList<>();
UpdateOptions options = new UpdateOptions().upsert(true);
StringJoiner content = new StringJoiner(", ");
referrers.forEach((user, amount) -> {
content.add(String.format("%s (**$%,d**)", user.getAsTag(), amount));
bulkData.add(new UpdateOneModel<>(Filters.eq("_id", user.getIdLong()), Updates.inc("economy.balance", amount), options));
});
bulkData.add(new UpdateOneModel<>(Filters.eq("_id", event.getAuthor().getIdLong()), Updates.inc("economy.balance", money), options));
String message = String.format("You have voted for the bot **%,d** time%s since you last used the command gathering you a total of **$%,d**, Vote for the bots again in 12 hours for more money.%s", votes.size(), votes.size() == 1 ? "" : "s", money, content.length() == 0 ? "" : "Referred users: " + content);
event.getMongo().bulkWriteUsers(bulkData).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.reply(message).queue();
});
});
}
use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.
the class ReputationCommand method amount.
@Command(value = "amount", description = "View the amount of reputation a user has")
@CommandId(420)
@Examples({ "reputation amount", "reputation amount @Shea#6653", "reputation amount Shea" })
public void amount(Sx4CommandEvent event, @Argument(value = "user", endless = true, nullDefault = true) Member member) {
User user = member == null ? event.getAuthor() : member.getUser();
int amount = event.getMongo().getUserById(user.getIdLong(), Projections.include("reputation.amount")).getEmbedded(List.of("reputation", "amount"), 0);
event.replyFormat("%s has **%,d** reputation", user.getAsTag(), amount).queue();
}
use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.
the class ReputationCommand method leaderboard.
@Command(value = "leaderboard", aliases = { "lb" }, description = "View the leaderboard for reputation across the bot")
@CommandId(421)
@Redirects({ "leaderboard reputation", "lb rep", "lb reputation", "leaderboard rep" })
@Examples({ "reputation leaderboard", "reputation leaderboard --server" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void leaderboard(Sx4CommandEvent event, @Option(value = "server", aliases = { "guild" }, description = "View the leaderboard with a server filter") boolean guild) {
List<Bson> pipeline = List.of(Aggregates.project(Projections.computed("reputation", "$reputation.amount")), Aggregates.match(Filters.exists("reputation")), Aggregates.sort(Sorts.descending("reputation")));
event.getMongo().aggregateUsers(pipeline).whenComplete((documents, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
List<Map.Entry<User, Integer>> users = new ArrayList<>();
AtomicInteger userIndex = new AtomicInteger(-1);
int i = 0;
for (Document data : documents) {
User user = event.getShardManager().getUserById(data.getLong("_id"));
if (user == null) {
continue;
}
if (!event.getGuild().isMember(user) && guild) {
continue;
}
i++;
users.add(Map.entry(user, data.getInteger("reputation")));
if (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<User, Integer>> paged = new PagedResult<>(event.getBot(), users).setPerPage(10).setCustomFunction(page -> {
int rank = userIndex.get();
EmbedBuilder embed = new EmbedBuilder().setTitle("Reputation 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` - %,d reputation\n", index + 1, MarkdownSanitizer.escape(entry.getKey().getAsTag()), entry.getValue())));
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 GameCommand method list.
@Command(value = "list", aliases = { "game list", "game list @Shea#6653", "game list Shea" }, description = "Lists basic info on all games a user has played on Sx4")
@CommandId(297)
@Redirects({ "games" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void list(Sx4CommandEvent event, @Argument(value = "user", endless = true, nullDefault = true) Member member) {
User user = member == null ? event.getAuthor() : member.getUser();
List<Document> games = event.getMongo().getGames(Filters.eq("userId", user.getIdLong()), Projections.include("type", "state")).into(new ArrayList<>());
if (games.isEmpty()) {
event.replyFailure("That user has not played any games yet").queue();
return;
}
PagedResult<Document> paged = new PagedResult<>(event.getBot(), games).setAuthor("Game List", null, user.getEffectiveAvatarUrl()).setIndexed(false).setPerPage(15).setSelect().setDisplayFunction(game -> "`" + GameType.fromId(game.getInteger("type")).getName() + "` - " + StringUtility.title(GameState.fromId(game.getInteger("state")).name()));
paged.execute(event);
}
Aggregations