use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class WelcomerCommand method screening.
@Command(value = "screening", aliases = { "member screening" }, description = "Toggles whether the bot should send a welcomer message after or before a member has gone through member screening")
@CommandId(461)
@Examples({ "welcomer screening" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void screening(Sx4CommandEvent event) {
List<Bson> update = List.of(Operators.set("welcomer.screening", Operators.cond(Operators.exists("$welcomer.screening"), Operators.REMOVE, false)));
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER).projection(Projections.include("welcomer.screening")).upsert(true);
event.getMongo().findAndUpdateGuildById(event.getGuild().getIdLong(), update, options).whenComplete((data, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess("Welcomer will now send a message " + (data.getEmbedded(List.of("welcomer", "screening"), true) ? "after" : "before") + " member screening").queue();
});
}
use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class WelcomerCommand method dmToggle.
@Command(value = "dm toggle", aliases = { "dm" }, description = "Toggle the state of welcomer private messaging the user")
@CommandId(98)
@Examples({ "welcomer dm toggle" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void dmToggle(Sx4CommandEvent event) {
List<Bson> update = List.of(Operators.set("welcomer.dm", Operators.cond("$welcomer.dm", Operators.REMOVE, true)));
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER).projection(Projections.include("welcomer.dm")).upsert(true);
event.getMongo().findAndUpdateGuildById(event.getGuild().getIdLong(), update, options).whenComplete((data, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess("Welcomer will " + (data.getEmbedded(List.of("welcomer", "dm"), false) ? "now" : "no longer") + " send in private messages").queue();
});
}
use of com.sx4.bot.annotations.command.CommandId 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.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class AutoRoleCommand method fix.
@Command(value = "fix", description = "Will give missing members the auto role if needed")
@CommandId(458)
@Examples({ "auto role fix @Role", "auto role fix Role", "auto role fix 406240455622262784" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
@BotPermissions(permissions = { Permission.MANAGE_ROLES })
public void fix(Sx4CommandEvent event, @Argument(value = "role", endless = true) Role role) {
Document data = event.getMongo().getAutoRole(Filters.eq("roleId", role.getIdLong()), Projections.include("filters"));
if (data == null) {
event.replyFailure("That role is not an auto role").queue();
return;
}
if (!event.getSelfMember().canInteract(role)) {
event.replyFailure("That auto role is above my top role").queue();
return;
}
List<Document> filters = data.getList("filters", Document.class, Collections.emptyList());
List<Member> members = event.getGuild().getMemberCache().applyStream(stream -> stream.filter(member -> AutoRoleUtility.filtersMatch(member, filters) && !member.getRoles().contains(role) && !member.isPending()).collect(Collectors.toList()));
if (members.size() == 0) {
event.replyFailure("No users currently need that auto role").queue();
return;
}
if (!this.pending.add(event.getGuild().getIdLong())) {
event.replyFailure("You already have an auto role fix in progress").queue();
return;
}
event.replyFormat("Adding %s to **%,d** user%s, another message will be sent once this is done %s", role.getAsMention(), members.size(), members.size() == 1 ? "" : "s", event.getConfig().getSuccessEmote()).queue();
List<CompletableFuture<Integer>> futures = new ArrayList<>();
for (Member member : members) {
futures.add(event.getGuild().addRoleToMember(member, role).submit().handle((result, exception) -> exception == null ? 1 : 0));
}
FutureUtility.allOf(futures).whenComplete((completed, exception) -> {
this.pending.remove(event.getGuild().getIdLong());
int count = completed.stream().reduce(0, Integer::sum);
event.replyFormat("Successfully added the role %s to **%,d/%,d** user%s %s", role.getAsMention(), count, members.size(), count == 1 ? "" : "s", event.getConfig().getSuccessEmote()).queue();
});
}
use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.
the class GiveawayCommand method reroll.
@Command(value = "reroll", aliases = { "re roll" }, description = "Rerolls the winners for an ended giveaway")
@CommandId(49)
@Examples({ "giveaway reroll 727224132202397726" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void reroll(Sx4CommandEvent event, @Argument(value = "message id") MessageArgument messageArgument) {
Document data = event.getMongo().getGiveawayById(messageArgument.getMessageId());
if (data == null) {
event.replyFailure("There is no giveaway with that id").queue();
return;
}
if (!data.containsKey("winners")) {
event.replyFailure("That giveaway has not ended yet").queue();
return;
}
event.getBot().getGiveawayManager().endGiveaway(data, true);
}
Aggregations