use of com.sx4.bot.formatter.function.FormatterVariable in project Sx4 by sx4-discord-bot.
the class WelcomerCommand method formatters.
@Command(value = "formatters", aliases = { "format", "formatting" }, description = "Get all the formatters for welcomer you can use")
@CommandId(441)
@Examples({ "welcomer formatters" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void formatters(Sx4CommandEvent event) {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Welcomer 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(OffsetDateTime.class)) {
content.add("`{now." + variable.getName() + "}` - " + variable.getDescription());
}
content.add("`{user.age}` - Gets the age of a user as a string");
embed.setDescription(content.toString());
event.reply(embed.build()).queue();
}
use of com.sx4.bot.formatter.function.FormatterVariable in project Sx4 by sx4-discord-bot.
the class FormatterCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "arguments", nullDefault = true) String content) {
FormatterManager manager = FormatterManager.getDefaultManager();
String[] arguments = content == null ? new String[0] : content.split("\\.");
Set<Class<?>> functionClasses = manager.getFunctions().keySet();
Set<Class<?>> variableClasses = manager.getVariables().keySet();
Set<Class<?>> classes = new HashSet<>();
classes.addAll(functionClasses);
classes.addAll(variableClasses);
List<Class<?>> filteredClasses = classes.stream().filter(clazz -> arguments.length == 0 || arguments[0].equalsIgnoreCase(clazz.getSimpleName())).collect(Collectors.toList());
if (filteredClasses.isEmpty()) {
event.replyFailure("I could not find that formatter type").queue();
return;
}
PagedResult<Class<?>> paged = new PagedResult<>(event.getBot(), filteredClasses).setPerPage(15).setAutoSelect(true).setDisplayFunction(Class::getSimpleName);
paged.onSelect(select -> {
Class<?> clazz = select.getSelected();
for (int i = 1; i < arguments.length; i++) {
String name = arguments[i];
FormatterFunction<?> function = manager.getFunctions(clazz).stream().filter(f -> f.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
FormatterVariable<?> variable = manager.getVariables(clazz).stream().filter(v -> v.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
boolean last = i == arguments.length - 1;
MessageEmbed embed;
if (function != null) {
Method method = function.getMethod();
if (!last) {
clazz = method.getReturnType();
continue;
}
embed = new EmbedBuilder().setDescription(function.getDescription()).setTitle(this.getFunctionString(function)).addField("Return Type", method.getReturnType().getSimpleName(), true).build();
} else if (variable != null) {
Class<?> returnType = variable.getReturnType();
if (!last) {
clazz = returnType;
continue;
}
embed = new EmbedBuilder().setDescription(variable.getDescription()).setTitle(variable.getName()).addField("Return Type", returnType.getSimpleName(), true).build();
} else {
event.replyFailure("I could not find a variable or function named `" + name + "` on the type `" + clazz.getSimpleName() + "`").queue();
return;
}
event.reply(embed).queue();
return;
}
String variables = manager.getVariables(clazz).stream().map(FormatterVariable::getName).collect(Collectors.joining("\n"));
String functions = manager.getFunctions(clazz).stream().map(this::getFunctionString).collect(Collectors.joining("\n"));
EmbedBuilder embed = new EmbedBuilder().setTitle(clazz.getSimpleName()).addField("Functions", functions.isEmpty() ? "None" : functions, true).addField("Variables", variables.isEmpty() ? "None" : variables, true);
event.reply(embed.build()).queue();
});
paged.execute(event);
}
use of com.sx4.bot.formatter.function.FormatterVariable in project Sx4 by sx4-discord-bot.
the class FreeGamesCommand method formatters.
@Command(value = "formatters", aliases = { "formatting", "format" }, description = "View the formatters you can use for a custom message")
@CommandId(476)
@Examples({ "free games formatters" })
public void formatters(Sx4CommandEvent event) {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Free Game Formatters", null, event.getSelfUser().getEffectiveAvatarUrl());
FormatterManager manager = FormatterManager.getDefaultManager();
StringJoiner content = new StringJoiner("\n");
for (FormatterVariable<?> variable : manager.getVariables(EpicFreeGame.class)) {
content.add("`{game." + variable.getName() + "}` - " + variable.getDescription());
}
embed.setDescription(content.toString());
event.reply(embed.build()).queue();
}
use of com.sx4.bot.formatter.function.FormatterVariable 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.formatter.function.FormatterVariable in project Sx4 by sx4-discord-bot.
the class LeaverCommand method formatters.
@Command(value = "formatters", aliases = { "format", "formatting" }, description = "Get all the formatters for leaver you can use")
@CommandId(442)
@Examples({ "leaver formatters" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void formatters(Sx4CommandEvent event) {
EmbedBuilder embed = new EmbedBuilder().setAuthor("Leaver 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(OffsetDateTime.class)) {
content.add("`{now." + variable.getName() + "}` - " + variable.getDescription());
}
content.add("`{user.age}` - Gets the age of a user as a string");
content.add("`{member.age}` - Gets the age of a member as a string");
embed.setDescription(content.toString());
event.reply(embed.build()).queue();
}
Aggregations