use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.
the class TwitchNotificationCommand method formatters.
@Command(value = "formatters", aliases = { "format", "formatting" }, description = "Get all the formatters for Twitch notifications you can use")
@CommandId(501)
@Examples({ "twitch notification formatters" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void formatters(Sx4CommandEvent event) {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Twitch Notification Formatters", null, event.getSelfUser().getEffectiveAvatarUrl());
FormatterManager manager = FormatterManager.getDefaultManager();
StringJoiner content = new StringJoiner("\n");
for (FormatterVariable<?> variable : manager.getVariables(TwitchStream.class)) {
content.add("`{stream." + variable.getName() + "}` - " + variable.getDescription());
}
for (FormatterVariable<?> variable : manager.getVariables(TwitchStreamer.class)) {
content.add("`{streamer." + variable.getName() + "}` - " + variable.getDescription());
}
embed.setDescription(content.toString());
event.reply(embed.build()).queue();
}
use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.
the class YouTubeNotificationCommand method stats.
@Command(value = "stats", aliases = { "settings", "setting" }, description = "View the settings for a specific notification")
@CommandId(166)
@Examples({ "youtube notification stats 5e45ce6d3688b30ee75201ae" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void stats(Sx4CommandEvent event, @Argument(value = "id") ObjectId id) {
Document notification = event.getMongo().getYouTubeNotification(Filters.eq("_id", id), Projections.include("uploaderId", "channelId", "message.content"));
if (notification == null) {
event.replyFailure("You don't have a notification with that id").queue();
return;
}
this.sendStats(event, notification);
}
use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.
the class YouTubeNotificationCommand method list.
@Command(value = "list", description = "View all the notifications you have setup throughout your server")
@CommandId(165)
@Examples({ "youtube notification list" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void list(Sx4CommandEvent event) {
List<Document> notifications = event.getMongo().getYouTubeNotifications(Filters.eq("guildId", event.getGuild().getIdLong()), Projections.include("uploaderId", "channelId", "message")).into(new ArrayList<>());
if (notifications.isEmpty()) {
event.replyFailure("You have no notifications setup in this server").queue();
return;
}
List<String> channels = notifications.stream().map(d -> d.getString("uploaderId")).distinct().collect(Collectors.toList());
int size = channels.size();
List<CompletableFuture<Map<String, String>>> futures = new ArrayList<>();
for (int i = 0; i < Math.ceil(size / 50D); i++) {
List<String> splitChannels = channels.subList(i * 50, Math.min((i + 1) * 50, size));
String ids = String.join(",", splitChannels);
Request request = new Request.Builder().url("https://www.googleapis.com/youtube/v3/channels?key=" + event.getConfig().getYouTube() + "&id=" + ids + "&part=snippet&maxResults=50").build();
CompletableFuture<Map<String, String>> future = new CompletableFuture<>();
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
Document data = Document.parse(response.body().string());
List<Document> items = data.getList("items", Document.class);
Map<String, String> names = new HashMap<>();
for (Document item : items) {
names.put(item.getString("id"), item.getEmbedded(List.of("snippet", "title"), String.class));
}
future.complete(names);
});
futures.add(future);
}
FutureUtility.allOf(futures).whenComplete((maps, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
Map<String, String> names = new HashMap<>();
for (Map<String, String> map : maps) {
names.putAll(map);
}
PagedResult<Document> paged = new PagedResult<>(event.getBot(), notifications).setIncreasedIndex(true).setAutoSelect(false).setAuthor("YouTube Notifications", null, event.getGuild().getIconUrl()).setDisplayFunction(data -> {
String uploaderId = data.getString("uploaderId");
return String.format("%s - [%s](https://youtube.com/channel/%s)", data.getObjectId("_id").toHexString(), names.getOrDefault(uploaderId, "Unknown"), uploaderId);
}).setSelect(SelectType.INDEX);
paged.onSelect(selected -> this.sendStats(event, selected.getSelected()));
paged.execute(event);
});
}
use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.
the class YouTubeNotificationCommand method formatters.
@Command(value = "formatters", aliases = { "format", "formatting" }, description = "Get all the formatters for YouTube notifications you can use")
@CommandId(445)
@Examples({ "youtube notification formatters" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void formatters(Sx4CommandEvent event) {
EmbedBuilder embed = new EmbedBuilder().setAuthor("YouTube Notification Formatters", null, event.getSelfUser().getEffectiveAvatarUrl());
FormatterManager manager = FormatterManager.getDefaultManager();
StringJoiner content = new StringJoiner("\n");
for (FormatterVariable<?> variable : manager.getVariables(YouTubeVideo.class)) {
content.add("`{video." + variable.getName() + "}` - " + variable.getDescription());
}
for (FormatterVariable<?> variable : manager.getVariables(YouTubeChannel.class)) {
content.add("`{channel." + variable.getName() + "}` - " + variable.getDescription());
}
embed.setDescription(content.toString());
event.reply(embed.build()).queue();
}
use of com.sx4.bot.annotations.command.BotPermissions in project Sx4 by sx4-discord-bot.
the class StarboardCommand method formatters.
@Command(value = "formatters", aliases = { "format", "formatting" }, description = "Get all the formatters for starboard you can use")
@CommandId(444)
@Examples({ "starboard formatters" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void formatters(Sx4CommandEvent event) {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Starboard Formatters", null, event.getSelfUser().getEffectiveAvatarUrl());
FormatterManager manager = FormatterManager.getDefaultManager();
StringJoiner content = new StringJoiner("\n");
for (FormatterVariable<?> variable : manager.getVariables(User.class)) {
content.add("`{user." + variable.getName() + "}` - " + variable.getDescription());
}
for (FormatterVariable<?> variable : manager.getVariables(Member.class)) {
content.add("`{member." + variable.getName() + "}` - " + variable.getDescription());
}
for (FormatterVariable<?> variable : manager.getVariables(Guild.class)) {
content.add("`{server." + variable.getName() + "}` - " + variable.getDescription());
}
for (FormatterVariable<?> variable : manager.getVariables(TextChannel.class)) {
content.add("`{channel." + variable.getName() + "}` - " + variable.getDescription());
}
for (FormatterVariable<?> variable : manager.getVariables(ReactionEmote.class)) {
content.add("`{emote." + variable.getName() + "}` - " + variable.getDescription());
}
content.add("`{stars}` - Gets amount of stars the starboard has");
content.add("`{stars.next}` - Gets the amount of stars the next milestone requires");
content.add("`{stars.next.until}` - Gets the amount of stars needed to reach the next milestone");
content.add("`{id}` - Gets the id for the starboard");
embed.setDescription(content.toString());
event.reply(embed.build()).queue();
}
Aggregations