Browse Source

api: add slow mode

This adds the following property to ITextChannel
- SlowMode (int)

The SlowMode field defines the time in seconds users must wait between
sending messages; if zero, slow-mode is disabled.

Bots are not affected by slow-mode, and as such, no changes need to be
made to the REST client's internal ratelimiting. This is strictly a
read/write cosmetic property for bots.
tags/2.0
Christopher F 6 years ago
parent
commit
97d17cfdda
8 changed files with 30 additions and 4 deletions
  1. +3
    -0
      src/Discord.Net.Core/Entities/Channels/ITextChannel.cs
  2. +13
    -1
      src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs
  3. +3
    -1
      src/Discord.Net.Rest/API/Common/Channel.cs
  4. +3
    -1
      src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs
  5. +2
    -0
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  6. +2
    -1
      src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
  7. +2
    -0
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
  8. +2
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs

+ 3
- 0
src/Discord.Net.Core/Entities/Channels/ITextChannel.cs View File

@@ -13,6 +13,9 @@ namespace Discord
/// <summary> Gets the current topic for this text channel. </summary>
string Topic { get; }

///<summary> Gets the current slow-mode delay for this channel. 0 if disabled. </summary>
int SlowMode { get; }

/// <summary> Bulk deletes multiple messages. </summary>
Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null);
/// <summary> Bulk deletes multiple messages. </summary>


+ 13
- 1
src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs View File

@@ -1,4 +1,6 @@
namespace Discord
using System;

namespace Discord
{
/// <inheritdoc />
public class TextChannelProperties : GuildChannelProperties
@@ -11,5 +13,15 @@
/// Should this channel be flagged as NSFW?
/// </summary>
public Optional<bool> IsNsfw { get; set; }
/// <summary>
/// What the slow-mode ratelimit for this channel should be set to; 0 will disable slow-mode.
/// </summary>
/// <remarks>
/// This value must fall within [0, 120]
///
/// Users with <see cref="ChannelPermission.ManageMessages"/> will be exempt from slow-mode.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">Throws ArgummentOutOfRange if the value does not fall within [0, 120]</exception>
public Optional<int> SlowMode { get; set; }
}
}

+ 3
- 1
src/Discord.Net.Rest/API/Common/Channel.cs View File

@@ -1,4 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json;
using System;

@@ -33,6 +33,8 @@ namespace Discord.API
public Optional<DateTimeOffset?> LastPinTimestamp { get; set; }
[JsonProperty("nsfw")]
public Optional<bool> Nsfw { get; set; }
[JsonProperty("rate_limit_per_user")]
public Optional<int> SlowMode { get; set; }

//VoiceChannel
[JsonProperty("bitrate")]


+ 3
- 1
src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs View File

@@ -1,4 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json;

namespace Discord.API.Rest
@@ -10,5 +10,7 @@ namespace Discord.API.Rest
public Optional<string> Topic { get; set; }
[JsonProperty("nsfw")]
public Optional<bool> IsNsfw { get; set; }
[JsonProperty("rate_limit_per_user")]
public Optional<int> SlowMode { get; set; }
}
}

+ 2
- 0
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -356,6 +356,8 @@ namespace Discord.API
Preconditions.NotNull(args, nameof(args));
Preconditions.AtLeast(args.Position, 0, nameof(args.Position));
Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name));
Preconditions.AtLeast(args.SlowMode, 0, nameof(args.SlowMode));
Preconditions.AtMost(args.SlowMode, 120, nameof(args.SlowMode));
options = RequestOptions.CreateOrClone(options);

var ids = new BucketIds(channelId: channelId);


+ 2
- 1
src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs View File

@@ -45,7 +45,8 @@ namespace Discord.Rest
Position = args.Position,
CategoryId = args.CategoryId,
Topic = args.Topic,
IsNsfw = args.IsNsfw
IsNsfw = args.IsNsfw,
SlowMode = args.SlowMode,
};
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
}


+ 2
- 0
src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs View File

@@ -12,6 +12,7 @@ namespace Discord.Rest
public class RestTextChannel : RestGuildChannel, IRestMessageChannel, ITextChannel
{
public string Topic { get; private set; }
public int SlowMode { get; private set; }
public ulong? CategoryId { get; private set; }

public string Mention => MentionUtils.MentionChannel(Id);
@@ -34,6 +35,7 @@ namespace Discord.Rest
base.Update(model);
CategoryId = model.CategoryId;
Topic = model.Topic.Value;
SlowMode = model.SlowMode.Value;
_nsfw = model.Nsfw.GetValueOrDefault();
}



+ 2
- 0
src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs View File

@@ -16,6 +16,7 @@ namespace Discord.WebSocket
private readonly MessageCache _messages;

public string Topic { get; private set; }
public int SlowMode { get; private set; }
public ulong? CategoryId { get; private set; }
public ICategoryChannel Category
=> CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null;
@@ -47,6 +48,7 @@ namespace Discord.WebSocket
base.Update(state, model);
CategoryId = model.CategoryId;
Topic = model.Topic.Value;
SlowMode = model.SlowMode.GetValueOrDefault(); // some guilds haven't been patched to include this yet?
_nsfw = model.Nsfw.GetValueOrDefault();
}



Loading…
Cancel
Save