use of com.sx4.bot.paged.PagedResult in project Sx4 by sx4-discord-bot.
the class ModLogCommand method view.
@Command(value = "view", aliases = { "viewcase", "view case", "list" }, description = "View a mod log case from the server")
@CommandId(70)
@Examples({ "modlog view 5e45ce6d3688b30ee75201ae", "modlog view" })
public void view(Sx4CommandEvent event, @Argument(value = "id", nullDefault = true) ObjectId id) {
Bson projection = Projections.include("moderatorId", "reason", "targetId", "action");
if (id == null) {
List<Document> allData = event.getMongo().getModLogs(Filters.eq("guildId", event.getGuild().getIdLong()), projection).into(new ArrayList<>());
if (allData.isEmpty()) {
event.replyFailure("There are no mod logs in this server").queue();
return;
}
PagedResult<Document> paged = new PagedResult<>(event.getBot(), allData).setDisplayFunction(data -> {
long targetId = data.getLong("targetId");
User target = event.getShardManager().getUserById(targetId);
return Action.fromData(data.get("action", Document.class)) + " to `" + (target == null ? targetId : target.getAsTag() + "`");
}).setIncreasedIndex(true);
paged.onSelect(select -> event.reply(ModLog.fromData(select.getSelected()).getEmbed(event.getShardManager())).queue());
paged.execute(event);
} else {
Document data = event.getMongo().getModLogById(Filters.and(Filters.eq("_id", id), Filters.eq("guildId", event.getGuild().getIdLong())), projection);
if (data == null) {
event.replyFailure("I could not find a mod log with that id").queue();
return;
}
event.reply(ModLog.fromData(data).getEmbed(event.getShardManager())).queue();
}
}
use of com.sx4.bot.paged.PagedResult in project Sx4 by sx4-discord-bot.
the class TemporaryBanCommand method list.
@Command(value = "list", description = "Lists all the users who have temporary bans")
@CommandId(345)
@Examples({ "temporary ban list" })
public void list(Sx4CommandEvent event) {
List<Document> bans = event.getMongo().getTemporaryBans(Filters.eq("guildId", event.getGuild().getIdLong()), Projections.include("unbanAt", "userId")).into(new ArrayList<>());
if (bans.isEmpty()) {
event.replyFailure("There is no one with a temporary ban in this server").queue();
return;
}
bans.sort(Comparator.comparingLong(d -> d.getLong("unbanAt")));
PagedResult<Document> paged = new PagedResult<>(event.getBot(), bans).setAuthor("Muted Users", null, event.getGuild().getIconUrl()).setIndexed(false).setSelect().setDisplayFunction(data -> {
User user = event.getShardManager().getUserById(data.getLong("userId"));
return (user == null ? "Anonymous#0000" : user.getAsTag()) + " - " + TimeUtility.LONG_TIME_FORMATTER.parse(data.getLong("unbanAt") - Clock.systemUTC().instant().getEpochSecond());
});
paged.execute(event);
}
use of com.sx4.bot.paged.PagedResult in project Sx4 by sx4-discord-bot.
the class SteamCommand method compare.
@Command(value = "compare", description = "Compare what games 2 steam accounts have in common")
@CommandId(279)
@Examples({ "steam compare dog cat", "steam compare https://steamcommunity.com/id/dog https://steamcommunity.com/id/cat" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void compare(Sx4CommandEvent event, @Argument(value = "first profile") String firstQuery, @Argument(value = "second profile", endless = true) String secondQuery) {
String firstUrl = this.getProfileUrl(firstQuery), secondUrl = this.getProfileUrl(secondQuery);
Request firstRequest = new Request.Builder().url(firstUrl + "games/?tab=all&xml=1").build();
Request secondRequest = new Request.Builder().url(secondUrl + "games/?tab=all&xml=1").build();
event.getHttpClient().newCall(firstRequest).enqueue((HttpCallback) firstResponse -> {
JSONObject firstData = XML.toJSONObject(firstResponse.body().string()).getJSONObject("gamesList");
if (firstData.has("error")) {
event.replyFailure("The steam profile <https://steamcommunity.com/profiles/" + firstData.getLong("steamID64") + "> is private").queue();
return;
}
event.getHttpClient().newCall(secondRequest).enqueue((HttpCallback) secondResponse -> {
JSONObject secondData = XML.toJSONObject(secondResponse.body().string()).getJSONObject("gamesList");
if (secondData.has("error")) {
event.replyFailure("The steam profile <https://steamcommunity.com/profiles/" + secondData.getLong("steamID64") + "> is private").queue();
return;
}
JSONArray firstGames = firstData.getJSONObject("games").getJSONArray("game"), secondGames = secondData.getJSONObject("games").getJSONArray("game");
Map<Integer, String> commonGames = new HashMap<>();
for (int x = 0; x < firstGames.length(); x++) {
for (int y = 0; y < secondGames.length(); y++) {
JSONObject firstGame = firstGames.getJSONObject(x), secondGame = secondGames.getJSONObject(y);
if (firstGame.getInt("appID") == secondGame.getInt("appID")) {
commonGames.put(firstGame.getInt("appID"), firstGame.getString("name"));
}
}
}
PagedResult<Map.Entry<Integer, String>> paged = new PagedResult<>(event.getBot(), new ArrayList<>(commonGames.entrySet())).setAuthor("Games In Common (" + commonGames.size() + ")", null, "https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Steam_icon_logo.svg/2000px-Steam_icon_logo.svg.png").setPerPage(15).setIncreasedIndex(true).setDisplayFunction(d -> "[" + d.getValue() + "](https://store.steampowered.com/app/" + d.getKey() + ")");
paged.execute(event);
});
});
}
use of com.sx4.bot.paged.PagedResult in project Sx4 by sx4-discord-bot.
the class ShardInfoCommand method onCommand.
public void onCommand(Sx4CommandEvent event) {
long totalGuilds = event.getShardManager().getGuildCache().size(), totalUsers = event.getShardManager().getUserCache().size();
List<JDA> shards = new ArrayList<>(event.getShardManager().getShards());
shards.sort(Comparator.comparingInt(a -> a.getShardInfo().getShardId()));
JDA.ShardInfo shardInfo = event.getJDA().getShardInfo();
PagedResult<JDA> paged = new PagedResult<>(event.getBot(), shards).setPerPage(9).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder();
embed.setDescription(String.format("```prolog\nTotal Shards: %d\nTotal Servers: %,d\nTotal Members: %,d\nAverage Ping: %.0fms```", shardInfo.getShardTotal(), totalGuilds, totalUsers, event.getShardManager().getAverageGatewayPing()));
embed.setAuthor("Shard Info!", null, event.getSelfUser().getEffectiveAvatarUrl());
embed.setFooter("next | previous | go to <page> | cancel");
page.forEach((shard, index) -> {
String currentShard = shardInfo.getShardId() == index ? "\\> " : "";
embed.addField(currentShard + "Shard " + (index + 1), String.format("%,d servers\n%,d members\n%dms\n%s", shard.getGuilds().size(), shard.getUsers().size(), shard.getGatewayPing(), shard.getStatus()), true);
});
return new MessageBuilder().setEmbeds(embed.build());
});
paged.execute(event);
}
use of com.sx4.bot.paged.PagedResult 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