use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.
the class SteamCommand method profile.
@Command(value = "profile", description = "Look up information about a steam profile")
@CommandId(212)
@Examples({ "steam profile dog", "steam profile https://steamcommunity.com/id/dog" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void profile(Sx4CommandEvent event, @Argument(value = "query", endless = true, nullDefault = true) String query) {
List<Document> profiles;
if (query == null) {
List<Document> connections = event.getMongo().getUserById(event.getAuthor().getIdLong(), Projections.include("connections.steam")).getEmbedded(List.of("connections", "steam"), Collections.emptyList());
if (connections.isEmpty()) {
event.replyFailure("You do not have a steam account linked, use `steam connect` to link an account or provide an argument to search").queue();
return;
}
profiles = connections.stream().map(data -> data.append("url", "https://steamcommunity.com/profiles/" + data.getLong("id"))).collect(Collectors.toList());
} else {
profiles = List.of(new Document("url", this.getProfileUrl(query)));
}
PagedResult<Document> paged = new PagedResult<>(event.getBot(), profiles).setAutoSelect(true).setAuthor("Steam Profiles", null, "https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Steam_icon_logo.svg/2000px-Steam_icon_logo.svg.png").setDisplayFunction(data -> "[" + data.getString("name") + "](" + data.getString("url") + ")");
paged.onSelect(select -> {
String url = select.getSelected().getString("url");
Request request = new Request.Builder().url(url + "?xml=1").build();
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
JSONObject json = XML.toJSONObject(response.body().string());
if (json.has("response")) {
event.replyFailure("I could not find that steam user").queue();
return;
}
JSONObject profile = json.getJSONObject("profile");
if (profile.getInt("visibilityState") == 1) {
event.replyFailure("That profile is private").queue();
return;
}
JSONObject mostPlayedGames = profile.optJSONObject("mostPlayedGames");
JSONArray gamesArray = mostPlayedGames == null ? new JSONArray() : mostPlayedGames.optJSONArray("mostPlayedGame");
if (gamesArray == null) {
gamesArray = new JSONArray().put(mostPlayedGames.getJSONObject("mostPlayedGame"));
}
double hours = 0D;
StringBuilder gamesString = new StringBuilder();
for (int i = 0; i < gamesArray.length(); i++) {
JSONObject game = gamesArray.getJSONObject(i);
hours += game.getDouble("hoursPlayed");
gamesString.append(String.format("[%s](%s) - **%.1f** hours\n", game.getString("gameName"), game.getString("gameLink"), game.getDouble("hoursPlayed")));
}
String stateMessage = profile.getString("stateMessage");
String location = profile.getString("location");
String realName = profile.getString("realname");
EmbedBuilder embed = new EmbedBuilder();
embed.setAuthor(profile.getString("steamID"), url, profile.getString("avatarFull"));
embed.setDescription(Jsoup.parse(profile.getString("summary")).text());
embed.setFooter("ID: " + profile.getLong("steamID64"));
embed.setThumbnail(profile.getString("avatarFull"));
embed.addField("Real Name", realName.isBlank() ? "None Given" : realName, true);
embed.addField("Created At", LocalDate.parse(profile.getString("memberSince"), DateTimeFormatter.ofPattern("LLLL d, yyyy")).format(this.formatter), true);
embed.addField("Status", StringUtility.title(profile.getString("onlineState")), true);
embed.addField("State Message", Jsoup.parse(stateMessage).text(), true);
embed.addField("Vac Bans", String.valueOf(profile.getInt("vacBanned")), true);
if (!location.isBlank()) {
embed.addField("Location", location, true);
}
if (hours != 0) {
gamesString.append(String.format("\nTotal - **%.1f** hours", hours));
embed.addField("Games Played (2 Weeks)", gamesString.toString(), false);
}
event.reply(embed.build()).queue();
});
});
paged.execute(event);
}
use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.
the class RoleCommand method remove.
@Command(value = "remove", description = "Remove a role from a member")
@CommandId(251)
@Redirects({ "removerole", "remove role", "rr" })
@Examples({ "role remove @Shea#6653 Role", "role remove Shea 345718366373150720", "role remove @Role" })
@AuthorPermissions(permissions = { Permission.MANAGE_ROLES })
@BotPermissions(permissions = { Permission.MANAGE_ROLES })
public void remove(Sx4CommandEvent event, @Argument(value = "user", nullDefault = true) Member member, @Argument(value = "role", endless = true) Role role) {
if (role.isManaged()) {
event.replyFailure("I cannot remove managed roles").queue();
return;
}
if (role.isPublicRole()) {
event.replyFailure("I cannot remove the @everyone role").queue();
return;
}
if (!event.getMember().canInteract(role)) {
event.replyFailure("You cannot remove a role higher or equal than your top role").queue();
return;
}
if (!event.getSelfMember().canInteract(role)) {
event.replyFailure("I cannot remove a role higher or equal than my top role").queue();
return;
}
Member effectiveMember = member == null ? event.getMember() : member;
event.getGuild().removeRoleFromMember(effectiveMember, role).flatMap($ -> event.replySuccess(role.getAsMention() + " has been removed from **" + effectiveMember.getUser().getAsTag() + "**")).queue();
}
use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.
the class LoggerCommand method list.
@Command(value = "list", description = "List and get info about loggers in the current server")
@CommandId(458)
@Examples({ "logger list" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void list(Sx4CommandEvent event, @Argument(value = "channel", endless = true, nullDefault = true) TextChannel channel) {
Bson filter = channel == null ? Filters.eq("guildId", event.getGuild().getIdLong()) : Filters.eq("channelId", channel.getIdLong());
List<Document> loggers = event.getMongo().getLoggers(filter, MongoDatabase.EMPTY_DOCUMENT).into(new ArrayList<>());
if (loggers.isEmpty()) {
event.replyFailure(channel == null ? "There are not any loggers setup" : "There is not a logger setup in " + channel.getAsMention()).queue();
return;
}
PagedResult<Document> paged = new PagedResult<>(event.getBot(), loggers).setAuthor("Loggers", null, event.getGuild().getIconUrl()).setAutoSelect(true).setDisplayFunction(data -> "<#" + data.getLong("channelId") + ">");
paged.onSelect(select -> {
Document data = select.getSelected();
EnumSet<LoggerEvent> events = LoggerEvent.getEvents(data.get("events", LoggerEvent.ALL));
PagedResult<LoggerEvent> loggerPaged = new PagedResult<>(event.getBot(), new ArrayList<>(events)).setSelect().setPerPage(20).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Logger Settings", null, event.getGuild().getIconUrl()).setTitle("Page " + page.getPage() + "/" + page.getMaxPage()).setFooter(PagedResult.DEFAULT_FOOTER_TEXT).addField("Status", data.getBoolean("enabled", true) ? "Enabled" : "Disabled", true).addField("Channel", "<#" + data.getLong("channelId") + ">", true);
StringJoiner content = new StringJoiner("\n");
page.forEach((loggerEvent, index) -> content.add(loggerEvent.name()));
embed.addField("Enabled Events", content.toString(), false);
return new MessageBuilder().setEmbeds(embed.build());
});
loggerPaged.execute(event);
});
paged.execute(event);
}
use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.
the class SteamCommand method game.
@Command(value = "profile", description = "Look up information about a steam profile")
@CommandId(212)
@Examples({ "steam profile dog", "steam profile https://steamcommunity.com/id/dog" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void game(Sx4CommandEvent event, @Argument(value = "query", endless = true, nullDefault = true) String query) {
List<Document> profiles;
if (query == null) {
List<Document> connections = event.getMongo().getUserById(event.getAuthor().getIdLong(), Projections.include("connections.steam")).getEmbedded(List.of("connections", "steam"), Collections.emptyList());
if (connections.isEmpty()) {
event.replyFailure("You do not have a steam account linked, use `steam connect` to link an account or provide an argument to search").queue();
return;
}
profiles = connections.stream().map(data -> data.append("url", "https://steamcommunity.com/profiles/" + data.getLong("id"))).collect(Collectors.toList());
} else {
profiles = List.of(new Document("url", this.getProfileUrl(query)));
}
PagedResult<Document> paged = new PagedResult<>(event.getBot(), profiles).setAutoSelect(true).setAuthor("Steam Profiles", null, "https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Steam_icon_logo.svg/2000px-Steam_icon_logo.svg.png").setDisplayFunction(data -> "[" + data.getString("name") + "](" + data.getString("url") + ")");
paged.onSelect(select -> {
String url = select.getSelected().getString("url");
Request request = new Request.Builder().url(url + "?xml=1").build();
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
JSONObject json = XML.toJSONObject(response.body().string());
if (json.has("response")) {
event.replyFailure("I could not find that steam user").queue();
return;
}
JSONObject profile = json.getJSONObject("profile");
if (profile.getInt("visibilityState") == 1) {
event.replyFailure("That profile is private").queue();
return;
}
JSONObject mostPlayedGames = profile.optJSONObject("mostPlayedGames");
JSONArray gamesArray = mostPlayedGames == null ? new JSONArray() : mostPlayedGames.optJSONArray("mostPlayedGame");
if (gamesArray == null) {
gamesArray = new JSONArray().put(mostPlayedGames.getJSONObject("mostPlayedGame"));
}
double hours = 0D;
StringBuilder gamesString = new StringBuilder();
for (int i = 0; i < gamesArray.length(); i++) {
JSONObject game = gamesArray.getJSONObject(i);
hours += game.getDouble("hoursPlayed");
gamesString.append(String.format("[%s](%s) - **%.1f** hours\n", game.getString("gameName"), game.getString("gameLink"), game.getDouble("hoursPlayed")));
}
String stateMessage = profile.getString("stateMessage");
String location = profile.getString("location");
String realName = profile.getString("realname");
EmbedBuilder embed = new EmbedBuilder();
embed.setAuthor(profile.getString("steamID"), url, profile.getString("avatarFull"));
embed.setDescription(Jsoup.parse(profile.getString("summary")).text());
embed.setFooter("ID: " + profile.getLong("steamID64"));
embed.setThumbnail(profile.getString("avatarFull"));
embed.addField("Real Name", realName.isBlank() ? "None Given" : realName, true);
embed.addField("Created At", LocalDate.parse(profile.getString("memberSince"), DateTimeFormatter.ofPattern("LLLL d, yyyy")).format(this.formatter), true);
embed.addField("Status", StringUtility.title(profile.getString("onlineState")), true);
embed.addField("State Message", Jsoup.parse(stateMessage).text(), true);
embed.addField("Vac Bans", String.valueOf(profile.getInt("vacBanned")), true);
if (!location.isBlank()) {
embed.addField("Location", location, true);
}
if (hours != 0) {
gamesString.append(String.format("\nTotal - **%.1f** hours", hours));
embed.addField("Games Played (2 Weeks)", gamesString.toString(), false);
}
event.reply(embed.build()).queue();
});
});
paged.execute(event);
}
Aggregations