Search in sources :

Example 1 with SinceSkybot

use of ml.duncte123.skybot.SinceSkybot in project SkyBot by duncte123.

the class AnnounceCommand method executeCommand.

@Override
public void executeCommand(String invoke, String[] args, GuildMessageReceivedEvent event) {
    Permission[] perms = { Permission.ADMINISTRATOR };
    if (!event.getMember().hasPermission(perms)) {
        MessageUtils.sendMsg(event, "I'm sorry but you don't have permission to run this command.");
        return;
    }
    if (event.getMessage().getMentionedChannels().size() < 1) {
        MessageUtils.sendMsg(event, "Correct usage is `" + PREFIX + getName() + " [#Channel] [Message]`");
        return;
    }
    try {
        TextChannel targetChannel = event.getMessage().getMentionedChannels().get(0);
        if (!targetChannel.getGuild().getSelfMember().hasPermission(targetChannel, Permission.MESSAGE_WRITE, Permission.MESSAGE_READ)) {
            MessageUtils.sendMsg(event, "I can not talk in " + targetChannel.getAsMention());
            MessageUtils.sendError(event.getMessage());
            return;
        }
        String msg = event.getMessage().getContentRaw().split("\\s+", 3)[2];
        @SinceSkybot(version = "3.52.3") EmbedBuilder embed = EmbedUtils.defaultEmbed().setDescription(msg).setFooter(null, "");
        if (!event.getMessage().getAttachments().isEmpty()) {
            event.getMessage().getAttachments().stream().filter(Message.Attachment::isImage).findFirst().ifPresent(attachment -> {
                if (invoke.endsWith("2"))
                    embed.setThumbnail(attachment.getUrl());
                else
                    embed.setImage(attachment.getUrl());
            });
        }
        MessageUtils.sendEmbed(targetChannel, embed.build());
        MessageUtils.sendSuccess(event.getMessage());
    } catch (ArrayIndexOutOfBoundsException ex) {
        MessageUtils.sendErrorWithMessage(event.getMessage(), "Please! You either forgot the text or to mention the channel!");
        ComparatingUtils.execCheck(ex);
    } catch (Exception e) {
        MessageUtils.sendMsg(event, "WHOOPS: " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) SinceSkybot(ml.duncte123.skybot.SinceSkybot) Permission(net.dv8tion.jda.core.Permission)

Aggregations

SinceSkybot (ml.duncte123.skybot.SinceSkybot)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 Permission (net.dv8tion.jda.core.Permission)1 TextChannel (net.dv8tion.jda.core.entities.TextChannel)1