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));
}
}
}
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();
}
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;
}
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);
}
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));
}
Aggregations