use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class InfoCmds method guildinfo.
@Subscribe
public void guildinfo(CommandRegistry cr) {
cr.register("serverinfo", new SimpleCommand(Category.INFO) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
Guild guild = event.getGuild();
TextChannel channel = event.getChannel();
String roles = guild.getRoles().stream().filter(role -> !guild.getPublicRole().equals(role)).map(Role::getName).collect(Collectors.joining(", "));
if (roles.length() > 1024)
roles = roles.substring(0, 1024 - 4) + "...";
channel.sendMessage(new EmbedBuilder().setAuthor("Server Information", null, guild.getIconUrl()).setColor(guild.getOwner().getColor() == null ? Color.ORANGE : guild.getOwner().getColor()).setDescription("Server information for " + guild.getName()).setThumbnail(guild.getIconUrl()).addField("Users (Online/Unique)", (int) guild.getMembers().stream().filter(u -> !u.getOnlineStatus().equals(OnlineStatus.OFFLINE)).count() + "/" + guild.getMembers().size(), true).addField("Creation Date", guild.getCreationTime().format(DateTimeFormatter.ISO_DATE_TIME).replaceAll("[^0-9.:-]", " "), true).addField("Voice/Text Channels", guild.getVoiceChannels().size() + "/" + guild.getTextChannels().size(), true).addField("Owner", guild.getOwner().getUser().getName() + "#" + guild.getOwner().getUser().getDiscriminator(), true).addField("Region", guild.getRegion() == null ? "Unknown." : guild.getRegion().getName(), true).addField("Roles (" + guild.getRoles().size() + ")", roles, false).setFooter("Server ID: " + String.valueOf(guild.getId()), null).build()).queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Server Info Command").setDescription("**See your server's current stats.**").setColor(event.getGuild().getOwner().getColor() == null ? Color.ORANGE : event.getGuild().getOwner().getColor()).build();
}
});
cr.registerAlias("serverinfo", "guildinfo");
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class MiscCmds method createPoll.
@Subscribe
public void createPoll(CommandRegistry registry) {
registry.register("createpoll", new SimpleCommand(Category.MISC) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
Map<String, Optional<String>> opts = StringUtils.parse(args);
PollBuilder builder = Poll.builder();
if (!opts.containsKey("time") || !opts.get("time").isPresent()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't include either the `-time` argument or it was empty!\n" + "Example: `~>poll -options \"hi there\",\"wew\",\"owo what's this\" -time 10m20s -name \"test poll\"").queue();
return;
}
if (!opts.containsKey("options") || !opts.get("options").isPresent()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't include either the `-options` argument or it was empty!\n" + "Example: ~>poll -options \"hi there\",\"wew\",\"owo what's this\" -time 10m20s -name \"test poll\"").queue();
return;
}
if (!opts.containsKey("name") || !opts.get("name").isPresent()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't include either the `-name` argument or it was empty!\n" + "Example: ~>poll -options \"hi there\",\"wew\",\"owo what's this\" -time 10m20s -name \"test poll\"").queue();
return;
}
if (opts.containsKey("name") || opts.get("name").isPresent()) {
builder.setName(opts.get("name").get().replaceAll(String.valueOf('"'), ""));
}
String[] options = opts.get("options").get().replaceAll(String.valueOf('"'), "").split(",");
long timeout = Utils.parseTime(opts.get("time").get());
builder.setEvent(event).setTimeout(timeout).setOptions(options).build().startPoll();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Poll Command").setDescription("**Creates a poll**").addField("Usage", "`~>poll [-options <options>] [-time <time>] [-name <name>]`", false).addField("Parameters", "`-options` The options to add. Minimum is 2 and maximum is 9. For instance: `Pizza,Spaghetti,Pasta,\"Spiral Nudels\"` (Enclose options with multiple words in double quotes).\n" + "`-time` The time the operation is gonna take. The format is as follows `1m29s` for 1 minute and 21 seconds. Maximum poll runtime is 45 minutes.\n" + "`-name` The name of the poll for reference.", false).addField("Considerations", "To cancel the running poll type &cancelpoll. Only the person who started it or an Admin can cancel it.", false).addField("Example", "~>poll -options \"hi there\",\"wew\",\"owo what's this\" -time 10m20s -name \"test poll\"", false).build();
}
});
registry.registerAlias("createpoll", "poll");
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class ModerationCmds method tempban.
@Subscribe
public void tempban(CommandRegistry cr) {
cr.register("tempban", new SimpleCommand(Category.MODERATION) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
String reason = content;
Guild guild = event.getGuild();
User author = event.getAuthor();
TextChannel channel = event.getChannel();
Message receivedMessage = event.getMessage();
if (!guild.getMember(author).hasPermission(net.dv8tion.jda.core.Permission.BAN_MEMBERS)) {
channel.sendMessage(EmoteReference.ERROR + "Cannot ban: You have no Ban Members permission.").queue();
return;
}
if (event.getMessage().getMentionedUsers().isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention an user!").queue();
return;
}
for (User user : event.getMessage().getMentionedUsers()) {
reason = reason.replaceAll("(\\s+)?<@!?" + user.getId() + ">(\\s+)?", "");
}
int index = reason.indexOf("time:");
if (index < 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot temp ban an user without giving me the time!").queue();
return;
}
String time = reason.substring(index);
reason = reason.replace(time, "").trim();
time = time.replaceAll("time:(\\s+)?", "");
if (reason.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot temp ban someone without a reason.!").queue();
return;
}
if (time.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot temp ban someone without giving me the time!").queue();
return;
}
final DBGuild db = MantaroData.db().getGuild(event.getGuild());
long l = Utils.parseTime(time);
String finalReason = String.format("Temporally banned by %#s: %s", event.getAuthor(), reason);
String sTime = StringUtils.parseTime(l);
receivedMessage.getMentionedUsers().forEach(user -> guild.getController().ban(user, 7).queue(success -> user.openPrivateChannel().queue(privateChannel -> {
if (!user.isBot()) {
privateChannel.sendMessage(String.format("%sYou were **temporarily banned** by %s#%s with reason: %s on server **%s**.", EmoteReference.MEGA, event.getAuthor().getName(), event.getAuthor().getDiscriminator(), finalReason, event.getGuild().getName())).queue();
}
db.getData().setCases(db.getData().getCases() + 1);
db.saveAsync();
channel.sendMessage(String.format("%s%s (%s got temporarly banned)", EmoteReference.ZAP, modActionQuotes[r.nextInt(modActionQuotes.length)], user.getName())).queue();
ModLog.log(event.getMember(), user, finalReason, ModLog.ModAction.TEMP_BAN, db.getData().getCases(), sTime);
MantaroBot.getTempBanManager().addTempban(guild.getId() + ":" + user.getId(), l + System.currentTimeMillis());
TextChannelGround.of(event).dropItemWithChance(1, 2);
}), error -> {
if (error instanceof PermissionException) {
channel.sendMessage(String.format("%sError banning %s: (I need the permission %s)", EmoteReference.ERROR, user.getName(), ((PermissionException) error).getPermission())).queue();
} else {
channel.sendMessage(String.format("%sI encountered an unknown error while banning %s", EmoteReference.ERROR, user.getName())).queue();
log.warn("Encountered an unexpected error while trying to ban someone.", error);
}
}));
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Tempban Command").setDescription("**Temporarily bans an user**").addField("Usage", "`~>tempban <user> <reason> time:<time>`", false).addField("Example", "`~>tempban @Kodehawa example time:1d`", false).addField("Extended usage", "`time` - can be used with the following parameters: " + "d (days), s (second), m (minutes), h (hour). **For example time:1d1h will give a day and an hour.**", false).build();
}
});
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class ModerationCmds method softban.
@Subscribe
public void softban(CommandRegistry cr) {
cr.register("softban", new SimpleCommand(Category.MODERATION) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
Guild guild = event.getGuild();
User author = event.getAuthor();
TextChannel channel = event.getChannel();
Message receivedMessage = event.getMessage();
String reason = content;
if (!guild.getMember(author).hasPermission(Permission.BAN_MEMBERS)) {
channel.sendMessage(EmoteReference.ERROR2 + "Cannot soft ban: You don't have the Ban Members permission.").queue();
return;
}
if (receivedMessage.getMentionedUsers().isEmpty()) {
channel.sendMessage(EmoteReference.ERROR + "You must mention 1 or more users to be soft-banned!").queue();
return;
}
Member selfMember = guild.getSelfMember();
if (!selfMember.hasPermission(Permission.BAN_MEMBERS)) {
channel.sendMessage(EmoteReference.ERROR2 + "Sorry! I don't have permission to ban members in this server!").queue();
return;
}
for (User user : event.getMessage().getMentionedUsers()) {
reason = reason.replaceAll("(\\s+)?<@!?" + user.getId() + ">(\\s+)?", "");
}
if (reason.isEmpty()) {
reason = "Reason not specified";
}
final String finalReason = String.format("Softbanned by %#s: %s", event.getAuthor(), reason);
receivedMessage.getMentionedUsers().forEach(user -> {
if (!event.getGuild().getMember(event.getAuthor()).canInteract(event.getGuild().getMember(user))) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot softban an user in a higher hierarchy than you").queue();
return;
}
if (event.getAuthor().getId().equals(user.getId())) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Why are you trying to soft-ban yourself?").queue();
return;
}
Member member = guild.getMember(user);
if (member == null)
return;
// If one of them is in a higher hierarchy than the bot, cannot ban.
if (!selfMember.canInteract(member)) {
channel.sendMessage(EmoteReference.ERROR2 + "Cannot softban member: " + member.getEffectiveName() + ", they are " + "higher or the same " + "hierarchy than I am!").queue();
return;
}
final DBGuild db = MantaroData.db().getGuild(event.getGuild());
// Proceed to ban them. Again, using queue so I don't get rate limited.
guild.getController().ban(member, 7).reason(finalReason).queue(success -> user.openPrivateChannel().queue(privateChannel -> {
if (!user.isBot()) {
privateChannel.sendMessage(String.format("%sYou were **softbanned** by %s#%s for reason %s on server **%s**.", EmoteReference.MEGA, event.getAuthor().getName(), event.getAuthor().getDiscriminator(), finalReason, event.getGuild().getName())).queue();
}
db.getData().setCases(db.getData().getCases() + 1);
db.saveAsync();
channel.sendMessage(String.format("%s%s. **(%s got softbanned)**", EmoteReference.ZAP, modActionQuotes[r.nextInt(modActionQuotes.length)], member.getEffectiveName())).queue();
guild.getController().unban(member.getUser()).reason(finalReason).queue(aVoid -> {
}, error -> {
if (error instanceof PermissionException) {
channel.sendMessage(String.format(EmoteReference.ERROR + "Error unbanning [%s]: (No permission provided: %s)", member.getEffectiveName(), ((PermissionException) error).getPermission())).queue();
} else {
channel.sendMessage(String.format(EmoteReference.ERROR + "Unknown error while unbanning [%s]: <%s>: %s", member.getEffectiveName(), error.getClass().getSimpleName(), error.getMessage())).queue();
log.warn("Unexpected error while unbanning someone.", error);
}
});
ModLog.log(event.getMember(), user, finalReason, ModLog.ModAction.KICK, db.getData().getCases());
TextChannelGround.of(event).dropItemWithChance(2, 2);
}), error -> {
if (error instanceof PermissionException) {
channel.sendMessage(String.format(EmoteReference.ERROR + "Error softbanning %s: (No permission provided: %s)", member.getEffectiveName(), ((PermissionException) error).getPermission())).queue();
} else {
channel.sendMessage(String.format(EmoteReference.ERROR + "Unknown error while softbanning %s", member.getEffectiveName())).queue();
log.warn("Unexpected error while soft banning someone.", error);
}
});
});
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Softban").setDescription("**Softban the mentioned user and clears their messages from the past week. (You need Ban " + "Members)**").addField("Summarizing", "A soft ban is a ban & instant unban, normally used to clear " + "the user's messages but **without banning the person permanently**.", false).build();
}
});
}
use of net.kodehawa.mantarobot.core.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class ModerationCmds method ban.
@Subscribe
public void ban(CommandRegistry cr) {
cr.register("ban", new SimpleCommand(Category.MODERATION) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
Guild guild = event.getGuild();
User author = event.getAuthor();
TextChannel channel = event.getChannel();
Message receivedMessage = event.getMessage();
String reason = content;
if (!guild.getMember(author).hasPermission(net.dv8tion.jda.core.Permission.BAN_MEMBERS)) {
channel.sendMessage(EmoteReference.ERROR + "You can't ban: You need the `Ban Users` permission.").queue();
return;
}
if (receivedMessage.getMentionedUsers().isEmpty()) {
channel.sendMessage(EmoteReference.ERROR + "You need to mention at least one user!").queue();
return;
}
for (User user : event.getMessage().getMentionedUsers()) {
reason = reason.replaceAll("(\\s+)?<@!?" + user.getId() + ">(\\s+)?", "");
}
if (reason.isEmpty()) {
reason = "Reason not specified";
}
final String finalReason = String.format("Banned by %#s: %s", event.getAuthor(), reason);
receivedMessage.getMentionedUsers().forEach(user -> {
if (!event.getGuild().getMember(event.getAuthor()).canInteract(event.getGuild().getMember(user))) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot ban an user who's higher than you in the " + "server hierarchy! Nice try " + EmoteReference.SMILE).queue();
return;
}
if (event.getAuthor().getId().equals(user.getId())) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Why are you trying to ban yourself, silly?").queue();
return;
}
Member member = guild.getMember(user);
if (member == null)
return;
if (!guild.getSelfMember().canInteract(member)) {
channel.sendMessage(String.format("%sI can't ban %s; they're higher in the server hierarchy than me!", EmoteReference.ERROR, member.getEffectiveName())).queue();
return;
}
if (!guild.getSelfMember().hasPermission(net.dv8tion.jda.core.Permission.BAN_MEMBERS)) {
channel.sendMessage(EmoteReference.ERROR + "Sorry! I don't have permission to ban members in this server!").queue();
return;
}
final DBGuild db = MantaroData.db().getGuild(event.getGuild());
guild.getController().ban(member, 7).reason(finalReason).queue(success -> user.openPrivateChannel().queue(privateChannel -> {
if (!user.isBot()) {
privateChannel.sendMessage(String.format("%sYou were **banned** by %s#%s on server **%s**. Reason: %s.", EmoteReference.MEGA, event.getAuthor().getName(), event.getAuthor().getDiscriminator(), event.getGuild().getName(), finalReason)).queue();
}
db.getData().setCases(db.getData().getCases() + 1);
db.saveAsync();
channel.sendMessage(String.format("%s%s (%s got banned)", EmoteReference.ZAP, modActionQuotes[r.nextInt(modActionQuotes.length)], user.getName())).queue();
ModLog.log(event.getMember(), user, finalReason, ModLog.ModAction.BAN, db.getData().getCases());
TextChannelGround.of(event).dropItemWithChance(1, 2);
}), error -> {
if (error instanceof PermissionException) {
channel.sendMessage(String.format("%sError banning %s: (I need the permission %s)", EmoteReference.ERROR, user.getName(), ((PermissionException) error).getPermission())).queue();
} else {
channel.sendMessage(String.format("%sI encountered an unknown error while banning %s", EmoteReference.ERROR, member.getEffectiveName())).queue();
log.warn("Encountered an unexpected error while trying to ban someone.", error);
}
});
});
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Ban").setDescription("**Bans the mentioned users. (You need Ban Members)**").addField("Usage", "`~>ban <@user> <reason>` - **Bans the specified user**", false).build();
}
});
}
Aggregations