Search in sources :

Example 6 with GuildChannel

use of net.dv8tion.jda.api.entities.GuildChannel in project command-flow by unnamed.

the class DiscordAuthorizer method isAuthorized.

@Override
public boolean isAuthorized(Namespace namespace, String permission) {
    if (permission == null || permission.trim().isEmpty()) {
        return true;
    }
    Member member = namespace.getObject(Member.class, DiscordCommandManager.MEMBER_NAMESPACE);
    Message message = namespace.getObject(Message.class, DiscordCommandManager.MESSAGE_NAMESPACE);
    if (!message.isFromGuild()) {
        return true;
    }
    GuildChannel channel = message.getTextChannel();
    Permission permissionValue;
    try {
        permissionValue = Permission.valueOf(permission.toUpperCase());
    } catch (IllegalArgumentException e) {
        message.getChannel().sendMessage("Invalid permission: `" + permission + "`").queue();
        return false;
    }
    return member.hasPermission(channel, permissionValue);
}
Also used : GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) Message(net.dv8tion.jda.api.entities.Message) Permission(net.dv8tion.jda.api.Permission) Member(net.dv8tion.jda.api.entities.Member)

Example 7 with GuildChannel

use of net.dv8tion.jda.api.entities.GuildChannel in project OrderlyDiscordBot by IceLeiYu.

the class ChannelChange method setBitrate.

public void setBitrate(SlashCommandInteractionEvent event) {
    List<String> lang = Main.language.getGuildLang(event.getGuild().getId());
    if (!permissionCheck(Permission.MANAGE_CHANNEL, event, true))
        return;
    GuildChannel channel;
    int bitrate;
    if (!(channel = event.getOption("channel").getAsGuildChannel()).getType().isAudio()) {
        event.getHook().editOriginalEmbeds(createEmbed(lang.get(ChannelChange_CHANNEL_TYPE_ERROR), 0xFF0000)).queue();
        return;
    }
    if ((bitrate = (int) event.getOption("bitrate").getAsLong() * 1000) > event.getGuild().getMaxBitrate()) {
        event.getHook().editOriginalEmbeds(createEmbed(lang.get(ChannelChange_BITRATE_ERROR) + " (8 ~ " + event.getGuild().getMaxBitrate() + " kbps", 0xFF0000)).queue();
        return;
    }
    event.getGuild().getVoiceChannelById(channel.getId()).getManager().setBitrate(bitrate).queue();
    event.getHook().editOriginalEmbeds(createEmbed(lang.get(ChannelChange_CHANGE_SUCCESSFULLY), 0x00FFFF)).queue();
}
Also used : GuildChannel(net.dv8tion.jda.api.entities.GuildChannel)

Example 8 with GuildChannel

use of net.dv8tion.jda.api.entities.GuildChannel in project JDA by DV8FromTheWorld.

the class ChannelOrderActionImpl method finalizeData.

@Override
protected RequestBody finalizeData() {
    final Member self = guild.getSelfMember();
    if (!self.hasPermission(Permission.MANAGE_CHANNEL))
        throw new InsufficientPermissionException(guild, Permission.MANAGE_CHANNEL);
    DataArray array = DataArray.empty();
    for (int i = 0; i < orderList.size(); i++) {
        GuildChannel chan = orderList.get(i);
        array.add(DataObject.empty().put("id", chan.getId()).put("position", i));
    }
    return getRequestBody(array);
}
Also used : GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) InsufficientPermissionException(net.dv8tion.jda.api.exceptions.InsufficientPermissionException) Member(net.dv8tion.jda.api.entities.Member) DataArray(net.dv8tion.jda.api.utils.data.DataArray)

Example 9 with GuildChannel

use of net.dv8tion.jda.api.entities.GuildChannel in project JDA by DV8FromTheWorld.

the class InviteCreateHandler method handleInternally.

