use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.
the class FreeGamesCommand method platforms.
@Command(value = "platforms", description = "Select what platforms you want notifications from")
@CommandId(491)
@Examples({ "free games platforms #channel STEAM", "free games platforms STEAM EPIC_GAMES" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void platforms(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true) BaseGuildMessageChannel channel, @Argument(value = "platforms") FreeGameType... types) {
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;
long raw = FreeGameType.getRaw(types);
event.getMongo().updateFreeGameChannel(Filters.eq("channelId", effectiveChannel.getIdLong()), Updates.set("platforms", raw), new UpdateOptions()).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getMatchedCount() == 0) {
event.replyFailure("You do not have a free game channel in " + effectiveChannel.getAsMention()).queue();
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("That free game channel already uses those platforms").queue();
return;
}
event.replySuccess("That free game channel will now send notifications from those platforms").queue();
});
}
use of com.jockie.bot.core.command.Command 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.jockie.bot.core.command.Command 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.jockie.bot.core.command.Command 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.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.
the class MuteCommand method list.
@Command(value = "list", description = "Lists all the currently muted users in the server")
@CommandId(343)
@Redirects({ "muted list" })
@Examples({ "mute list" })
public void list(Sx4CommandEvent event) {
List<Document> mutes = event.getMongo().getMutes(Filters.eq("guildId", event.getGuild().getIdLong()), Projections.include("unmuteAt", "userId")).into(new ArrayList<>());
if (mutes.isEmpty()) {
event.replyFailure("There is no one muted in this server").queue();
return;
}
mutes.sort(Comparator.comparingLong(d -> d.getLong("unmuteAt")));
PagedResult<Document> paged = new PagedResult<>(event.getBot(), mutes).setAuthor("Muted Users", null, event.getGuild().getIconUrl()).setIndexed(false).setSelect().setDisplayFunction(data -> {
User user = event.getShardManager().getUserById(data.getLong("userId"));
return (user == null ? "Anonymous#0000" : user.getAsTag()) + " - " + TimeUtility.LONG_TIME_FORMATTER.parse(data.getLong("unmuteAt") - Clock.systemUTC().instant().getEpochSecond());
});
paged.execute(event);
}
Aggregations