use of com.sx4.bot.entities.argument.Or in project Sx4 by sx4-discord-bot.
the class RoleCommand method remove.
@Command(value = "remove", description = "Remove a role from a member")
@CommandId(251)
@Redirects({ "removerole", "remove role", "rr" })
@Examples({ "role remove @Shea#6653 Role", "role remove Shea 345718366373150720", "role remove @Role" })
@AuthorPermissions(permissions = { Permission.MANAGE_ROLES })
@BotPermissions(permissions = { Permission.MANAGE_ROLES })
public void remove(Sx4CommandEvent event, @Argument(value = "user", nullDefault = true) Member member, @Argument(value = "role", endless = true) Role role) {
if (role.isManaged()) {
event.replyFailure("I cannot remove managed roles").queue();
return;
}
if (role.isPublicRole()) {
event.replyFailure("I cannot remove the @everyone role").queue();
return;
}
if (!event.getMember().canInteract(role)) {
event.replyFailure("You cannot remove a role higher or equal than your top role").queue();
return;
}
if (!event.getSelfMember().canInteract(role)) {
event.replyFailure("I cannot remove a role higher or equal than my top role").queue();
return;
}
Member effectiveMember = member == null ? event.getMember() : member;
event.getGuild().removeRoleFromMember(effectiveMember, role).flatMap($ -> event.replySuccess(role.getAsMention() + " has been removed from **" + effectiveMember.getUser().getAsTag() + "**")).queue();
}
use of com.sx4.bot.entities.argument.Or in project Sx4 by sx4-discord-bot.
the class ServerStatsCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "duration", endless = true, nullDefault = true) Duration duration, @Option(value = "live", description = "Adds the live counting data to the total") boolean live, @Option(value = "reset", description = "Gets the stats since 00:00 UTC") boolean reset) {
if (duration != null && (duration.toHours() < 1 || duration.toHours() > 168)) {
event.replyFailure("Time frame cannot be less than 1 hour or more than 7 days").queue();
return;
}
List<Document> data = event.getMongo().getServerStats(Filters.eq("guildId", event.getGuild().getIdLong()), MongoDatabase.EMPTY_DOCUMENT).into(new ArrayList<>());
if (data.isEmpty()) {
event.replyFailure("There has been no data recorded for this server yet").queue();
return;
}
Date lastUpdate = event.getBot().getServerStatsManager().getLastUpdate();
OffsetDateTime currentHour = OffsetDateTime.now(ZoneOffset.UTC).withMinute(0).withSecond(0).withNano(0);
if (reset) {
duration = Duration.between(currentHour.withHour(0), currentHour);
}
Map<Long, Map<ServerStatsType, Integer>> map = new HashMap<>();
if (duration == null) {
Map<ServerStatsType, Integer> defaultStatsDay = new HashMap<>();
defaultStatsDay.put(ServerStatsType.JOINS, 0);
defaultStatsDay.put(ServerStatsType.MESSAGES, 0);
map.put(24L, defaultStatsDay);
Map<ServerStatsType, Integer> defaultStatsWeek = new HashMap<>();
defaultStatsWeek.put(ServerStatsType.JOINS, 0);
defaultStatsWeek.put(ServerStatsType.MESSAGES, 0);
map.put(168L, defaultStatsWeek);
} else {
Map<ServerStatsType, Integer> defaultStats = new HashMap<>();
defaultStats.put(ServerStatsType.JOINS, 0);
defaultStats.put(ServerStatsType.MESSAGES, 0);
map.put(duration.toHours(), defaultStats);
}
for (Document stats : data) {
Date time = stats.getDate("time");
Duration difference = Duration.between(time.toInstant(), currentHour);
int joins = stats.getInteger("joins", 0), messages = stats.getInteger("messages", 0);
if (duration != null && difference.toHours() <= duration.toHours()) {
this.compute(map, duration.toHours(), joins, messages);
}
if (duration == null && difference.toHours() <= 24) {
this.compute(map, 24, joins, messages);
}
if (duration == null && difference.toDays() <= 7) {
this.compute(map, 168, joins, messages);
}
lastUpdate = lastUpdate == null || lastUpdate.getTime() < time.getTime() ? time : lastUpdate;
}
EmbedBuilder embed = new EmbedBuilder().setAuthor("Server Stats", null, event.getGuild().getIconUrl()).setFooter("Updated every hour").setTimestamp(lastUpdate.toInstant());
ServerStatsManager manager = event.getBot().getServerStatsManager();
for (long key : map.keySet()) {
Map<ServerStatsType, Integer> stats = map.get(key);
for (ServerStatsType type : stats.keySet()) {
embed.addField(StringUtility.title(type.getField()) + " (" + TimeUtility.LONG_TIME_FORMATTER.parse(Duration.of(key, ChronoUnit.HOURS)) + ")", String.format("%,d", stats.get(type) + (live ? manager.getCounter(event.getGuild().getIdLong(), type) : 0)), false);
}
}
event.reply(embed.build()).queue();
}
use of com.sx4.bot.entities.argument.Or in project Sx4 by sx4-discord-bot.
the class KickCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user") Member member, @Argument(value = "reason", endless = true, nullDefault = true) Reason reason) {
if (member.getIdLong() == event.getSelfUser().getIdLong()) {
event.replyFailure("You cannot kick me, that is illegal").queue();
return;
}
if (!event.getMember().canInteract(member)) {
event.replyFailure("You cannot kick someone higher or equal than your top role").queue();
return;
}
if (!event.getSelfMember().canInteract(member)) {
event.replyFailure("I cannot kick someone higher or equal than my top role").queue();
return;
}
member.kick().reason(ModUtility.getAuditReason(reason, event.getAuthor())).queue($ -> {
event.replySuccess("**" + member.getUser().getAsTag() + "** has been kicked").queue();
event.getBot().getModActionManager().onModAction(new KickEvent(event.getMember(), member.getUser(), reason));
});
}
Aggregations