@Override
protected Long handleInternally(DataObject content) {
    long guildId = content.getUnsignedLong("guild_id");
    if (getJDA().getGuildSetupController().isLocked(guildId))
        return guildId;
    Guild realGuild = getJDA().getGuildById(guildId);
    if (realGuild == null) {
        EventCache.LOG.debug("Caching INVITE_CREATE for unknown guild with id {}", guildId);
        getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
        return null;
    }
    long channelId = content.getUnsignedLong("channel_id");
    GuildChannel realChannel = realGuild.getGuildChannelById(channelId);
    if (realChannel == null) {
        EventCache.LOG.debug("Caching INVITE_CREATE for unknown channel with id {} in guild with id {}", channelId, guildId);
        getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
        return null;
    }
    String code = content.getString("code");
    boolean temporary = content.getBoolean("temporary");
    int maxAge = content.getInt("max_age", -1);
    int maxUses = content.getInt("max_uses", -1);
    OffsetDateTime creationTime = content.opt("created_at").map(String::valueOf).map(OffsetDateTime::parse).orElse(null);
    Optional<DataObject> inviterJson = content.optObject("inviter");
    boolean expanded = maxUses != -1;
    User inviter = inviterJson.map(json -> getJDA().getEntityBuilder().createUser(json)).orElse(null);
    InviteImpl.ChannelImpl channel = new InviteImpl.ChannelImpl(realChannel);
    InviteImpl.GuildImpl guild = new InviteImpl.GuildImpl(realGuild);
    final Invite.TargetType targetType = Invite.TargetType.fromId(content.getInt("target_type", 0));
    final Invite.InviteTarget target;
    switch(targetType) {
        case STREAM:
            DataObject targetUserObject = content.getObject("target_user");
            target = new InviteImpl.InviteTargetImpl(targetType, null, getJDA().getEntityBuilder().createUser(targetUserObject));
            break;
        case EMBEDDED_APPLICATION:
            DataObject applicationObject = content.getObject("target_application");
            Invite.EmbeddedApplication application = new InviteImpl.EmbeddedApplicationImpl(applicationObject.getString("icon", null), applicationObject.getString("name"), applicationObject.getString("description"), applicationObject.getString("summary"), applicationObject.getLong("id"), applicationObject.getInt("max_participants", -1));
            target = new InviteImpl.InviteTargetImpl(targetType, application, null);
            break;
        case NONE:
            target = null;
            break;
        default:
            target = new InviteImpl.InviteTargetImpl(targetType, null, null);
    }
    Invite invite = new InviteImpl(getJDA(), code, expanded, inviter, maxAge, maxUses, temporary, creationTime, 0, channel, guild, null, target, Invite.InviteType.GUILD);
    getJDA().handleEvent(new GuildInviteCreateEvent(getJDA(), responseNumber, invite, realChannel));
    return null;
}
Also used : Guild(net.dv8tion.jda.api.entities.Guild) OffsetDateTime(java.time.OffsetDateTime) InviteImpl(net.dv8tion.jda.internal.entities.InviteImpl) JDAImpl(net.dv8tion.jda.internal.JDAImpl) GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) GuildInviteCreateEvent(net.dv8tion.jda.api.events.guild.invite.GuildInviteCreateEvent) Optional(java.util.Optional) DataObject(net.dv8tion.jda.api.utils.data.DataObject) Invite(net.dv8tion.jda.api.entities.Invite) User(net.dv8tion.jda.api.entities.User) User(net.dv8tion.jda.api.entities.User) Guild(net.dv8tion.jda.api.entities.Guild) GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) DataObject(net.dv8tion.jda.api.utils.data.DataObject) OffsetDateTime(java.time.OffsetDateTime) GuildInviteCreateEvent(net.dv8tion.jda.api.events.guild.invite.GuildInviteCreateEvent) Invite(net.dv8tion.jda.api.entities.Invite) InviteImpl(net.dv8tion.jda.internal.entities.InviteImpl)

Example 10 with GuildChannel

use of net.dv8tion.jda.api.entities.GuildChannel in project JDA by DV8FromTheWorld.

the class InviteDeleteHandler method handleInternally.

@Override
protected Long handleInternally(DataObject content) {
    long guildId = content.getUnsignedLong("guild_id");
    if (getJDA().getGuildSetupController().isLocked(guildId))
        return guildId;
    Guild guild = getJDA().getGuildById(guildId);
    if (guild == null) {
        EventCache.LOG.debug("Caching INVITE_DELETE for unknown guild {}", guildId);
        getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
        return null;
    }
    long channelId = content.getUnsignedLong("channel_id");
    GuildChannel channel = guild.getGuildChannelById(channelId);
    if (channel == null) {
        EventCache.LOG.debug("Caching INVITE_DELETE for unknown channel {} in guild {}", channelId, guildId);
        getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
        return null;
    }
    String code = content.getString("code");
    getJDA().handleEvent(new GuildInviteDeleteEvent(getJDA(), responseNumber, code, channel));
    return null;
}
Also used : GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) GuildInviteDeleteEvent(net.dv8tion.jda.api.events.guild.invite.GuildInviteDeleteEvent) Guild(net.dv8tion.jda.api.entities.Guild)

Aggregations

GuildChannel (net.dv8tion.jda.api.entities.GuildChannel)16 Guild (net.dv8tion.jda.api.entities.Guild)9 Member (net.dv8tion.jda.api.entities.Member)9 List (java.util.List)6 ArrayList (java.util.ArrayList)5 Permission (net.dv8tion.jda.api.Permission)5 GuildVoiceState (net.dv8tion.jda.api.entities.GuildVoiceState)4 Bean (at.xirado.bean.Bean)3 CommandFlag (at.xirado.bean.command.CommandFlag)3 GenericCommand (at.xirado.bean.command.GenericCommand)3 SlashCommand (at.xirado.bean.command.SlashCommand)3 SlashCommandContext (at.xirado.bean.command.SlashCommandContext)3 MessageContextCommand (at.xirado.bean.command.context.MessageContextCommand)3 UserContextCommand (at.xirado.bean.command.context.UserContextCommand)3 MockContextMenuCommand (at.xirado.bean.command.context.message.MockContextMenuCommand)3 SlapContextMenuCommand (at.xirado.bean.command.context.user.SlapContextMenuCommand)3 at.xirado.bean.command.slashcommands (at.xirado.bean.command.slashcommands)3 at.xirado.bean.command.slashcommands.leveling (at.xirado.bean.command.slashcommands.leveling)3 at.xirado.bean.command.slashcommands.moderation (at.xirado.bean.command.slashcommands.moderation)3 at.xirado.bean.command.slashcommands.music (at.xirado.bean.command.slashcommands.music)3