use of net.kodehawa.mantarobot.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class ImageCmds method rule34.
@Command
public static void rule34(CommandRegistry cr) {
cr.register("rule34", new SimpleCommand(Category.IMAGE) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (!nsfwCheck(event, true, true))
return;
String noArgs = content.split(" ")[0];
TextChannelGround.of(event).dropItemWithChance(13, 3);
switch(noArgs) {
case "get":
try {
String whole1 = content.replace("get ", "");
String[] wholeBeheaded = whole1.split(" ");
Rule34.get(60, image -> {
try {
int number;
try {
number = Integer.parseInt(wholeBeheaded[0]);
} catch (Exception e) {
number = r.nextInt(image.size());
}
String TAGS = image.get(number).getTags().replace(" ", " ,");
EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor("Found image", null, "http:" + image.get(number - 1).getFile_url()).setImage("http:" + image.get(number - 1).getFile_url()).addField("Width", String.valueOf(image.get(number - 1).getWidth()), true).addField("Height", String.valueOf(image.get(number - 1).getHeight()), true).addField("Tags", "``" + (TAGS == null ? "None" : TAGS) + "``", false).setFooter("If the image doesn't load, click the title.", null);
event.getChannel().sendMessage(builder.build()).queue();
} catch (ArrayIndexOutOfBoundsException e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't more images or no results found**! Try with a lower number.").queue();
}
});
} catch (Exception exception) {
if (exception instanceof NumberFormatException)
event.getChannel().sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help rule34").queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
}
break;
case "tags":
try {
try {
boolean isOldFormat = args[1].matches("^[0-9]*$");
if (isOldFormat) {
event.getChannel().sendMessage(EmoteReference.WARNING + "Now you don't need to specify the page number. Please use ~>rule34 tags <tag>").queue();
return;
}
String sNoArgs = content.replace("tags ", "");
String[] expectedNumber = sNoArgs.split(" ");
String tags = expectedNumber[0];
Rule34.onSearch(60, tags, images -> {
try {
try {
number1 = Integer.parseInt(expectedNumber[2]);
} catch (Exception e) {
number1 = r.nextInt(images.size() > 0 ? images.size() - 1 : images.size());
}
String TAGS = images.get(number).getTags() == null ? tags : images.get(number).getTags().replace(" ", " ,");
EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor("Found image", null, "http:" + images.get(number1 - 1).getFile_url()).setImage("http:" + images.get(number1 - 1).getFile_url()).addField("Width", String.valueOf(images.get(number1 - 1).getWidth()), true).addField("Height", String.valueOf(images.get(number1 - 1).getHeight()), true).addField("Tags", "``" + (TAGS == null ? "None" : TAGS) + "``", false).setFooter("If the image doesn't load, click the title.", null);
event.getChannel().sendMessage(builder.build()).queue();
} catch (Exception e) {
e.printStackTrace();
event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't more images or no results found**! Try with a lower number.").queue();
}
});
} catch (Exception exception) {
if (exception instanceof NumberFormatException)
event.getChannel().sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help rule34").queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
}
} catch (NullPointerException e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Rule34 decided to not fetch the image. Well, you can try with another number or tag.").queue();
}
break;
default:
onHelp(event);
break;
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "rule34.xxx commmand").setColor(Color.PINK).setDescription("**Retrieves images from the rule34 (hentai) image board.**").addField("Usage", "`~>rule34 get <imagenumber>` - **Gets an image based in parameters.**\n" + "`~>rule34 tags <tag> <imagenumber>` - **Gets an image based in the specified tag and parameters.**\n", false).addField("Parameters", "`page` - **Can be any value from 1 to the rule34 maximum page. Probably around 4000.**\n" + "`imagenumber` - **(OPTIONAL) Any number from 1 to the maximum possible images to get, specified by the first instance of the command.**\n" + "`tag` - **Any valid image tag. For example animal_ears or original.**", false).build();
}
});
}
use of net.kodehawa.mantarobot.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class ModerationCmds method tempban.
@Command
public static 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 = AudioCmdUtils.parseTime(time);
String finalReason = reason;
String sTime = StringUtils.parseTime(l);
receivedMessage.getMentionedUsers().forEach(user -> guild.getController().ban(user, 7).queue(success -> {
user.openPrivateChannel().complete().sendMessage(EmoteReference.MEGA + "You were **temporarly banned** by " + event.getAuthor().getName() + "#" + event.getAuthor().getDiscriminator() + " with reason: " + finalReason + ".").queue();
db.getData().setCases(db.getData().getCases() + 1);
db.saveAsync();
channel.sendMessage(EmoteReference.ZAP + "You will be missed... or not " + 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(EmoteReference.ERROR + "Error banning " + user.getName() + ": " + "(I need the permission " + ((PermissionException) error).getPermission() + ")").queue();
} else {
channel.sendMessage(EmoteReference.ERROR + "I encountered an unknown error while banning " + user.getName() + ": " + "<" + error.getClass().getSimpleName() + ">: " + error.getMessage()).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.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class InfoCmds method guildinfo.
@Command
public static 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("Main Channel", guild.getPublicChannel().getAsMention(), 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.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class InfoCmds method ping.
@Command
public static void ping(CommandRegistry cr) {
RateLimiter rateLimiter = new RateLimiter(TimeUnit.SECONDS, 5);
cr.register("ping", new SimpleCommand(Category.INFO) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (!rateLimiter.process(event.getMember())) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Yikes! Seems like you're going too fast.").queue();
return;
}
long start = System.currentTimeMillis();
event.getChannel().sendTyping().queue(v -> {
long ping = System.currentTimeMillis() - start;
event.getChannel().sendMessage(EmoteReference.MEGA + "My ping: " + ping + " ms - " + ratePing(ping) + " `Websocket:" + event.getJDA().getPing() + "ms`").queue();
TextChannelGround.of(event).dropItemWithChance(5, 5);
});
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Ping Command").setDescription("**Plays Ping-Pong with Discord and prints out the result.**").build();
}
});
}
use of net.kodehawa.mantarobot.modules.commands.SimpleCommand in project MantaroBot by Mantaro.
the class MusicCmds method queue.
@Command
public static void queue(CommandRegistry cr) {
cr.register("queue", new SimpleCommand(Category.MUSIC) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
GuildMusicManager musicManager = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
int page = 0;
try {
page = Math.max(Integer.parseInt(args[0]), 1);
} catch (Exception ignored) {
}
if (content.startsWith("clear")) {
if (!event.getMember().getVoiceState().inVoiceChannel() || !event.getMember().getVoiceState().getChannel().equals(event.getGuild().getAudioManager().getConnectedChannel())) {
sendNotConnectedToMyChannel(event.getChannel());
return;
}
if (isDJ(event.getMember())) {
event.getChannel().sendMessage(EmoteReference.CORRECT + "The server DJ has decided to clear the queue!").queue();
int TEMP_QUEUE_LENGTH = musicManager.getTrackScheduler().getQueue().size();
MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild()).getTrackScheduler().getQueue().clear();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Removed **" + TEMP_QUEUE_LENGTH + " songs** from the queue" + ".").queue();
MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild()).getTrackScheduler().next(true);
return;
}
event.getChannel().sendMessage(EmoteReference.ERROR + "Either you're not connected to the VC or you're not the DJ.").queue();
return;
}
embedForQueue(page, event, musicManager);
TextChannelGround.of(event).dropItemWithChance(0, 10);
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Queue Command").setDescription("**Either returns the current queue playing on the server or clears it.**").addField("Usage:", "`~>queue` - **Shows the queue**\n" + "`~>queue clear` - **Clears the queue**", false).build();
}
});
cr.registerAlias("queue", "q");
}
Aggregations