[Feature] Guild incident actions (#2783)
* initial commit * <see langword="null"/> notes
This commit is contained in:
16
src/Discord.Net.Core/Entities/Guilds/GuildIncidentsData.cs
Normal file
16
src/Discord.Net.Core/Entities/Guilds/GuildIncidentsData.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Discord;
|
||||||
|
|
||||||
|
public class GuildIncidentsData
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the time when invites get enabled again. <see langword="null"/> if invites are not disabled.
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset? InvitesDisabledUntil { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the time when DMs get enabled again. <see langword="null"/> if DMs are not disabled.
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset? DmsDisabledUntil { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Discord;
|
||||||
|
|
||||||
|
public class GuildIncidentsDataProperties
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or set when invites get enabled again, up to 24 hours in the future.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Set to <see langword="null"/> to enable invites.
|
||||||
|
/// </remarks>
|
||||||
|
public Optional<DateTimeOffset?> InvitesDisabledUntil { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or set when dms get enabled again, up to 24 hours in the future.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Set to <see langword="null"/> to enable dms.
|
||||||
|
/// </remarks>
|
||||||
|
public Optional<DateTimeOffset?> DmsDisabledUntil { get; set; }
|
||||||
|
}
|
||||||
@@ -376,6 +376,11 @@ namespace Discord
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
ulong MaxUploadLimit { get; }
|
ulong MaxUploadLimit { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the incidents data for this guild.
|
||||||
|
/// </summary>
|
||||||
|
GuildIncidentsData IncidentsData { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Modifies this guild.
|
/// Modifies this guild.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1325,5 +1330,13 @@ namespace Discord
|
|||||||
/// A task that represents the asynchronous creation operation. The task result contains the modified <see cref="IGuildOnboarding"/>.
|
/// A task that represents the asynchronous creation operation. The task result contains the modified <see cref="IGuildOnboarding"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
Task<IGuildOnboarding> ModifyOnboardingAsync(Action<GuildOnboardingProperties> props, RequestOptions options = null);
|
Task<IGuildOnboarding> ModifyOnboardingAsync(Action<GuildOnboardingProperties> props, RequestOptions options = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modifies the incident actions of the guild.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// A task that represents the asynchronous creation operation. The task result contains the modified <see cref="IncidentsData"/>.
|
||||||
|
/// </returns>
|
||||||
|
Task<GuildIncidentsData> ModifyIncidentActionsAsync(Action<GuildIncidentsDataProperties> props, RequestOptions options = null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,5 +91,8 @@ namespace Discord.API
|
|||||||
|
|
||||||
[JsonProperty("max_stage_video_channel_users")]
|
[JsonProperty("max_stage_video_channel_users")]
|
||||||
public Optional<int> MaxStageVideoChannelUsers { get; set; }
|
public Optional<int> MaxStageVideoChannelUsers { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("incidents_data")]
|
||||||
|
public GuildIncidentsData IncidentsData { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/Discord.Net.Rest/API/Common/GuildIncidentsData.cs
Normal file
13
src/Discord.Net.Rest/API/Common/GuildIncidentsData.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Discord.API;
|
||||||
|
|
||||||
|
internal class GuildIncidentsData
|
||||||
|
{
|
||||||
|
[JsonProperty("invites_disabled_until")]
|
||||||
|
public DateTimeOffset? InvitesDisabledUntil { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("dms_disabled_until")]
|
||||||
|
public DateTimeOffset? DmsDisabledUntil { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Discord.API.Rest;
|
||||||
|
|
||||||
|
internal class ModifyGuildIncidentsDataParams
|
||||||
|
{
|
||||||
|
[JsonProperty("invites_disabled_until")]
|
||||||
|
public Optional<DateTimeOffset?> InvitesDisabledUntil { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("dms_disabled_until")]
|
||||||
|
public Optional<DateTimeOffset?> DmsDisabledUntil { get; set; }
|
||||||
|
}
|
||||||
@@ -1651,6 +1651,16 @@ namespace Discord.API
|
|||||||
var ids = new BucketIds(guildId: guildId);
|
var ids = new BucketIds(guildId: guildId);
|
||||||
return await SendAsync<GetGuildPruneCountResponse>("GET", () => $"guilds/{guildId}/prune?days={args.Days}{endpointRoleIds}", ids, options: options).ConfigureAwait(false);
|
return await SendAsync<GetGuildPruneCountResponse>("GET", () => $"guilds/{guildId}/prune?days={args.Days}{endpointRoleIds}", ids, options: options).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<GuildIncidentsData> ModifyGuildIncidentActionsAsync(ulong guildId, ModifyGuildIncidentsDataParams args, RequestOptions options = null)
|
||||||
|
{
|
||||||
|
Preconditions.NotEqual(guildId, 0, nameof(guildId));
|
||||||
|
|
||||||
|
var ids = new BucketIds(guildId: guildId);
|
||||||
|
|
||||||
|
return await SendJsonAsync<GuildIncidentsData>("PUT", () => $"guilds/{guildId}/incident-actions", args, ids, options: options).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Guild Bans
|
#region Guild Bans
|
||||||
|
|||||||
@@ -147,6 +147,24 @@ namespace Discord.Rest
|
|||||||
var mebibyte = Math.Pow(2, 20);
|
var mebibyte = Math.Pow(2, 20);
|
||||||
return (ulong)(tierFactor * mebibyte);
|
return (ulong)(tierFactor * mebibyte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<GuildIncidentsData> ModifyGuildIncidentActionsAsync(IGuild guild, BaseDiscordClient client, Action<GuildIncidentsDataProperties> func, RequestOptions options = null)
|
||||||
|
{
|
||||||
|
var props = new GuildIncidentsDataProperties();
|
||||||
|
func(props);
|
||||||
|
|
||||||
|
var args = props.DmsDisabledUntil.IsSpecified || props.InvitesDisabledUntil.IsSpecified
|
||||||
|
? new ModifyGuildIncidentsDataParams { DmsDisabledUntil = props.DmsDisabledUntil, InvitesDisabledUntil = props.InvitesDisabledUntil }
|
||||||
|
: null;
|
||||||
|
|
||||||
|
var model = await client.ApiClient.ModifyGuildIncidentActionsAsync(guild.Id, args, options);
|
||||||
|
|
||||||
|
return new GuildIncidentsData
|
||||||
|
{
|
||||||
|
DmsDisabledUntil = model.DmsDisabledUntil,
|
||||||
|
InvitesDisabledUntil = model.InvitesDisabledUntil
|
||||||
|
};
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Bans
|
#region Bans
|
||||||
|
|||||||
@@ -115,6 +115,9 @@ namespace Discord.Rest
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public GuildFeatures Features { get; private set; }
|
public GuildFeatures Features { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public GuildIncidentsData IncidentsData { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||||
|
|
||||||
@@ -181,6 +184,10 @@ namespace Discord.Rest
|
|||||||
Description = model.Description;
|
Description = model.Description;
|
||||||
PremiumSubscriptionCount = model.PremiumSubscriptionCount.GetValueOrDefault();
|
PremiumSubscriptionCount = model.PremiumSubscriptionCount.GetValueOrDefault();
|
||||||
NsfwLevel = model.NsfwLevel;
|
NsfwLevel = model.NsfwLevel;
|
||||||
|
IncidentsData = model.IncidentsData is not null
|
||||||
|
? new GuildIncidentsData { DmsDisabledUntil = model.IncidentsData.DmsDisabledUntil, InvitesDisabledUntil = model.IncidentsData.InvitesDisabledUntil }
|
||||||
|
: new GuildIncidentsData();
|
||||||
|
|
||||||
if (model.MaxPresences.IsSpecified)
|
if (model.MaxPresences.IsSpecified)
|
||||||
MaxPresences = model.MaxPresences.Value ?? 25000;
|
MaxPresences = model.MaxPresences.Value ?? 25000;
|
||||||
if (model.MaxMembers.IsSpecified)
|
if (model.MaxMembers.IsSpecified)
|
||||||
@@ -303,6 +310,15 @@ namespace Discord.Rest
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task LeaveAsync(RequestOptions options = null)
|
public Task LeaveAsync(RequestOptions options = null)
|
||||||
=> GuildHelper.LeaveAsync(this, Discord, options);
|
=> GuildHelper.LeaveAsync(this, Discord, options);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<GuildIncidentsData> ModifyIncidentActionsAsync(Action<GuildIncidentsDataProperties> props, RequestOptions options = null)
|
||||||
|
{
|
||||||
|
IncidentsData = await GuildHelper.ModifyGuildIncidentActionsAsync(this, Discord, props, options);
|
||||||
|
|
||||||
|
return IncidentsData;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Interactions
|
#region Interactions
|
||||||
|
|||||||
@@ -143,6 +143,8 @@ namespace Discord.WebSocket
|
|||||||
public bool IsBoostProgressBarEnabled { get; private set; }
|
public bool IsBoostProgressBarEnabled { get; private set; }
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public GuildFeatures Features { get; private set; }
|
public GuildFeatures Features { get; private set; }
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public GuildIncidentsData IncidentsData { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||||
@@ -560,6 +562,9 @@ namespace Discord.WebSocket
|
|||||||
PreferredCulture = PreferredLocale == null ? null : new CultureInfo(PreferredLocale);
|
PreferredCulture = PreferredLocale == null ? null : new CultureInfo(PreferredLocale);
|
||||||
if (model.IsBoostProgressBarEnabled.IsSpecified)
|
if (model.IsBoostProgressBarEnabled.IsSpecified)
|
||||||
IsBoostProgressBarEnabled = model.IsBoostProgressBarEnabled.Value;
|
IsBoostProgressBarEnabled = model.IsBoostProgressBarEnabled.Value;
|
||||||
|
IncidentsData = model.IncidentsData is not null
|
||||||
|
? new GuildIncidentsData { DmsDisabledUntil = model.IncidentsData.DmsDisabledUntil, InvitesDisabledUntil = model.IncidentsData.InvitesDisabledUntil }
|
||||||
|
: new GuildIncidentsData();
|
||||||
if (model.Emojis != null)
|
if (model.Emojis != null)
|
||||||
{
|
{
|
||||||
var emojis = ImmutableArray.CreateBuilder<GuildEmote>(model.Emojis.Length);
|
var emojis = ImmutableArray.CreateBuilder<GuildEmote>(model.Emojis.Length);
|
||||||
@@ -656,6 +661,11 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task LeaveAsync(RequestOptions options = null)
|
public Task LeaveAsync(RequestOptions options = null)
|
||||||
=> GuildHelper.LeaveAsync(this, Discord, options);
|
=> GuildHelper.LeaveAsync(this, Discord, options);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task<GuildIncidentsData> ModifyIncidentActionsAsync(Action<GuildIncidentsDataProperties> props, RequestOptions options = null)
|
||||||
|
=> GuildHelper.ModifyGuildIncidentActionsAsync(this, Discord, props, options);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Bans
|
#region Bans
|
||||||
|
|||||||
Reference in New Issue
Block a user