Search in sources :

Example 1 with IUser

use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.

the class Mentions method patch.

public void patch(UserJSON[] mentions, RoleJSON[] mention_roles, boolean mention_everyone) {
    everyone = mention_everyone;
    users.clear();
    roles.clear();
    for (UserJSON data : mentions) {
        IUser user = EntityRegistry.getUserByID(data.id);
        if (user == null)
            user = EntityRegistry.addUser(data);
        users.put(SnowflakeUtil.parse(data.id), user);
    }
    if (guild != null) {
        for (RoleJSON data : mention_roles) {
            long id = SnowflakeUtil.parse(data.id);
            roles.put(id, guild.getRoles().get(id));
        }
    }
}
Also used : UserJSON(io.discloader.discloader.network.json.UserJSON) IUser(io.discloader.discloader.entity.user.IUser) RoleJSON(io.discloader.discloader.network.json.RoleJSON)

Example 2 with IUser

use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.

the class Reaction method getUsers.

@Override
public CompletableFuture<List<IUser>> getUsers() {
    CompletableFuture<List<IUser>> future = new CompletableFuture<>();
    CompletableFuture<IUser[]> cf = message.getLoader().rest.request(Methods.GET, Endpoints.messageReaction(message.getChannel().getID(), message.getID(), SnowflakeUtil.asString(emoji)), new RESTOptions(), IUser[].class);
    cf.thenAcceptAsync(ius -> {
        List<IUser> users = new ArrayList<>();
        for (IUser usr : ius) {
            users.add(usr);
        }
        future.complete(users);
    });
    return future;
// return new RESTAction<List<IUser>>(message.getLoader()) {
// 
// @Override
// public CompletableFuture<List<IUser>> execute() {
// return
// super.execute(loader.rest.makeRequest(Endpoints.messageReaction(message.getChannel().getID(),
// message.getID(), SnowflakeUtil.asString(emoji)), Methods.GET, true));
// }
// 
// @Override
// public void complete(String text, Throwable ex) {
// if (ex != null) {
// future.completeExceptionally(ex);
// return;
// }
// }
// }.execute();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) ArrayList(java.util.ArrayList) IUser(io.discloader.discloader.entity.user.IUser) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with IUser

use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.

the class DLUser method getOAuth2Application.

/**
 * Gets the OAuth2 application of the logged in user, if {@link User#isBot()}
 * returns true
 *
 * @return A Future that completes with a new {@link OAuth2Application} if
 *         successful.
 * @throws AccountTypeException
 *             Thrown if the account the client is logged in as is a user
 *             account.
 */
public CompletableFuture<OAuth2Application> getOAuth2Application() {
    if (!isBot()) {
        throw new AccountTypeException("Cannot fetch the OAuth2Application details of a User Account.");
    }
    CompletableFuture<OAuth2Application> future = new CompletableFuture<>();
    CompletableFuture<OAuthApplicationJSON> cf = getLoader().rest.request(Methods.GET, Endpoints.currentOAuthApplication, new RESTOptions(), OAuthApplicationJSON.class);
    cf.thenAcceptAsync(appData -> {
        IUser owner = EntityRegistry.addUser(appData.owner);
        future.complete(new OAuth2Application(appData, owner));
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : OAuthApplicationJSON(io.discloader.discloader.network.json.OAuthApplicationJSON) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) AccountTypeException(io.discloader.discloader.common.exceptions.AccountTypeException) IUser(io.discloader.discloader.entity.user.IUser)

Example 4 with IUser

use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.

the class GuildBanAdd method handle.

@Override
public void handle(SocketPacket packet) {
    String d = gson.toJson(packet.d);
    GuildMemberRemoveJSON data = this.gson.fromJson(d, GuildMemberRemoveJSON.class);
    IGuild guild = EntityRegistry.getGuildByID(data.guild_id);
    IUser user = EntityRegistry.addUser(data.user);
    guild.removeMember(user);
    GuildBanAddEvent event = new GuildBanAddEvent(guild, user);
    loader.emit(DLUtil.Events.GUILD_BAN_ADD, event);
    loader.emit(event);
}
Also used : GuildMemberRemoveJSON(io.discloader.discloader.network.json.GuildMemberRemoveJSON) GuildBanAddEvent(io.discloader.discloader.common.event.guild.GuildBanAddEvent) IUser(io.discloader.discloader.entity.user.IUser) IGuild(io.discloader.discloader.entity.guild.IGuild)

Example 5 with IUser

use of io.discloader.discloader.entity.user.IUser in project DiscLoader by R3alCl0ud.

the class ReactionRemove method handle.

public void handle(SocketPacket packet) {
    ReactionJSON data = gson.fromJson(gson.toJson(packet.d), ReactionJSON.class);
    IUser user = EntityRegistry.getUserByID(data.user_id);
    ITextChannel channel = EntityRegistry.getTextChannelByID(data.channel_id);
    if (channel == null)
        channel = EntityRegistry.getPrivateChannelByID(data.channel_id);
    if (channel == null)
        return;
    IMessage message = channel.getMessage(data.message_id);
    if (message == null || user == null)
        return;
    IReaction reaction = new Reaction(data, message);
    for (IReaction r : message.getReactions()) {
        if (r.getEmoji().toString().equals(reaction.toString()))
            reaction = r;
    }
    message.getReactions().remove(reaction);
    loader.emit(new MessageReactionRemoveEvent(message, reaction, user));
}
Also used : ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) MessageReactionRemoveEvent(io.discloader.discloader.common.event.message.MessageReactionRemoveEvent) IMessage(io.discloader.discloader.entity.message.IMessage) IUser(io.discloader.discloader.entity.user.IUser) IReaction(io.discloader.discloader.entity.message.IReaction) ReactionJSON(io.discloader.discloader.network.json.ReactionJSON) Reaction(io.discloader.discloader.core.entity.message.Reaction) IReaction(io.discloader.discloader.entity.message.IReaction)

Aggregations

IUser (io.discloader.discloader.entity.user.IUser)10 ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)3 IGuild (io.discloader.discloader.entity.guild.IGuild)3 Reaction (io.discloader.discloader.core.entity.message.Reaction)2 IMessage (io.discloader.discloader.entity.message.IMessage)2 IReaction (io.discloader.discloader.entity.message.IReaction)2 GuildMemberRemoveJSON (io.discloader.discloader.network.json.GuildMemberRemoveJSON)2 ReactionJSON (io.discloader.discloader.network.json.ReactionJSON)2 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 UserUpdateEvent (io.discloader.discloader.common.event.UserUpdateEvent)1 TypingStartEvent (io.discloader.discloader.common.event.channel.TypingStartEvent)1 GuildBanAddEvent (io.discloader.discloader.common.event.guild.GuildBanAddEvent)1 GuildBanRemoveEvent (io.discloader.discloader.common.event.guild.GuildBanRemoveEvent)1 GuildMemberUpdateEvent (io.discloader.discloader.common.event.guild.member.GuildMemberUpdateEvent)1 MessageReactionAddEvent (io.discloader.discloader.common.event.message.MessageReactionAddEvent)1 MessageReactionRemoveEvent (io.discloader.discloader.common.event.message.MessageReactionRemoveEvent)1 AccountTypeException (io.discloader.discloader.common.exceptions.AccountTypeException)1 User (io.discloader.discloader.core.entity.user.User)1 IGuildMember (io.discloader.discloader.entity.guild.IGuildMember)1