Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various small API updates #107

Merged
merged 8 commits into from
Dec 21, 2023
2 changes: 1 addition & 1 deletion src/Disqord.Core/Discord/Cdn/Discord.Cdn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static string GetDefaultAvatarUrl(string discriminator)

public static string GetDefaultAvatarUrl(Snowflake userId)
{
return GetDefaultAvatarUrl((DefaultAvatarColor) ((userId.RawValue >> 22) % 5));
return GetDefaultAvatarUrl((DefaultAvatarColor) ((userId.RawValue >> 22) % 6));
}

public static string GetDefaultAvatarUrl(DefaultAvatarColor color)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public interface IApplicationTeamMember : IUser, IJsonUpdatable<TeamMemberJsonMo
/// Gets the permissions of this member.
/// </summary>
IReadOnlyList<string> Permissions { get; }
}

/// <summary>
/// Gets the role of this member.
/// </summary>
TeamMemberRole Role { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ public interface IGuildAuditLogChanges
AuditLogChange<Snowflake?> WidgetChannelId { get; }

AuditLogChange<Snowflake?> SystemChannelId { get; }

AuditLogChange<Snowflake?> SafetyAlertsChannelId { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ public interface IAutoModerationTriggerMetadata : IEntity, IJsonUpdatable<AutoMo
/// Used by the <see cref="AutoModerationRuleTrigger.MentionSpam"/> trigger type.
/// </remarks>
int? MentionLimit { get; }

/// <summary>
/// Gets whether mention raids should be automatically detected.
/// </summary>
/// <remarks>
/// Used by the <see cref="AutoModerationRuleTrigger.MentionSpam"/> trigger type.
/// </remarks>
bool IsMentionRaidProtectionEnabled { get; }
}
5 changes: 5 additions & 0 deletions src/Disqord.Core/Entities/Core/Guild/IGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,9 @@ public interface IGuild : ISnowflakeEntity, INamableEntity, IJsonUpdatable<Guild
/// Gets whether this guild has the boost progress bar enabled.
/// </summary>
bool IsBoostProgressBarEnabled { get; }

/// <summary>
/// Gets the safety alerts channel ID of this guild.
/// </summary>
Snowflake? SafetyAlertsChannelId { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,10 @@ public static LocalAutoModerationTriggerMetadata WithMentionLimit(this LocalAuto
metadata.MentionLimit = mentionLimit;
return metadata;
}

public static LocalAutoModerationTriggerMetadata WithIsMentionRaidProtectionEnabled(this LocalAutoModerationTriggerMetadata metadata, bool isEnabled = true)
{
metadata.IsMentionRaidProtectionEnabled = isEnabled;
return metadata;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class LocalAutoModerationTriggerMetadata : ILocalConstruct<LocalAutoModer

public Optional<int> MentionLimit { get; set; }

public Optional<bool> IsMentionRaidProtectionEnabled { get; set; }

/// <summary>
/// Instantiates a new <see cref="LocalAutoModerationTriggerMetadata"/>.
/// </summary>
Expand All @@ -33,6 +35,7 @@ protected LocalAutoModerationTriggerMetadata(LocalAutoModerationTriggerMetadata
Presets = other.Presets.Clone();
AllowedSubstrings = other.AllowedSubstrings.Clone();
MentionLimit = other.MentionLimit;
IsMentionRaidProtectionEnabled = other.IsMentionRaidProtectionEnabled;
}

/// <inheritdoc/>
Expand All @@ -50,7 +53,8 @@ public AutoModerationTriggerMetadataJsonModel ToModel()
RegexPatterns = RegexPatterns.ToArray(),
Presets = Presets.ToArray(),
AllowList = AllowedSubstrings.ToArray(),
MentionTotalLimit = MentionLimit
MentionTotalLimit = MentionLimit,
MentionRaidProtectionEnabled = IsMentionRaidProtectionEnabled
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class TransientApplicationTeamMember : TransientUser, IApplicationTeamMem
/// <inheritdoc/>
public IReadOnlyList<string> Permissions => Model.Permissions;

/// <inheritdoc/>
public TeamMemberRole Role => Model.Role;

/// <inheritdoc/>
public new TeamMemberJsonModel Model { get; }

Expand All @@ -23,4 +26,4 @@ public TransientApplicationTeamMember(IClient client, TeamMemberJsonModel model)
{
Model = model;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public class TransientGuildAuditLogChanges : IGuildAuditLogChanges
/// <inheritdoc/>
public AuditLogChange<Snowflake?> SystemChannelId { get; }

/// <inheritdoc/>
public AuditLogChange<Snowflake?> SafetyAlertsChannelId { get; }

public TransientGuildAuditLogChanges(IClient client, AuditLogJsonModel? auditLogJsonModel, AuditLogEntryJsonModel model)
{
for (var i = 0; i < model.Changes.Value.Length; i++)
Expand Down Expand Up @@ -200,6 +203,11 @@ public TransientGuildAuditLogChanges(IClient client, AuditLogJsonModel? auditLog
SystemChannelId = AuditLogChange<Snowflake?>.Convert(change);
break;
}
case "safety_alerts_channel_id":
{
SafetyAlertsChannelId = AuditLogChange<Snowflake?>.Convert(change);
break;
}
default:
{
client.Logger.LogDebug("Unknown key {0} for {1}", change.Key, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public IReadOnlyList<string> AllowedSubstrings
/// <inheritdoc/>
public int? MentionLimit => Model.MentionTotalLimit.GetValueOrNullable();

/// <inheritdoc/>
public bool IsMentionRaidProtectionEnabled => Model.MentionRaidProtectionEnabled.GetValueOrDefault();

public TransientAutoModerationTriggerMetadata(AutoModerationTriggerMetadataJsonModel model)
: base(model)
{ }
Expand Down
3 changes: 3 additions & 0 deletions src/Disqord.Core/Entities/Transient/Guild/TransientGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public IReadOnlyDictionary<Snowflake, IGuildSticker> Stickers
/// <inheritdoc/>
public bool IsBoostProgressBarEnabled => Model.PremiumProgressBarEnabled;

/// <inheritdoc/>
public Snowflake? SafetyAlertsChannelId => Model.SafetyAlertsChannelId;

public TransientGuild(IClient client, GuildJsonModel model)
: base(client, model)
{ }
Expand Down
16 changes: 13 additions & 3 deletions src/Disqord.Core/Enums/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public enum Permissions : ulong
ManageWebhooks = 1ul << 29,

/// <summary>
/// Allows management of emojis, stickers, soundboard sounds etc.
/// Allows management of emojis, stickers, soundboard sounds, etc.
/// </summary>
ManageExpressions = 1ul << 30,

Expand Down Expand Up @@ -241,6 +241,16 @@ public enum Permissions : ulong
/// </summary>
UseSoundboard = 1ul << 42,

/// <summary>
/// Allows creating emojis, stickers, soundboard sounds, etc.
/// </summary>
CreateExpressions = 1ul << 43,

/// <summary>
/// Allows creating guild events.
/// </summary>
CreateEvents = 1ul << 44,

/// <summary>
/// Allows using sounds from other guilds.
/// </summary>
Expand All @@ -267,6 +277,6 @@ public enum Permissions : ulong
| ManageRoles | ManageWebhooks | ManageExpressions | UseApplicationCommands
| RequestToSpeak | ManageEvents | ManageThreads | CreatePublicThreads
| CreatePrivateThreads | UseExternalStickers | SendMessagesInThreads | StartActivities
| ModerateMembers | ViewCreatorMonetizationAnalytics | UseSoundboard | UseExternalSounds
| SendVoiceMessages
| ModerateMembers | ViewCreatorMonetizationAnalytics | UseSoundboard | CreateExpressions
| CreateEvents | UseExternalSounds | SendVoiceMessages
}
29 changes: 29 additions & 0 deletions src/Disqord.Core/Enums/TeamMemberRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Runtime.Serialization;
using Disqord.Serialization.Json;

namespace Disqord;

/// <summary>
/// Represents the role of team member in an application team.
/// </summary>
[StringEnum]
public enum TeamMemberRole
{
/// <summary>
/// Represents a team administrator.
/// </summary>
[EnumMember(Value = "admin")]
Administrator,

/// <summary>
/// Represents a team developer.
/// </summary>
[EnumMember(Value = "developer")]
Developer,

/// <summary>
/// Represents a team member with read-only access.
/// </summary>
[EnumMember(Value = "read_only")]
ReadOnly
}
5 changes: 4 additions & 1 deletion src/Disqord.Core/Models/Application/TeamMemberJsonModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ public class TeamMemberJsonModel : JsonModel

[JsonProperty("user")]
public UserJsonModel User = null!;
}

[JsonProperty("role")]
public TeamMemberRole Role;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ public class AutoModerationTriggerMetadataJsonModel : JsonModel

[JsonProperty("mention_total_limit")]
public Optional<int> MentionTotalLimit;

[JsonProperty("mention_raid_protection_enabled")]
public Optional<bool> MentionRaidProtectionEnabled;
}
3 changes: 3 additions & 0 deletions src/Disqord.Core/Models/GuildJsonModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,7 @@ public class GuildJsonModel : JsonModel

[JsonProperty("premium_progress_bar_enabled")]
public bool PremiumProgressBarEnabled;

[JsonProperty("safety_alerts_channel_id")]
public Snowflake? SafetyAlertsChannelId;
}
4 changes: 4 additions & 0 deletions src/Disqord.Gateway/Entities/Cached/CachedGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public IReadOnlyDictionary<Snowflake, IMember> Members
/// <inheritdoc/>
public bool IsBoostProgressBarEnabled { get; private set; }

/// <inheritdoc/>
public Snowflake? SafetyAlertsChannelId { get; private set; }

IReadOnlyDictionary<Snowflake, IGuildChannel> IGatewayGuild.Channels
{
get
Expand Down Expand Up @@ -250,6 +253,7 @@ public void Update(GuildJsonModel model)
MaxVideoMemberCount = model.MaxVideoChannelUsers.GetValueOrNullable();
NsfwLevel = model.NsfwLevel;
IsBoostProgressBarEnabled = model.PremiumProgressBarEnabled;
SafetyAlertsChannelId = model.SafetyAlertsChannelId;
}

public void Update(GatewayGuildJsonModel model)
Expand Down
14 changes: 12 additions & 2 deletions src/Disqord.Gateway/Entities/Local/LocalActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public static LocalActivity Watching(string name)
return new(name, ActivityType.Watching);
}

public static LocalActivity Custom(string text)
{
return new("Custom Status", ActivityType.Custom, text: text);
}

public static LocalActivity Competing(string name)
{
return new(name, ActivityType.Competing);
Expand All @@ -37,6 +42,8 @@ public static LocalActivity Competing(string name)

public Optional<ActivityType> Type { get; set; }

public Optional<string> Text { get; set; }

public LocalActivity()
{ }

Expand All @@ -45,13 +52,15 @@ protected LocalActivity(LocalActivity other)
Name = other.Name;
Url = other.Url;
Type = other.Type;
Text = other.Text;
}

public LocalActivity(string name, ActivityType type, string? url = null)
public LocalActivity(string name, ActivityType type, string? url = null, string? text = null)
{
Name = name;
Url = Optional.FromNullable(url);
Type = type;
Text = Optional.FromNullable(text);
}

public LocalActivity(string name, string url)
Expand All @@ -76,7 +85,8 @@ public virtual ActivityJsonModel ToModel()
{
Name = Name.Value,
Type = Type.Value,
Url = Url
Url = Url,
State = Text
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public IReadOnlyDictionary<Snowflake, IGuildSticker> Stickers

public bool IsBoostProgressBarEnabled => Model.PremiumProgressBarEnabled;

public Snowflake? SafetyAlertsChannelId => Model.SafetyAlertsChannelId;

public DateTimeOffset JoinedAt => Model.JoinedAt;

public bool IsLarge => Model.Large;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ public class ModifyGuildJsonRestRequestContent : JsonModelRestRequestContent

[JsonProperty("premium_progress_bar_enabled")]
public Optional<bool> PremiumProgressBarEnabled;
}

[JsonProperty("safety_alerts_channel_id")]
public Optional<Snowflake?> SafetyAlertsChannelId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public sealed class ModifyGuildActionProperties

public Optional<bool> IsBoostProgressBarEnabled { internal get; set; }

public Optional<Snowflake?> SafetyAlertsChannelId { internal get; set; }

internal ModifyGuildActionProperties()
{ }
}
}
3 changes: 2 additions & 1 deletion src/Disqord.Rest/Extensions/RestClientExtensions.Guild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public static async Task<IGuild> ModifyGuildAsync(this IRestClient client,
PreferredLocale = Optional.Convert(properties.PreferredLocale, x => x.Name),
Features = Optional.Convert(properties.Features, x => x.ToArray()),
Description = properties.Description,
PremiumProgressBarEnabled = properties.IsBoostProgressBarEnabled
PremiumProgressBarEnabled = properties.IsBoostProgressBarEnabled,
SafetyAlertsChannelId = properties.SafetyAlertsChannelId
};

var model = await client.ApiClient.ModifyGuildAsync(guildId, content, options, cancellationToken).ConfigureAwait(false);
Expand Down
Loading