use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class FreeGamesCommand method toggle.
@Command(value = "toggle", description = "Enables/disables a free game channel")
@CommandId(484)
@Examples({ "free games toggle", "free games toggle #channel" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void toggle(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true, endless = true) BaseGuildMessageChannel channel) {
MessageChannel messageChannel = event.getChannel();
if (channel == null && !(messageChannel instanceof BaseGuildMessageChannel)) {
event.replyFailure("You cannot use this channel type").queue();
return;
}
BaseGuildMessageChannel effectiveChannel = channel == null ? (BaseGuildMessageChannel) messageChannel : channel;
List<Bson> update = List.of(Operators.set("enabled", Operators.cond(Operators.exists("$enabled"), Operators.REMOVE, false)));
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().projection(Projections.include("enabled")).returnDocument(ReturnDocument.AFTER);
event.getMongo().findAndUpdateFreeGameChannel(Filters.eq("channelId", effectiveChannel.getIdLong()), update, options).whenComplete((data, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess("The free game channel in " + effectiveChannel.getAsMention() + " is now **" + (data.get("enabled", true) ? "enabled" : "disabled") + "**").queue();
});
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class FreeGamesCommand method avatar.
@Command(value = "avatar", description = "Set the avatar of the webhook that sends free game notifications")
@CommandId(480)
@Examples({ "free games avatar Shea#6653", "free games avatar https://i.imgur.com/i87lyNO.png" })
@Premium
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void avatar(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true) BaseGuildMessageChannel channel, @Argument(value = "avatar", endless = true, acceptEmpty = true) @ImageUrl String url) {
MessageChannel messageChannel = event.getChannel();
if (channel == null && !(messageChannel instanceof BaseGuildMessageChannel)) {
event.replyFailure("You cannot use this channel type").queue();
return;
}
BaseGuildMessageChannel effectiveChannel = channel == null ? (BaseGuildMessageChannel) messageChannel : channel;
event.getMongo().updateFreeGameChannel(Filters.eq("channelId", effectiveChannel.getIdLong()), Updates.set("webhook.avatar", url), new UpdateOptions()).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getMatchedCount() == 0) {
event.replyFailure("You don't have a free game channel setup").queue();
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("Your webhook avatar for free game notifications was already set to that").queue();
return;
}
event.replySuccess("Your webhook avatar has been updated for that free game notifications, this only works with premium <https://patreon.com/Sx4>").queue();
});
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class MuteCommand method defaultTime.
@Command(value = "default time", aliases = { "default duration" }, description = "Sets the default time to be used when a duration argument isn't given")
@CommandId(342)
@Examples({ "mute default time 10m", "mute default time 5d", "mute default time 1h 30m" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void defaultTime(Sx4CommandEvent event, @Argument(value = "duration", endless = true) Duration duration) {
long seconds = duration.toSeconds();
Bson update = seconds == ModUtility.DEFAULT_MUTE_DURATION ? Updates.unset("mute.defaultTime") : Updates.set("mute.defaultTime", seconds);
event.getMongo().updateGuildById(event.getGuild().getIdLong(), update).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0 && result.getUpsertedId() == null) {
event.replyFailure("Your mute default time was already set to that").queue();
return;
}
event.replySuccess("Your mute default time has been set to **" + TimeUtility.LONG_TIME_FORMATTER.parse(seconds) + "**").queue();
});
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class RoleCommand method add.
@Command(value = "add", description = "Add a role to a member")
@CommandId(250)
@Redirects({ "addrole", "add role", "ar" })
@Examples({ "role add @Shea#6653 Role", "role add Shea 345718366373150720", "role add @Role" })
@AuthorPermissions(permissions = { Permission.MANAGE_ROLES })
@BotPermissions(permissions = { Permission.MANAGE_ROLES })
public void add(Sx4CommandEvent event, @Argument(value = "user", nullDefault = true) @AlternativeOptions("all") Alternative<Member> option, @Argument(value = "role", endless = true) Role role) {
if (role.isManaged()) {
event.replyFailure("I cannot give managed roles").queue();
return;
}
if (role.isPublicRole()) {
event.replyFailure("I cannot give the @everyone role").queue();
return;
}
if (!event.getMember().canInteract(role)) {
event.replyFailure("You cannot give a role higher or equal than your top role").queue();
return;
}
if (!event.getSelfMember().canInteract(role)) {
event.replyFailure("I cannot give a role higher or equal than my top role").queue();
return;
}
if (option != null && option.isAlternative()) {
List<Member> members = event.getGuild().getMemberCache().applyStream(stream -> stream.filter(member -> !member.getRoles().contains(role)).collect(Collectors.toList()));
if (members.size() == 0) {
event.replyFailure("All users already have that role").queue();
return;
}
if (!this.pending.add(event.getGuild().getIdLong())) {
event.replyFailure("You can only have 1 concurrent role being added to all users").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();
});
} else {
Member effectiveMember = option == null ? event.getMember() : option.getValue();
event.getGuild().addRoleToMember(effectiveMember, role).flatMap($ -> event.replySuccess(role.getAsMention() + " has been added to **" + effectiveMember.getUser().getAsTag() + "**")).queue();
}
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class TemporaryBanCommand method defaultTime.
@Command(value = "default time", aliases = { "default duration" }, description = "Sets the default time to be used when a duration argument isn't given")
@CommandId(344)
@Examples({ "temporary ban default time 10m", "temporary ban default time 5d", "temporary ban default time 1h 30m" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void defaultTime(Sx4CommandEvent event, @Argument(value = "duration", endless = true) Duration duration) {
long seconds = duration.toSeconds();
Bson update = seconds == ModUtility.DEFAULT_TEMPORARY_BAN_DURATION ? Updates.unset("temporaryBan.defaultTime") : Updates.set("temporaryBan.defaultTime", seconds);
event.getMongo().updateGuildById(event.getGuild().getIdLong(), update).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0 && result.getUpsertedId() == null) {
event.replyFailure("Your temporary ban default time was already set to that").queue();
return;
}
event.replySuccess("Your temporary ban default time has been set to **" + TimeUtility.LONG_TIME_FORMATTER.parse(seconds) + "**").queue();
});
}
Aggregations