use of net.dv8tion.jda.internal.requests.Route in project pokeraidbot by magnusmickelsson.
the class InstallEmotesCommand method createEmote.
// Code taken from JDA's GuildController since they have a limitation that bot accounts can't upload emotes.
private void createEmote(String iconName, CommandEvent commandEvent, Icon icon, Role... roles) {
JSONObject body = new JSONObject();
body.put("name", iconName);
body.put("image", icon.getEncoding());
if (// making sure none of the provided roles are null before mapping them to the snowflake id
roles.length > 0) {
body.put("roles", Stream.of(roles).filter(Objects::nonNull).map(ISnowflake::getId).collect(Collectors.toSet()));
}
StringWriter writer = new StringWriter();
body.write(writer);
DataObject dataObject = DataObject.fromJson(writer.toString());
GuildImpl guild = (GuildImpl) commandEvent.getGuild();
JDA jda = commandEvent.getJDA();
Route.CompiledRoute route = Route.Emotes.CREATE_EMOTE.compile(guild.getId());
AuditableRestAction<Emote> action = new AuditableRestActionImpl<Emote>(jda, route, dataObject) {
@Override
public void handleResponse(Response response, Request<Emote> request) {
if (response.isOk()) {
DataObject obj = response.getObject();
final long id = obj.getLong("id");
String name = obj.getString("name");
EmoteImpl emote = new EmoteImpl(id, guild).setName(name);
// managed is false by default, should always be false for emotes created by client accounts.
DataArray rolesArr = obj.getArray("roles");
Set<Role> roleSet = emote.getRoleSet();
for (int i = 0; i < rolesArr.length(); i++) {
roleSet.add(guild.getRoleById(rolesArr.getString(i)));
}
// put emote into cache
guild.createEmote(name, icon, roles);
request.onSuccess(emote);
} else {
request.onFailure(response);
throw new RuntimeException("Couldn't install emojis. " + "Make sure that pokeraidbot has access to manage emojis.");
}
}
};
action.queue();
}
use of net.dv8tion.jda.internal.requests.Route in project JDA by DV8FromTheWorld.
the class ReceivedMessage method suppressEmbeds.
@Nonnull
@Override
public AuditableRestAction<Void> suppressEmbeds(boolean suppressed) {
if (isEphemeral())
throw new IllegalStateException("Cannot suppress embeds on ephemeral messages.");
if (!getJDA().getSelfUser().equals(getAuthor())) {
if (isFromType(ChannelType.PRIVATE))
throw new PermissionException("Cannot suppress embeds of others in a PrivateChannel.");
GuildMessageChannel gChan = getGuildChannel();
if (!getGuild().getSelfMember().hasPermission(gChan, Permission.MESSAGE_MANAGE))
throw new InsufficientPermissionException(gChan, Permission.MESSAGE_MANAGE);
}
JDAImpl jda = (JDAImpl) getJDA();
Route.CompiledRoute route = Route.Messages.EDIT_MESSAGE.compile(getChannel().getId(), getId());
int newFlags = flags;
int suppressionValue = MessageFlag.EMBEDS_SUPPRESSED.getValue();
if (suppressed)
newFlags |= suppressionValue;
else
newFlags &= ~suppressionValue;
return new AuditableRestActionImpl<>(jda, route, DataObject.empty().put("flags", newFlags));
}
use of net.dv8tion.jda.internal.requests.Route in project JDA by DV8FromTheWorld.
the class RoleImpl method delete.
@Nonnull
@Override
public AuditableRestAction<Void> delete() {
Guild guild = getGuild();
if (!guild.getSelfMember().hasPermission(Permission.MANAGE_ROLES))
throw new InsufficientPermissionException(guild, Permission.MANAGE_ROLES);
if (!PermissionUtil.canInteract(guild.getSelfMember(), this))
throw new HierarchyException("Can't delete role >= highest self-role");
if (managed)
throw new UnsupportedOperationException("Cannot delete a Role that is managed. ");
Route.CompiledRoute route = Route.Roles.DELETE_ROLE.compile(guild.getId(), getId());
return new AuditableRestActionImpl<>(getJDA(), route);
}
use of net.dv8tion.jda.internal.requests.Route in project JDA by DV8FromTheWorld.
the class StageChannelImpl method requestToSpeak.
@Nonnull
@Override
public RestAction<Void> requestToSpeak() {
Guild guild = getGuild();
Route.CompiledRoute route = Route.Guilds.UPDATE_VOICE_STATE.compile(guild.getId(), "@me");
DataObject body = DataObject.empty().put("channel_id", getId());
// Stage moderators can bypass the request queue by just unsuppressing
if (guild.getSelfMember().hasPermission(this, Permission.VOICE_MUTE_OTHERS))
body.putNull("request_to_speak_timestamp").put("suppress", false);
else
body.put("request_to_speak_timestamp", OffsetDateTime.now().toString());
if (!this.equals(guild.getSelfMember().getVoiceState().getChannel()))
throw new IllegalStateException("Cannot request to speak without being connected to the stage channel!");
return new RestActionImpl<>(getJDA(), route, body);
}
use of net.dv8tion.jda.internal.requests.Route in project JDA by DV8FromTheWorld.
the class StageChannelImpl method cancelRequestToSpeak.
@Nonnull
@Override
public RestAction<Void> cancelRequestToSpeak() {
Guild guild = getGuild();
Route.CompiledRoute route = Route.Guilds.UPDATE_VOICE_STATE.compile(guild.getId(), "@me");
DataObject body = DataObject.empty().putNull("request_to_speak_timestamp").put("suppress", true).put("channel_id", getId());
if (!this.equals(guild.getSelfMember().getVoiceState().getChannel()))
throw new IllegalStateException("Cannot cancel request to speak without being connected to the stage channel!");
return new RestActionImpl<>(getJDA(), route, body);
}
Aggregations