diff --git a/src/main/java/net/dv8tion/jda/core/audit/ActionType.java b/src/main/java/net/dv8tion/jda/core/audit/ActionType.java
index d1625f2fb0..27e69c29de 100644
--- a/src/main/java/net/dv8tion/jda/core/audit/ActionType.java
+++ b/src/main/java/net/dv8tion/jda/core/audit/ActionType.java
@@ -51,6 +51,7 @@ public enum ActionType
*
{@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_BITRATE CHANNEL_BITRATE} (VoiceChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_USER_LIMIT CHANNEL_USER_LIMIT} (VoiceChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_TOPIC CHANNEL_TOPIC} (TextChannel only)
+ * {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_SLOWMODE CHANNEL_SLOWMODE} (TextChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_NSFW CHANNEL_NSFW} (TextChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_OVERRIDES CHANNEL_OVERRIDES}
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_NAME CHANNEL_NAME}
@@ -68,6 +69,7 @@ public enum ActionType
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_BITRATE CHANNEL_BITRATE} (VoiceChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_USER_LIMIT CHANNEL_USER_LIMIT} (VoiceChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_TOPIC CHANNEL_TOPIC} (TextChannel only)
+ * {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_SLOWMODE CHANNEL_SLOWMODE} (TextChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_NSFW CHANNEL_NSFW} (TextChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_NAME CHANNEL_NAME}
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_TYPE CHANNEL_TYPE}
@@ -83,6 +85,7 @@ public enum ActionType
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_BITRATE CHANNEL_BITRATE} (VoiceChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_USER_LIMIT CHANNEL_USER_LIMIT} (VoiceChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_TOPIC CHANNEL_TOPIC} (TextChannel only)
+ * {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_SLOWMODE CHANNEL_SLOWMODE} (TextChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_NSFW CHANNEL_NSFW} (TextChannel only)
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_OVERRIDES CHANNEL_OVERRIDES}
* {@link net.dv8tion.jda.core.audit.AuditLogKey#CHANNEL_NAME CHANNEL_NAME}
diff --git a/src/main/java/net/dv8tion/jda/core/audit/AuditLogKey.java b/src/main/java/net/dv8tion/jda/core/audit/AuditLogKey.java
index 8f9c7a99c6..55d98ad9b8 100644
--- a/src/main/java/net/dv8tion/jda/core/audit/AuditLogKey.java
+++ b/src/main/java/net/dv8tion/jda/core/audit/AuditLogKey.java
@@ -153,6 +153,14 @@ public enum AuditLogKey
*/
CHANNEL_TOPIC("topic"),
+ /**
+ * Change of the {@link net.dv8tion.jda.core.entities.TextChannel#getSlowmode() TextChannel.getSlowmode()} value.
+ *
Only for {@link net.dv8tion.jda.core.entities.ChannelType#TEXT ChannelType.TEXT}
+ *
+ * Expected type: Integer
+ */
+ CHANNEL_SLOWMODE("rate_limit_per_user"),
+
/**
* Change of the {@link net.dv8tion.jda.core.entities.VoiceChannel#getBitrate() VoiceChannel.getBitrate()} value.
*
Only for {@link net.dv8tion.jda.core.entities.ChannelType#VOICE ChannelType.VOICE}
diff --git a/src/main/java/net/dv8tion/jda/core/entities/EntityBuilder.java b/src/main/java/net/dv8tion/jda/core/entities/EntityBuilder.java
index 9bcb8cf01c..a5e9d6505b 100644
--- a/src/main/java/net/dv8tion/jda/core/entities/EntityBuilder.java
+++ b/src/main/java/net/dv8tion/jda/core/entities/EntityBuilder.java
@@ -609,9 +609,10 @@ public TextChannel createTextChannel(GuildImpl guildObj, JSONObject json, long g
.setParent(Helpers.optLong(json, "parent_id", 0))
.setLastMessageId(Helpers.optLong(json, "last_message_id", 0))
.setName(json.getString("name"))
- .setTopic(json.optString("topic"))
+ .setTopic(json.optString("topic", null))
.setPosition(json.getInt("position"))
- .setNSFW(Helpers.optBoolean(json, "nsfw"));
+ .setNSFW(Helpers.optBoolean(json, "nsfw"))
+ .setSlowmode(Helpers.optInt(json, "rate_limit_per_user", 0));
if (playbackCache)
getJDA().getEventCache().playbackCache(EventCache.Type.CHANNEL, id);
return channel;
diff --git a/src/main/java/net/dv8tion/jda/core/entities/TextChannel.java b/src/main/java/net/dv8tion/jda/core/entities/TextChannel.java
index 1020dd5de4..e81a5f358b 100644
--- a/src/main/java/net/dv8tion/jda/core/entities/TextChannel.java
+++ b/src/main/java/net/dv8tion/jda/core/entities/TextChannel.java
@@ -53,6 +53,21 @@ public interface TextChannel extends Channel, MessageChannel, ComparableIf slowmode is set this returns an {@code int} between 1 and 120. If not set this returns {@code 0}.
+ *
+ * Note that only {@link net.dv8tion.jda.core.AccountType#CLIENT CLIENT} type accounts are
+ * affected by slowmode, and that {@link net.dv8tion.jda.core.AccountType#BOT BOT} accounts
+ * are immune to the restrictions.
+ *
Having {@link net.dv8tion.jda.core.Permission#MESSAGE_MANAGE MESSAGE_MANAGE} or
+ * {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} permission also
+ * grants immunity to slowmode.
+ *
+ * @return The slowmode for this TextChannel, between 1 and 120, or {@code 0} if no slowmode is set.
+ */
+ int getSlowmode();
+
/**
* Retrieves the {@link net.dv8tion.jda.core.entities.Webhook Webhooks} attached to this TextChannel.
*
diff --git a/src/main/java/net/dv8tion/jda/core/entities/impl/TextChannelImpl.java b/src/main/java/net/dv8tion/jda/core/entities/impl/TextChannelImpl.java
index 24a2c58d9f..fd21e3e383 100644
--- a/src/main/java/net/dv8tion/jda/core/entities/impl/TextChannelImpl.java
+++ b/src/main/java/net/dv8tion/jda/core/entities/impl/TextChannelImpl.java
@@ -41,6 +41,7 @@ public class TextChannelImpl extends AbstractChannelImpl implem
private String topic;
private long lastMessageId;
private boolean nsfw;
+ private int slowmode;
public TextChannelImpl(long id, GuildImpl guild)
{
@@ -263,6 +264,12 @@ public boolean isNSFW() {
return nsfw || name.equals("nsfw") || name.startsWith("nsfw-");
}
+ @Override
+ public int getSlowmode()
+ {
+ return slowmode;
+ }
+
@Override
public List getMembers()
{
@@ -537,6 +544,12 @@ public TextChannelImpl setNSFW(boolean nsfw)
return this;
}
+ public TextChannelImpl setSlowmode(int slowmode)
+ {
+ this.slowmode = slowmode;
+ return this;
+ }
+
// -- internal --
private void checkVerification()
diff --git a/src/main/java/net/dv8tion/jda/core/events/channel/text/update/TextChannelUpdateSlowmodeEvent.java b/src/main/java/net/dv8tion/jda/core/events/channel/text/update/TextChannelUpdateSlowmodeEvent.java
new file mode 100644
index 0000000000..bc51d97a6d
--- /dev/null
+++ b/src/main/java/net/dv8tion/jda/core/events/channel/text/update/TextChannelUpdateSlowmodeEvent.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2015-2018 Austin Keener & Michael Ritter & Florian Spieß
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dv8tion.jda.core.events.channel.text.update;
+
+import net.dv8tion.jda.core.JDA;
+import net.dv8tion.jda.core.entities.TextChannel;
+
+/**
+ * Indicates that a {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}'s slowmode changed.
+ *
+ * Can be used to detect when a TextChannel slowmode changes and get its previous value.
+ *
+ *
Identifier: {@code slowmode}
+ */
+public class TextChannelUpdateSlowmodeEvent extends GenericTextChannelUpdateEvent
+{
+ public static final String IDENTIFIER = "slowmode";
+
+ public TextChannelUpdateSlowmodeEvent(JDA api, long responseNumber, TextChannel channel, int oldSlowmode)
+ {
+ super(api, responseNumber, channel, oldSlowmode, channel.getSlowmode(), IDENTIFIER);
+ }
+
+ /**
+ * The old slowmode.
+ *
+ * @return The old slowmode.
+ */
+ public int getOldSlowmode()
+ {
+ return getOldValue();
+ }
+
+ /**
+ * The new slowmode.
+ *
+ * @return The new slowmode.
+ */
+ public int getNewSlowmode()
+ {
+ return getNewValue();
+ }
+}
diff --git a/src/main/java/net/dv8tion/jda/core/handle/ChannelUpdateHandler.java b/src/main/java/net/dv8tion/jda/core/handle/ChannelUpdateHandler.java
index 15bda5f9e2..94ab403372 100644
--- a/src/main/java/net/dv8tion/jda/core/handle/ChannelUpdateHandler.java
+++ b/src/main/java/net/dv8tion/jda/core/handle/ChannelUpdateHandler.java
@@ -64,6 +64,7 @@ protected Long handleInternally(JSONObject content)
final int position = content.getInt("position");
final String name = content.getString("name");
final boolean nsfw = Helpers.optBoolean(content, "nsfw");
+ final int slowmode = Helpers.optInt(content, "rate_limit_per_user", 0);
JSONArray permOverwrites = content.getJSONArray("permission_overwrites");
switch (type)
{
@@ -85,6 +86,7 @@ protected Long handleInternally(JSONObject content)
final String oldTopic = textChannel.getTopic();
final int oldPosition = textChannel.getPositionRaw();
final boolean oldNsfw = textChannel.isNSFW();
+ final int oldSlowmode = textChannel.getSlowmode();
if (!Objects.equals(oldName, name))
{
textChannel.setName(name);
@@ -124,7 +126,16 @@ protected Long handleInternally(JSONObject content)
getJDA().getEventManager().handle(
new TextChannelUpdateNSFWEvent(
getJDA(), responseNumber,
- textChannel, nsfw));
+ textChannel, oldNsfw));
+ }
+
+ if (oldSlowmode != slowmode)
+ {
+ textChannel.setSlowmode(slowmode);
+ getJDA().getEventManager().handle(
+ new TextChannelUpdateSlowmodeEvent(
+ getJDA(), responseNumber,
+ textChannel, oldSlowmode));
}
applyPermissions(textChannel, content, permOverwrites, contained, changed);
diff --git a/src/main/java/net/dv8tion/jda/core/hooks/ListenerAdapter.java b/src/main/java/net/dv8tion/jda/core/hooks/ListenerAdapter.java
index e7d89d7c98..c20a4e7234 100644
--- a/src/main/java/net/dv8tion/jda/core/hooks/ListenerAdapter.java
+++ b/src/main/java/net/dv8tion/jda/core/hooks/ListenerAdapter.java
@@ -176,6 +176,7 @@ public void onTextChannelUpdatePosition(TextChannelUpdatePositionEvent event) {}
public void onTextChannelUpdatePermissions(TextChannelUpdatePermissionsEvent event) {}
public void onTextChannelUpdateNSFW(TextChannelUpdateNSFWEvent event) {}
public void onTextChannelUpdateParent(TextChannelUpdateParentEvent event) {}
+ public void onTextChannelUpdateSlowmode(TextChannelUpdateSlowmodeEvent event) {}
public void onTextChannelCreate(TextChannelCreateEvent event) {}
//VoiceChannel Events
@@ -464,6 +465,8 @@ else if (event instanceof TextChannelUpdateNSFWEvent)
onTextChannelUpdateNSFW((TextChannelUpdateNSFWEvent) event);
else if (event instanceof TextChannelUpdateParentEvent)
onTextChannelUpdateParent((TextChannelUpdateParentEvent) event);
+ else if (event instanceof TextChannelUpdateSlowmodeEvent)
+ onTextChannelUpdateSlowmode((TextChannelUpdateSlowmodeEvent) event);
else if (event instanceof TextChannelDeleteEvent)
onTextChannelDelete((TextChannelDeleteEvent) event);
diff --git a/src/main/java/net/dv8tion/jda/core/managers/ChannelManager.java b/src/main/java/net/dv8tion/jda/core/managers/ChannelManager.java
index 4c42fa1482..f1409fe839 100644
--- a/src/main/java/net/dv8tion/jda/core/managers/ChannelManager.java
+++ b/src/main/java/net/dv8tion/jda/core/managers/ChannelManager.java
@@ -55,21 +55,23 @@
public class ChannelManager extends ManagerBase
{
/** Used to reset the name field */
- public static final long NAME = 0x1;
+ public static final long NAME = 0x1;
/** Used to reset the parent field */
- public static final long PARENT = 0x2;
+ public static final long PARENT = 0x2;
/** Used to reset the topic field */
- public static final long TOPIC = 0x4;
+ public static final long TOPIC = 0x4;
/** Used to reset the position field */
- public static final long POSITION = 0x8;
+ public static final long POSITION = 0x8;
/** Used to reset the nsfw field */
- public static final long NSFW = 0x10;
+ public static final long NSFW = 0x10;
/** Used to reset the userlimit field */
- public static final long USERLIMIT = 0x20;
+ public static final long USERLIMIT = 0x20;
/** Used to reset the bitrate field */
- public static final long BITRATE = 0x40;
+ public static final long BITRATE = 0x40;
/** Used to reset the permission field */
public static final long PERMISSION = 0x80;
+ /** Used to reset the rate-limit per user field */
+ public static final long SLOWMODE = 0x100;
protected final UpstreamReference channel;
@@ -78,6 +80,7 @@ public class ChannelManager extends ManagerBase
protected String topic;
protected int position;
protected boolean nsfw;
+ protected int slowmode;
protected int userlimit;
protected int bitrate;
@@ -148,6 +151,7 @@ public Guild getGuild()
* {@link #TOPIC}
* {@link #POSITION}
* {@link #NSFW}
+ * {@link #SLOWMODE}
* {@link #USERLIMIT}
* {@link #BITRATE}
* {@link #PERMISSION}
@@ -587,6 +591,41 @@ public ChannelManager setNSFW(boolean nsfw)
return this;
}
+ /**
+ * Sets the slowmode of the selected {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}.
+ *
Provide {@code 0} to reset the slowmode of the {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}
+ *
+ * A channel slowmode must not be negative nor greater than {@code 120}!
+ *
This is only available to {@link net.dv8tion.jda.core.entities.TextChannel TextChannels}
+ *
+ *
Note that only {@link net.dv8tion.jda.core.AccountType#CLIENT CLIENT} type accounts are
+ * affected by slowmode, and that {@link net.dv8tion.jda.core.AccountType#BOT BOT} accounts
+ * are immune to the restrictions.
+ *
Having {@link net.dv8tion.jda.core.Permission#MESSAGE_MANAGE MESSAGE_MANAGE} or
+ * {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} permission also
+ * grants immunity to slowmode.
+ *
+ * @param slowmode
+ * The new slowmode for the selected {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}
+ *
+ * @throws IllegalStateException
+ * If the selected {@link net.dv8tion.jda.core.entities.Channel Channel}'s type is not {@link net.dv8tion.jda.core.entities.ChannelType#TEXT TEXT}
+ * @throws IllegalArgumentException
+ * If the provided slowmode is negative or greater than {@code 120}
+ *
+ * @return ChannelManager for chaining convenience
+ */
+ @CheckReturnValue
+ public ChannelManager setSlowmode(int slowmode)
+ {
+ if (getType() != ChannelType.TEXT)
+ throw new IllegalStateException("Can only set slowmode on text channels");
+ Checks.check(slowmode <= 120 && slowmode >= 0, "Slowmode per user must be between 0 and 120 (seconds)!");
+ this.slowmode = slowmode;
+ set |= SLOWMODE;
+ return this;
+ }
+
/**
* Sets the user-limit of the selected {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel}.
*
Provide {@code 0} to reset the user-limit of the {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel}
@@ -661,6 +700,8 @@ protected RequestBody finalizeData()
frame.put("topic", opt(topic));
if (shouldUpdate(NSFW))
frame.put("nsfw", nsfw);
+ if (shouldUpdate(SLOWMODE))
+ frame.put("rate_limit_per_user", slowmode);
if (shouldUpdate(USERLIMIT))
frame.put("user_limit", userlimit);
if (shouldUpdate(BITRATE))
diff --git a/src/main/java/net/dv8tion/jda/core/requests/restaction/ChannelAction.java b/src/main/java/net/dv8tion/jda/core/requests/restaction/ChannelAction.java
index 8abcdf7438..5583ab8c48 100644
--- a/src/main/java/net/dv8tion/jda/core/requests/restaction/ChannelAction.java
+++ b/src/main/java/net/dv8tion/jda/core/requests/restaction/ChannelAction.java
@@ -50,6 +50,7 @@ public class ChannelAction extends AuditableRestAction
// --text only--
protected String topic = null;
protected Boolean nsfw = null;
+ protected Integer slowmode = null;
// --voice only--
protected Integer bitrate = null;
@@ -170,6 +171,33 @@ public ChannelAction setNSFW(boolean nsfw)
return this;
}
+ /**
+ * Sets the slowmode value, which limits the amount of time that individual users must wait
+ * between sending messages in the new TextChannel. This is measured in seconds.
+ *
+ * Note that only {@link net.dv8tion.jda.core.AccountType#CLIENT CLIENT} type accounts are
+ * affected by slowmode, and that {@link net.dv8tion.jda.core.AccountType#BOT BOT} accounts
+ * are immune to the restrictions.
+ *
Having {@link net.dv8tion.jda.core.Permission#MESSAGE_MANAGE MESSAGE_MANAGE} or
+ * {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} permission also
+ * grants immunity to slowmode.
+ *
+ * @param slowmode
+ * The number of seconds required to wait between sending messages in the channel.
+ *
+ * @throws IllegalArgumentException
+ * If the {@code slowmode} is greater than 120, or less than 0
+ *
+ * @return The current ChannelAction, for chaining convenience
+ */
+ @CheckReturnValue
+ public ChannelAction setSlowmode(int slowmode)
+ {
+ Checks.check(slowmode <= 120 && slowmode >= 0, "Slowmode must be between 0 and 120 (seconds)!");
+ this.slowmode = slowmode;
+ return this;
+ }
+
/**
* Adds a new Role or Member {@link net.dv8tion.jda.core.entities.PermissionOverride PermissionOverride}
* for the new Channel.
@@ -343,6 +371,8 @@ protected RequestBody finalizeData()
object.put("topic", topic);
if (nsfw != null)
object.put("nsfw", nsfw);
+ if (slowmode != null)
+ object.put("rate_limit_per_user", slowmode);
}
if (type != ChannelType.CATEGORY && parent != null)
object.put("parent_id", parent.getId());