Guilduser timeouts and MODERATE_MEMBERS permission (#2003)

Co-Authored-By: Armano den Boef <68127614+Rozen4334@users.noreply.github.com>
This commit is contained in:
Quin Lynch
2021-12-24 15:57:41 -04:00
committed by GitHub
parent 82bb3e403f
commit 144741e7c4
13 changed files with 157 additions and 11 deletions

View File

@@ -20,6 +20,7 @@ namespace Discord.WebSocket
{
#region SocketGuildUser
private long? _premiumSinceTicks;
private long? _timedOutTicks;
private long? _joinedAtTicks;
private ImmutableArray<ulong> _roleIds;
@@ -89,6 +90,17 @@ namespace Discord.WebSocket
public AudioInStream AudioStream => Guild.GetAudioStream(Id);
/// <inheritdoc />
public DateTimeOffset? PremiumSince => DateTimeUtils.FromTicks(_premiumSinceTicks);
/// <inheritdoc />
public DateTimeOffset? TimedOutUntil
{
get
{
if (!_timedOutTicks.HasValue || _timedOutTicks.Value < 0)
return null;
else
return DateTimeUtils.FromTicks(_timedOutTicks);
}
}
/// <summary>
/// Returns the position of the user within the role hierarchy.
@@ -157,6 +169,8 @@ namespace Discord.WebSocket
UpdateRoles(model.Roles.Value);
if (model.PremiumSince.IsSpecified)
_premiumSinceTicks = model.PremiumSince.Value?.UtcTicks;
if (model.TimedOutUntil.IsSpecified)
_timedOutTicks = model.TimedOutUntil.Value?.UtcTicks;
if (model.Pending.IsSpecified)
IsPending = model.Pending.Value;
}
@@ -221,7 +235,12 @@ namespace Discord.WebSocket
/// <inheritdoc />
public Task RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)
=> RemoveRolesAsync(roles.Select(x => x.Id));
/// <inheritdoc />
public Task SetTimeOutAsync(TimeSpan span, RequestOptions options = null)
=> UserHelper.SetTimeoutAsync(this, Discord, span, options);
/// <inheritdoc />
public Task RemoveTimeOutAsync(RequestOptions options = null)
=> UserHelper.RemoveTimeOutAsync(this, Discord, options);
/// <inheritdoc />
public ChannelPermissions GetPermissions(IGuildChannel channel)
=> new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, GuildPermissions.RawValue));

View File

@@ -39,6 +39,10 @@ namespace Discord.WebSocket
public DateTimeOffset? PremiumSince
=> GuildUser.PremiumSince;
/// <inheritdoc/>
public DateTimeOffset? TimedOutUntil
=> GuildUser.TimedOutUntil;
/// <inheritdoc/>
public bool? IsPending
=> GuildUser.IsPending;
@@ -171,7 +175,11 @@ namespace Discord.WebSocket
/// <inheritdoc/>
public Task RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null) => GuildUser.RemoveRolesAsync(roles, options);
/// <inheritdoc/>
public Task SetTimeOutAsync(TimeSpan span, RequestOptions options = null) => GuildUser.SetTimeOutAsync(span, options);
/// <inheritdoc/>
public Task RemoveTimeOutAsync(RequestOptions options = null) => GuildUser.RemoveTimeOutAsync(options);
/// <inheritdoc/>
GuildPermissions IGuildUser.GuildPermissions => GuildUser.GuildPermissions;

View File

@@ -72,6 +72,8 @@ namespace Discord.WebSocket
/// <inheritdoc />
DateTimeOffset? IGuildUser.PremiumSince => null;
/// <inheritdoc />
DateTimeOffset? IGuildUser.TimedOutUntil => null;
/// <inheritdoc />
bool? IGuildUser.IsPending => null;
/// <inheritdoc />
int IGuildUser.Hierarchy => 0;
@@ -129,6 +131,14 @@ namespace Discord.WebSocket
/// <exception cref="NotSupportedException">Roles are not supported on webhook users.</exception>
Task IGuildUser.RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Timeouts are not supported on webhook users.</exception>
Task IGuildUser.SetTimeOutAsync(TimeSpan span, RequestOptions options) =>
throw new NotSupportedException("Timeouts are not supported on webhook users.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Timeouts are not supported on webhook users.</exception>
Task IGuildUser.RemoveTimeOutAsync(RequestOptions options) =>
throw new NotSupportedException("Timeouts are not supported on webhook users.");
#endregion
#region IVoiceState