use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.
the class ImageCmds method catgirls.
@Command
public static void catgirls(CommandRegistry cr) {
cr.register("catgirl", new SimpleCommand(Category.IMAGE) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
boolean nsfw = args.length > 0 && args[0].equalsIgnoreCase("nsfw");
if (nsfw && !nsfwCheck(event, true, true))
return;
try {
JSONObject obj = Unirest.get(nsfw ? NSFWURL : BASEURL).asJson().getBody().getObject();
if (!obj.has("url")) {
event.getChannel().sendMessage("Unable to find image").queue();
} else {
event.getChannel().sendFile(CACHE.getInput(obj.getString("url")), "catgirl.png", null).queue();
}
} catch (UnirestException e) {
e.printStackTrace();
event.getChannel().sendMessage("Unable to get image").queue();
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Catgirl command").setDescription("**Sends catgirl images**").addField("Usage", "`~>catgirl` - **Returns catgirl images.**" + "\n´`~>catgirl nsfw` - **Returns lewd or questionable cargirl images.**", false).build();
}
});
}
use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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();
}
});
}
Aggregations