    001package co.aikar.commands;
    002
    003import net.dv8tion.jda.core.entities.Message;
    004import net.dv8tion.jda.core.entities.MessageEmbed;
    005import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
    006import org.jetbrains.annotations.NotNull;
    007
    008import java.util.UUID;
    009
    010public class JDACommandEvent implements CommandIssuer {
    011
    012    private MessageReceivedEvent event;
    013    private JDACommandManager manager;
    014
    015    public JDACommandEvent(JDACommandManager manager, MessageReceivedEvent event) {
    016
    017        this.manager = manager;
    018        this.event = event;
    019    }
    020
    021    public MessageReceivedEvent getEvent() {
    022        return event;
    023    }
    024
    025    @Override
    026    public MessageReceivedEvent getIssuer() {
    027        return event;
    028    }
    029
    030    @Override
    031    public CommandManager getManager() {
    032        return this.manager;
    033    }
    034
    035    @Override
    036    public boolean isPlayer() {
    037        return false;
    038    }
    039
    040    @Override
    041    public @NotNull UUID getUniqueId() {
    042        // Discord id only have 64 bit width (long) while UUIDs have twice the size.
    043        // In order to keep it unique we use 0L for the first 64 bit.
    044        long authorId = event.getAuthor().getIdLong();
    045        return new UUID(0, authorId);
    046    }
    047
    048    @Override
    049    public boolean hasPermission(String permission) {
    050        CommandPermissionResolver permissionResolver = this.manager.getPermissionResolver();
    051        return permissionResolver == null || permissionResolver.hasPermission(manager, this, permission);
    052    }
    053
    054    @Override
    055    public void sendMessageInternal(String message) {
    056        this.event.getChannel().sendMessage(message).queue();
    057    }
    058
    059    public void sendMessage(Message message) {
    060        this.event.getChannel().sendMessage(message).queue();
    061    }
    062
    063    public void sendMessage(MessageEmbed message) {
    064        this.event.getChannel().sendMessage(message).queue();
    065    }
    066}