more monetizatios stuffz (#3002)
* uhhhhhhhhhhhhhhhhhhh yes * uhhhhhhhhhhhhhhhhhhh yes * ~~i love git~~
This commit is contained in:
@@ -1032,6 +1032,42 @@ namespace Discord.WebSocket
|
||||
internal readonly AsyncEvent<Func<Cacheable<SocketEntitlement, ulong>, Task>> _entitlementDeleted = new();
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a user subscribes to a SKU.
|
||||
/// </summary>
|
||||
public event Func<SocketSubscription, Task> SubscriptionCreated
|
||||
{
|
||||
add { _subscriptionCreated.Add(value); }
|
||||
remove { _subscriptionCreated.Remove(value); }
|
||||
}
|
||||
|
||||
internal readonly AsyncEvent<Func<SocketSubscription, Task>> _subscriptionCreated = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a subscription to a SKU is updated.
|
||||
/// </summary>
|
||||
public event Func<Cacheable<SocketSubscription, ulong>, SocketSubscription, Task> SubscriptionUpdated
|
||||
{
|
||||
add { _subscriptionUpdated.Add(value); }
|
||||
remove { _subscriptionUpdated.Remove(value); }
|
||||
}
|
||||
|
||||
internal readonly AsyncEvent<Func<Cacheable<SocketSubscription, ulong>, SocketSubscription, Task>> _subscriptionUpdated = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a user's subscription is deleted.
|
||||
/// </summary>
|
||||
public event Func<Cacheable<SocketSubscription, ulong>, Task> SubscriptionDeleted
|
||||
{
|
||||
add { _subscriptionDeleted.Add(value); }
|
||||
remove { _subscriptionDeleted.Remove(value); }
|
||||
}
|
||||
|
||||
internal readonly AsyncEvent<Func<Cacheable<SocketSubscription, ulong>, Task>> _subscriptionDeleted = new();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Discord.WebSocket
|
||||
private readonly ConcurrentHashSet<ulong> _groupChannels;
|
||||
private readonly ConcurrentDictionary<ulong, SocketApplicationCommand> _commands;
|
||||
private readonly ConcurrentDictionary<ulong, SocketEntitlement> _entitlements;
|
||||
private readonly ConcurrentDictionary<ulong, SocketSubscription> _subscriptions;
|
||||
|
||||
internal IReadOnlyCollection<SocketChannel> Channels => _channels.ToReadOnlyCollection();
|
||||
internal IReadOnlyCollection<SocketDMChannel> DMChannels => _dmChannels.ToReadOnlyCollection();
|
||||
@@ -26,6 +27,7 @@ namespace Discord.WebSocket
|
||||
internal IReadOnlyCollection<SocketGlobalUser> Users => _users.ToReadOnlyCollection();
|
||||
internal IReadOnlyCollection<SocketApplicationCommand> Commands => _commands.ToReadOnlyCollection();
|
||||
internal IReadOnlyCollection<SocketEntitlement> Entitlements => _entitlements.ToReadOnlyCollection();
|
||||
internal IReadOnlyCollection<SocketSubscription> Subscriptions => _subscriptions.ToReadOnlyCollection();
|
||||
|
||||
internal IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels =>
|
||||
_dmChannels.Select(x => x.Value as ISocketPrivateChannel).Concat(
|
||||
@@ -43,6 +45,7 @@ namespace Discord.WebSocket
|
||||
_groupChannels = new ConcurrentHashSet<ulong>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(10 * CollectionMultiplier));
|
||||
_commands = new ConcurrentDictionary<ulong, SocketApplicationCommand>();
|
||||
_entitlements = new();
|
||||
_subscriptions = new();
|
||||
}
|
||||
|
||||
internal SocketChannel GetChannel(ulong id)
|
||||
@@ -197,5 +200,29 @@ namespace Discord.WebSocket
|
||||
return entitlement;
|
||||
return null;
|
||||
}
|
||||
|
||||
internal void AddSubscription(ulong id, SocketSubscription subscription)
|
||||
{
|
||||
_subscriptions.TryAdd(id, subscription);
|
||||
}
|
||||
|
||||
internal SocketSubscription GetSubscription(ulong id)
|
||||
{
|
||||
if (_subscriptions.TryGetValue(id, out var subscription))
|
||||
return subscription;
|
||||
return null;
|
||||
}
|
||||
|
||||
internal SocketSubscription GetOrAddSubscription(ulong id, Func<ulong, SocketSubscription> subscriptionFactory)
|
||||
{
|
||||
return _subscriptions.GetOrAdd(id, subscriptionFactory);
|
||||
}
|
||||
|
||||
internal SocketSubscription RemoveSubscription(ulong id)
|
||||
{
|
||||
if (_subscriptions.TryRemove(id, out var subscription))
|
||||
return subscription;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2531
src/Discord.Net.WebSocket/DiscordSocketClient.EventHandling.cs
Normal file
2531
src/Discord.Net.WebSocket/DiscordSocketClient.EventHandling.cs
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace Discord.WebSocket;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an application subscription.
|
||||
/// </summary>
|
||||
public class SocketSubscription : SocketEntity<ulong>, ISubscription
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong UserId { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<ulong> SKUIds { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<ulong> EntitlementIds { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CurrentPeriodStart { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CurrentPeriodEnd { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public SubscriptionStatus Status { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset? CanceledAt { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Country { get; private set; }
|
||||
|
||||
internal SocketSubscription(DiscordSocketClient discord, ulong id) : base(discord, id)
|
||||
{
|
||||
}
|
||||
|
||||
internal static SocketSubscription Create(DiscordSocketClient discord, API.Subscription model)
|
||||
{
|
||||
var s = new SocketSubscription(discord, model.Id);
|
||||
s.Update(model);
|
||||
return s;
|
||||
}
|
||||
|
||||
internal void Update(API.Subscription model)
|
||||
{
|
||||
UserId = model.UserId;
|
||||
SKUIds = model.SKUIds.ToImmutableArray();
|
||||
EntitlementIds = model.EntitlementIds.ToImmutableArray();
|
||||
CurrentPeriodStart = model.CurrentPeriodStart;
|
||||
CurrentPeriodEnd = model.CurrentPeriodEnd;
|
||||
Status = model.Status;
|
||||
CanceledAt = model.CanceledAt;
|
||||
Country = model.Country;
|
||||
}
|
||||
|
||||
internal SocketSubscription Clone()
|
||||
=> MemberwiseClone() as SocketSubscription;
|
||||
}
|
||||
Reference in New Issue
Block a user