use of sx.blah.discord.api.internal.DiscordClientImpl in project Discord4J by Discord4J.
the class Reaction method getUsers.
@Override
public List<IUser> getUsers() {
List<IUser> users = new ArrayList<>();
String emoji = getEmoji().isUnicode() ? getEmoji().getName() : getEmoji().getName() + ":" + getEmoji().getStringID();
String endpoint = String.format(DiscordEndpoints.REACTIONS_USER_LIST, getMessage().getChannel().getStringID(), getMessage().getStringID(), emoji);
String after = "0";
while (users.size() < count) {
UserObject[] json = ((DiscordClientImpl) getClient()).REQUESTS.GET.makeRequest(endpoint + "?after=" + after + "&limit=100", UserObject[].class);
for (UserObject obj : json) {
users.add(getMessage().getShard().getUserByID(Long.parseUnsignedLong(obj.id)));
}
// Temporary measure so a refactor can be applied later.
if (json.length == 0)
break;
after = json[json.length - 1].id;
}
return users;
}
use of sx.blah.discord.api.internal.DiscordClientImpl in project Discord4J by Discord4J.
the class NickHolder method moveToVoiceChannel.
@Override
public void moveToVoiceChannel(IVoiceChannel channel) {
IVoiceChannel oldChannel = getVoiceStateForGuild(channel.getGuild()).getChannel();
if (oldChannel == null)
throw new DiscordException("User must already be in a voice channel before they can be moved to another.");
// client must have permission to both move members and connect to the channel.
PermissionUtils.requirePermissions(channel, client.getOurUser(), Permissions.VOICE_MOVE_MEMBERS, Permissions.VOICE_CONNECT);
try {
((DiscordClientImpl) client).REQUESTS.PATCH.makeRequest(DiscordEndpoints.GUILDS + channel.getGuild().getStringID() + "/members/" + id, DiscordUtils.MAPPER_NO_NULLS.writeValueAsString(new MemberEditRequest.Builder().channel(channel.getStringID()).build()));
} catch (JsonProcessingException e) {
Discord4J.LOGGER.error(LogMarkers.HANDLE, "Discord4J Internal Exception", e);
}
}
use of sx.blah.discord.api.internal.DiscordClientImpl in project Discord4J by Discord4J.
the class Guild method loadWebhooks.
/**
* Forcibly loads and caches all webhooks for the channel.
*/
public void loadWebhooks() {
try {
PermissionUtils.requirePermissions(this, client.getOurUser(), Permissions.MANAGE_WEBHOOKS);
} catch (MissingPermissionsException ignored) {
return;
}
RequestBuffer.request(() -> {
try {
List<IWebhook> oldList = getWebhooks().stream().map(IWebhook::copy).collect(Collectors.toCollection(CopyOnWriteArrayList::new));
WebhookObject[] response = ((DiscordClientImpl) client).REQUESTS.GET.makeRequest(DiscordEndpoints.GUILDS + getStringID() + "/webhooks", WebhookObject[].class);
if (response != null) {
for (WebhookObject webhookObject : response) {
Channel channel = (Channel) getChannelByID(Long.parseUnsignedLong(webhookObject.channel_id));
long webhookId = Long.parseUnsignedLong(webhookObject.id);
if (getWebhookByID(webhookId) == null) {
IWebhook newWebhook = DiscordUtils.getWebhookFromJSON(channel, webhookObject);
client.getDispatcher().dispatch(new WebhookCreateEvent(newWebhook));
channel.webhooks.put(newWebhook);
} else {
IWebhook toUpdate = channel.getWebhookByID(webhookId);
IWebhook oldWebhook = toUpdate.copy();
toUpdate = DiscordUtils.getWebhookFromJSON(channel, webhookObject);
if (!oldWebhook.getDefaultName().equals(toUpdate.getDefaultName()) || !String.valueOf(oldWebhook.getDefaultAvatar()).equals(String.valueOf(toUpdate.getDefaultAvatar())))
client.getDispatcher().dispatch(new WebhookUpdateEvent(oldWebhook, toUpdate));
oldList.remove(oldWebhook);
}
}
}
oldList.forEach(webhook -> {
((Channel) webhook.getChannel()).webhooks.remove(webhook);
client.getDispatcher().dispatch(new WebhookDeleteEvent(webhook));
});
} catch (Exception e) {
Discord4J.LOGGER.warn(LogMarkers.HANDLE, "Discord4J Internal Exception", e);
}
});
}
use of sx.blah.discord.api.internal.DiscordClientImpl in project Discord4J by Discord4J.
the class Webhook method edit.
/**
* Sends a request to edit the webhook.
*
* @param name The default name of the webhook.
* @param avatar The base64-encoded default avatar of the webhook.
*/
private void edit(String name, String avatar) {
PermissionUtils.requirePermissions(channel, client.getOurUser(), Permissions.MANAGE_WEBHOOKS);
WebhookObject response = ((DiscordClientImpl) client).REQUESTS.PATCH.makeRequest(DiscordEndpoints.WEBHOOKS + id, new WebhookEditRequest(name, avatar), WebhookObject.class);
IWebhook oldWebhook = copy();
IWebhook newWebhook = DiscordUtils.getWebhookFromJSON(channel, response);
client.getDispatcher().dispatch(new WebhookUpdateEvent(oldWebhook, newWebhook));
}
use of sx.blah.discord.api.internal.DiscordClientImpl in project Discord4J by Discord4J.
the class Category method overridePermissions.
private void overridePermissions(String type, String id, EnumSet<Permissions> toAdd, EnumSet<Permissions> toRemove) {
PermissionUtils.requirePermissions(getModifiedPermissions(getClient().getOurUser()), EnumSet.of(Permissions.MANAGE_PERMISSIONS));
((DiscordClientImpl) client).REQUESTS.PUT.makeRequest(DiscordEndpoints.CHANNELS + getStringID() + "/permissions/" + id, new OverwriteObject(type, null, Permissions.generatePermissionsNumber(toAdd), Permissions.generatePermissionsNumber(toRemove)));
}
Aggregations