Search in sources :

Example 1 with IRole

use of io.discloader.discloader.entity.guild.IRole in project DiscLoader by R3alCl0ud.

the class GuildChannel method permissionsOf.

@Override
public IPermission permissionsOf(IGuildMember member) {
    long raw = 0;
    if (getGuild().isOwner(member))
        return new Permission(member, this, 2146958463);
    for (IRole role : member.getRoles()) {
        if (role != null) {
            raw |= role.getPermissions().toLong();
        }
    }
    for (IOverwrite overwrite : overwritesOf(member)) {
        raw |= overwrite.getAllowed();
        raw &= ~overwrite.getDenied();
    }
    return new Permission(member, this, raw);
}
Also used : IRole(io.discloader.discloader.entity.guild.IRole) IPermission(io.discloader.discloader.entity.IPermission) Permission(io.discloader.discloader.core.entity.Permission) IOverwrite(io.discloader.discloader.entity.IOverwrite)

Example 2 with IRole

use of io.discloader.discloader.entity.guild.IRole in project DiscLoader by R3alCl0ud.

the class Guild method addRole.

@Override
public IRole addRole(RoleJSON guildRole) {
    boolean exists = roles.containsKey(SnowflakeUtil.parse(guildRole.id));
    IRole role = new Role(this, guildRole);
    roles.put(role.getID(), role);
    GuildRoleCreateEvent event = new GuildRoleCreateEvent(role);
    if (!exists && this.loader.ready) {
        loader.emit(event);
    }
    return role;
}
Also used : CreateRole(io.discloader.discloader.network.rest.actions.guild.CreateRole) SendableRole(io.discloader.discloader.entity.sendable.SendableRole) IRole(io.discloader.discloader.entity.guild.IRole) IRole(io.discloader.discloader.entity.guild.IRole) GuildRoleCreateEvent(io.discloader.discloader.common.event.guild.role.GuildRoleCreateEvent)

Example 3 with IRole

use of io.discloader.discloader.entity.guild.IRole in project DiscLoader by R3alCl0ud.

the class GuildEmoji method getRoles.

@Override
public Map<Long, IRole> getRoles() {
    Map<Long, IRole> roles = new HashMap<>();
    for (String roleID : roleIDs) {
        IRole role = guild.getRoleByID(roleID);
        roles.put(role.getID(), role);
    }
    return roles;
}
Also used : IRole(io.discloader.discloader.entity.guild.IRole) HashMap(java.util.HashMap)

Example 4 with IRole

use of io.discloader.discloader.entity.guild.IRole in project DiscLoader by R3alCl0ud.

the class RoleDelete method handle.

@Override
public void handle(SocketPacket packet) {
    String d = this.gson.toJson(packet.d);
    GuildRoleJSON data = this.gson.fromJson(d, GuildRoleJSON.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    IRole role = guild.removeRole(data.role_id);
    if (role == null)
        return;
    GuildRoleDeleteEvent event = new GuildRoleDeleteEvent(role);
    loader.emit(DLUtil.Events.GUILD_ROLE_DELETE, event);
    loader.emit(event);
}
Also used : IRole(io.discloader.discloader.entity.guild.IRole) IGuild(io.discloader.discloader.entity.guild.IGuild) GuildRoleJSON(io.discloader.discloader.network.json.GuildRoleJSON) GuildRoleDeleteEvent(io.discloader.discloader.common.event.guild.role.GuildRoleDeleteEvent)

Example 5 with IRole

use of io.discloader.discloader.entity.guild.IRole in project DiscLoader by R3alCl0ud.

the class RoleUpdate method handle.

@Override
public void handle(SocketPacket packet) {
    String d = this.gson.toJson(packet.d);
    Packet data = this.gson.fromJson(d, Packet.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    IRole oldRole = guild.getRoleByID(data.role.id);
    IRole role = guild.addRole(data.role);
    GuildRoleUpdateEvent event = new GuildRoleUpdateEvent(role, oldRole);
    loader.emit(DLUtil.Events.GUILD_ROLE_UPDATE, event);
    loader.emit(event);
}
Also used : GuildRoleUpdateEvent(io.discloader.discloader.common.event.guild.role.GuildRoleUpdateEvent) IRole(io.discloader.discloader.entity.guild.IRole) IGuild(io.discloader.discloader.entity.guild.IGuild)

Aggregations

IRole (io.discloader.discloader.entity.guild.IRole)10 PermissionsException (io.discloader.discloader.common.exceptions.PermissionsException)3 IGuild (io.discloader.discloader.entity.guild.IGuild)3 IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)3 EventListenerAdapter (io.discloader.discloader.common.event.EventListenerAdapter)2 GuildMemberUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent)2 GuildRoleCreateEvent (io.discloader.discloader.common.event.guild.role.GuildRoleCreateEvent)2 GuildRoleJSON (io.discloader.discloader.network.json.GuildRoleJSON)2 RoleJSON (io.discloader.discloader.network.json.RoleJSON)2 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 JSONObject (org.json.JSONObject)2 IEventListener (io.discloader.discloader.common.event.IEventListener)1 GuildRoleDeleteEvent (io.discloader.discloader.common.event.guild.role.GuildRoleDeleteEvent)1 GuildRoleUpdateEvent (io.discloader.discloader.common.event.guild.role.GuildRoleUpdateEvent)1 AccountTypeException (io.discloader.discloader.common.exceptions.AccountTypeException)1 GuildSyncException (io.discloader.discloader.common.exceptions.GuildSyncException)1 MissmatchException (io.discloader.discloader.common.exceptions.MissmatchException)1 UnauthorizedException (io.discloader.discloader.common.exceptions.UnauthorizedException)1 Permission (io.discloader.discloader.core.entity.Permission)1