Browse Source

Change default sticker behavior and add AlwaysResolveSticker to the config

pull/1923/head
quin lynch 3 years ago
parent
commit
a094be5b71
4 changed files with 36 additions and 3 deletions
  1. +1
    -1
      src/Discord.Net.WebSocket/DiscordShardedClient.cs
  2. +6
    -2
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  3. +23
    -0
      src/Discord.Net.WebSocket/DiscordSocketConfig.cs
  4. +6
    -0
      src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs

+ 1
- 1
src/Discord.Net.WebSocket/DiscordShardedClient.cs View File

@@ -164,7 +164,7 @@ namespace Discord.WebSocket
for (int i = 0; i < _shards.Length; i++)
await _shards[i].LoginAsync(tokenType, token);

if(_defaultStickers.Length == 0)
if(_defaultStickers.Length == 0 && _baseConfig.AlwaysDownloadDefaultStickers)
await DownloadDefaultStickersAsync().ConfigureAwait(false);

}


+ 6
- 2
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -65,7 +65,7 @@ namespace Discord.WebSocket
private Optional<IActivity> _activity;
#endregion

//From DiscordSocketConfig
// From DiscordSocketConfig
internal int TotalShards { get; private set; }
internal int MessageCacheSize { get; private set; }
internal int LargeThreshold { get; private set; }
@@ -74,6 +74,8 @@ namespace Discord.WebSocket
internal WebSocketProvider WebSocketProvider { get; private set; }
internal bool AlwaysDownloadUsers { get; private set; }
internal int? HandlerTimeout { get; private set; }
internal bool AlwaysDownloadDefaultStickers { get; private set; }
internal bool AlwaysResolveStickers { get; private set; }
internal new DiscordSocketApiClient ApiClient => base.ApiClient;
/// <inheritdoc />
public override IReadOnlyCollection<SocketGuild> Guilds => State.Guilds;
@@ -143,6 +145,8 @@ namespace Discord.WebSocket
UdpSocketProvider = config.UdpSocketProvider;
WebSocketProvider = config.WebSocketProvider;
AlwaysDownloadUsers = config.AlwaysDownloadUsers;
AlwaysDownloadDefaultStickers = config.AlwaysDownloadDefaultStickers;
AlwaysResolveStickers = config.AlwaysResolveStickers;
HandlerTimeout = config.HandlerTimeout;
State = new ClientState(0, 0);
Rest = new DiscordSocketRestClient(config, ApiClient);
@@ -209,7 +213,7 @@ namespace Discord.WebSocket

internal override async Task OnLoginAsync(TokenType tokenType, string token)
{
if(_shardedClient == null && _defaultStickers.Length == 0)
if (_shardedClient == null && _defaultStickers.Length == 0 && AlwaysDownloadDefaultStickers)
{
var models = await ApiClient.ListNitroStickerPacksAsync().ConfigureAwait(false);



+ 23
- 0
src/Discord.Net.WebSocket/DiscordSocketConfig.cs View File

@@ -49,8 +49,31 @@ namespace Discord.WebSocket
/// <summary>
/// Gets or sets the total number of shards for this application.
/// </summary>
/// <remarks>
/// If this is left <see langword="null"/> in a sharded client the bot will get the recommended shard
/// count from discord and use that.
/// </remarks>
public int? TotalShards { get; set; } = null;

/// <summary>
/// Gets or sets whether or not the client should download the default stickers on startup.
/// </summary>
/// <remarks>
/// When this is set to <see langword="false"/> default stickers arn't present and cannot be resolved by the client.
/// This will make all default stickers have the type of <see cref="SocketUnknownSticker"/>.
/// </remarks>
public bool AlwaysDownloadDefaultStickers { get; set; } = false;

/// <summary>
/// Gets or sets whether or not the client should automatically resolve the stickers sent on a message.
/// </summary>
/// <remarks>
/// Note if a sticker isn't cached the client will preform a rest request to resolve it. This
/// may be very rest heavy depending on your bots size, it isn't recommended to use this with large scale bots as you
/// can get ratelimited easily.
/// </remarks>
public bool AlwaysResolveStickers { get; set; } = false;

/// <summary>
/// Gets or sets the number of messages per channel that should be kept in cache. Setting this to zero
/// disables the message cache entirely.


+ 6
- 0
src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs View File

@@ -154,6 +154,12 @@ namespace Discord.WebSocket
if (sticker == null)
sticker = Discord.GetSticker(stickerItem.Id);

// if they want to auto resolve
if (Discord.AlwaysResolveStickers)
{
sticker = Task.Run(async () => await Discord.GetStickerAsync(stickerItem.Id).ConfigureAwait(false)).GetAwaiter().GetResult();
}

// if its still null, create an unknown
if (sticker == null)
sticker = SocketUnknownSticker.Create(Discord, stickerItem);


Loading…
Cancel
Save