[Feature] AutoMod support (#2578)
* initial implementation * update models * somewhat working auto mod action executed event * made some properties optional * comments, rest entity, guild methods * add placeholder methods * started working on rule cache * working events * started working on rule builder * working state * fix null issue * commentsssss * public automod rules collection in a socketgulild * forgot nullability * update limits * add Download func to cacheable user * Apply suggestions from code review * Update src/Discord.Net.Rest/DiscordRestApiClient.cs * missing xml doc * reworkkkk * fix the `;` lol --------- Co-authored-by: Quin Lynch <lynchquin@gmail.com> Co-authored-by: Casmir <68127614+csmir@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Newtonsoft.Json;
|
||||
namespace Discord.API.Gateway;
|
||||
|
||||
internal class AutoModActionExecutedEvent
|
||||
{
|
||||
[JsonProperty("guild_id")]
|
||||
public ulong GuildId { get; set; }
|
||||
|
||||
[JsonProperty("action")]
|
||||
public Discord.API.AutoModAction Action { get; set; }
|
||||
|
||||
[JsonProperty("rule_id")]
|
||||
public ulong RuleId { get; set; }
|
||||
|
||||
[JsonProperty("rule_trigger_type")]
|
||||
public AutoModTriggerType TriggerType { get; set; }
|
||||
|
||||
[JsonProperty("user_id")]
|
||||
public ulong UserId { get; set; }
|
||||
|
||||
[JsonProperty("channel_id")]
|
||||
public Optional<ulong> ChannelId { get; set; }
|
||||
|
||||
[JsonProperty("message_id")]
|
||||
public Optional<ulong> MessageId { get; set; }
|
||||
|
||||
[JsonProperty("alert_system_message_id")]
|
||||
public Optional<ulong> AlertSystemMessageId { get; set; }
|
||||
|
||||
[JsonProperty("content")]
|
||||
public string Content { get; set; }
|
||||
|
||||
[JsonProperty("matched_keyword")]
|
||||
public Optional<string> MatchedKeyword { get; set; }
|
||||
|
||||
[JsonProperty("matched_content")]
|
||||
public Optional<string> MatchedContent { get; set; }
|
||||
}
|
||||
@@ -892,5 +892,49 @@ namespace Discord.WebSocket
|
||||
internal readonly AsyncEvent<Func<SocketGuild, SocketChannel, Task>> _webhooksUpdated = new AsyncEvent<Func<SocketGuild, SocketChannel, Task>>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region AutoModeration
|
||||
|
||||
/// <summary>
|
||||
/// Fired when an auto moderation rule is created.
|
||||
/// </summary>
|
||||
public event Func<SocketAutoModRule, Task> AutoModRuleCreated
|
||||
{
|
||||
add => _autoModRuleCreated.Add(value);
|
||||
remove => _autoModRuleCreated.Remove(value);
|
||||
}
|
||||
internal readonly AsyncEvent<Func<SocketAutoModRule, Task>> _autoModRuleCreated = new ();
|
||||
|
||||
/// <summary>
|
||||
/// Fired when an auto moderation rule is modified.
|
||||
/// </summary>
|
||||
public event Func<Cacheable<SocketAutoModRule, ulong>, SocketAutoModRule, Task> AutoModRuleUpdated
|
||||
{
|
||||
add => _autoModRuleUpdated.Add(value);
|
||||
remove => _autoModRuleUpdated.Remove(value);
|
||||
}
|
||||
internal readonly AsyncEvent<Func<Cacheable<SocketAutoModRule, ulong>, SocketAutoModRule, Task>> _autoModRuleUpdated = new ();
|
||||
|
||||
/// <summary>
|
||||
/// Fired when an auto moderation rule is deleted.
|
||||
/// </summary>
|
||||
public event Func<SocketAutoModRule, Task> AutoModRuleDeleted
|
||||
{
|
||||
add => _autoModRuleDeleted.Add(value);
|
||||
remove => _autoModRuleDeleted.Remove(value);
|
||||
}
|
||||
internal readonly AsyncEvent<Func<SocketAutoModRule, Task>> _autoModRuleDeleted = new ();
|
||||
|
||||
/// <summary>
|
||||
/// Fired when an auto moderation rule is triggered by a user.
|
||||
/// </summary>
|
||||
public event Func<SocketGuild, AutoModRuleAction, AutoModActionExecutedData, Task> AutoModActionExecuted
|
||||
{
|
||||
add => _autoModActionExecuted.Add(value);
|
||||
remove => _autoModActionExecuted.Remove(value);
|
||||
}
|
||||
internal readonly AsyncEvent<Func<SocketGuild, AutoModRuleAction, AutoModActionExecutedData, Task>> _autoModActionExecuted = new ();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ using Discord.Net.Udp;
|
||||
using Discord.Net.WebSockets;
|
||||
using Discord.Rest;
|
||||
using Discord.Utils;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@@ -16,6 +18,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using GameModel = Discord.API.Game;
|
||||
|
||||
namespace Discord.WebSocket
|
||||
@@ -2882,6 +2885,132 @@ namespace Discord.WebSocket
|
||||
|
||||
#endregion
|
||||
|
||||
#region Auto Moderation
|
||||
|
||||
case "AUTO_MODERATION_RULE_CREATE":
|
||||
{
|
||||
var data = (payload as JToken).ToObject<AutoModerationRule>(_serializer);
|
||||
|
||||
var guild = State.GetGuild(data.GuildId);
|
||||
|
||||
var rule = guild.AddOrUpdateAutoModRule(data);
|
||||
|
||||
await TimedInvokeAsync(_autoModRuleCreated, nameof(AutoModRuleCreated), rule);
|
||||
}
|
||||
break;
|
||||
|
||||
case "AUTO_MODERATION_RULE_UPDATE":
|
||||
{
|
||||
var data = (payload as JToken).ToObject<AutoModerationRule>(_serializer);
|
||||
|
||||
var guild = State.GetGuild(data.GuildId);
|
||||
|
||||
var cachedRule = guild.GetAutoModRule(data.Id);
|
||||
var cacheableBefore = new Cacheable<SocketAutoModRule, ulong>(cachedRule?.Clone(),
|
||||
data.Id,
|
||||
cachedRule is not null,
|
||||
async () => await guild.GetAutoModRuleAsync(data.Id));
|
||||
|
||||
await TimedInvokeAsync(_autoModRuleUpdated, nameof(AutoModRuleUpdated), cacheableBefore, guild.AddOrUpdateAutoModRule(data));
|
||||
}
|
||||
break;
|
||||
|
||||
case "AUTO_MODERATION_RULE_DELETE":
|
||||
{
|
||||
var data = (payload as JToken).ToObject<AutoModerationRule>(_serializer);
|
||||
|
||||
var guild = State.GetGuild(data.GuildId);
|
||||
|
||||
var rule = guild.RemoveAutoModRule(data);
|
||||
|
||||
await TimedInvokeAsync(_autoModRuleDeleted, nameof(AutoModRuleDeleted), rule);
|
||||
}
|
||||
break;
|
||||
|
||||
case "AUTO_MODERATION_ACTION_EXECUTION":
|
||||
{
|
||||
var data = (payload as JToken).ToObject<AutoModActionExecutedEvent>(_serializer);
|
||||
|
||||
var guild = State.GetGuild(data.GuildId);
|
||||
var action = new AutoModRuleAction(data.Action.Type,
|
||||
data.Action.Metadata.IsSpecified
|
||||
? data.Action.Metadata.Value.ChannelId.IsSpecified
|
||||
? data.Action.Metadata.Value.ChannelId.Value
|
||||
: null
|
||||
: null,
|
||||
data.Action.Metadata.IsSpecified
|
||||
? data.Action.Metadata.Value.DurationSeconds.IsSpecified
|
||||
? data.Action.Metadata.Value.DurationSeconds.Value
|
||||
: null
|
||||
: null);
|
||||
|
||||
var member = guild.GetUser(data.UserId);
|
||||
|
||||
var cacheableUser = new Cacheable<SocketGuildUser, ulong>(member,
|
||||
data.UserId,
|
||||
member is not null,
|
||||
async () =>
|
||||
{
|
||||
var model = await ApiClient.GetGuildMemberAsync(data.GuildId, data.UserId);
|
||||
return guild.AddOrUpdateUser(model);
|
||||
}
|
||||
);
|
||||
|
||||
ISocketMessageChannel channel = null;
|
||||
if (data.ChannelId.IsSpecified)
|
||||
channel = GetChannel(data.ChannelId.Value) as ISocketMessageChannel;
|
||||
|
||||
var cacheableChannel = new Cacheable<ISocketMessageChannel, ulong>(channel,
|
||||
data.ChannelId.GetValueOrDefault(0),
|
||||
channel != null,
|
||||
async () =>
|
||||
{
|
||||
if(data.ChannelId.IsSpecified)
|
||||
return await GetChannelAsync(data.ChannelId.Value).ConfigureAwait(false) as ISocketMessageChannel;
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
var cachedMsg = channel?.GetCachedMessage(data.MessageId.GetValueOrDefault(0)) as IUserMessage;
|
||||
|
||||
var cacheableMessage = new Cacheable<IUserMessage, ulong>(cachedMsg,
|
||||
data.MessageId.GetValueOrDefault(0),
|
||||
cachedMsg is not null,
|
||||
async () =>
|
||||
{
|
||||
if(data.MessageId.IsSpecified)
|
||||
return (await channel.GetMessageAsync(data.MessageId.Value).ConfigureAwait(false)) as IUserMessage;
|
||||
return null;
|
||||
});
|
||||
|
||||
var cachedRule = guild.GetAutoModRule(data.RuleId);
|
||||
|
||||
var cacheableRule = new Cacheable<IAutoModRule, ulong>(cachedRule,
|
||||
data.RuleId,
|
||||
cachedRule is not null,
|
||||
async () => await guild.GetAutoModRuleAsync(data.RuleId));
|
||||
|
||||
var eventData = new AutoModActionExecutedData(
|
||||
cacheableRule,
|
||||
data.TriggerType,
|
||||
cacheableUser,
|
||||
cacheableChannel,
|
||||
cachedMsg is not null ? cacheableMessage : null,
|
||||
data.AlertSystemMessageId.GetValueOrDefault(0),
|
||||
data.Content,
|
||||
data.MatchedContent.IsSpecified
|
||||
? data.MatchedContent.Value
|
||||
: null,
|
||||
data.MatchedKeyword.IsSpecified
|
||||
? data.MatchedKeyword.Value
|
||||
: null);
|
||||
|
||||
await TimedInvokeAsync(_autoModActionExecuted, nameof(AutoModActionExecuted), guild, action, eventData);
|
||||
}
|
||||
break;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Ignored (User only)
|
||||
case "CHANNEL_PINS_ACK":
|
||||
await _gatewayLogger.DebugAsync("Ignored Dispatch (CHANNEL_PINS_ACK)").ConfigureAwait(false);
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
using Discord.Rest;
|
||||
|
||||
namespace Discord.WebSocket;
|
||||
|
||||
public class AutoModActionExecutedData
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the id of the rule which action belongs to.
|
||||
/// </summary>
|
||||
public Cacheable<IAutoModRule, ulong> Rule { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the trigger type of rule which was triggered.
|
||||
/// </summary>
|
||||
public AutoModTriggerType TriggerType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user which generated the content which triggered the rule.
|
||||
/// </summary>
|
||||
public Cacheable<SocketGuildUser, ulong> User { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the channel in which user content was posted.
|
||||
/// </summary>
|
||||
public Cacheable<ISocketMessageChannel, ulong> Channel { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the message that triggered the action.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property will be <see langword="null"/> if the message was blocked by the automod.
|
||||
/// </remarks>
|
||||
public Cacheable<IUserMessage, ulong>? Message { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the id of the system auto moderation messages posted as a result of this action.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property will be <see langword="null"/> if this event does not correspond to an action
|
||||
/// with type <see cref="AutoModActionType.SendAlertMessage"/>.
|
||||
/// </remarks>
|
||||
public ulong AlertMessageId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user-generated text content.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property will be empty if <see cref="GatewayIntents.MessageContent"/> is disabled.
|
||||
/// </remarks>
|
||||
public string Content { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the substring in content that triggered the rule.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property will be empty if <see cref="GatewayIntents.MessageContent"/> is disabled.
|
||||
/// </remarks>
|
||||
public string MatchedContent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the word or phrase configured in the rule that triggered the rule.
|
||||
/// </summary>
|
||||
public string MatchedKeyword { get; }
|
||||
|
||||
internal AutoModActionExecutedData(Cacheable<IAutoModRule, ulong> rule,
|
||||
AutoModTriggerType triggerType,
|
||||
Cacheable<SocketGuildUser, ulong> user,
|
||||
Cacheable<ISocketMessageChannel, ulong> channel,
|
||||
Cacheable<IUserMessage, ulong>? message,
|
||||
ulong alertMessageId,
|
||||
string content,
|
||||
string matchedContent,
|
||||
string matchedKeyword
|
||||
)
|
||||
{
|
||||
Rule = rule;
|
||||
TriggerType = triggerType;
|
||||
User = user;
|
||||
Channel = channel;
|
||||
Message = message;
|
||||
AlertMessageId = alertMessageId;
|
||||
Content = content;
|
||||
MatchedContent = matchedContent;
|
||||
MatchedKeyword = matchedKeyword;
|
||||
}
|
||||
}
|
||||
122
src/Discord.Net.WebSocket/Entities/Guilds/SocketAutoModRule.cs
Normal file
122
src/Discord.Net.WebSocket/Entities/Guilds/SocketAutoModRule.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.AutoModerationRule;
|
||||
|
||||
namespace Discord.WebSocket
|
||||
{
|
||||
public class SocketAutoModRule : SocketEntity<ulong>, IAutoModRule
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the guild that this rule is in.
|
||||
/// </summary>
|
||||
public SocketGuild Guild { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the creator of this rule.
|
||||
/// </summary>
|
||||
public SocketGuildUser Creator { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public AutoModEventType EventType { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public AutoModTriggerType TriggerType { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<string> KeywordFilter { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<string> RegexPatterns { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<string> AllowList { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<KeywordPresetTypes> Presets { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyCollection<AutoModRuleAction> Actions { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int? MentionTotalLimit { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Enabled { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the roles that are exempt from this rule.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<SocketRole> ExemptRoles { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the channels that are exempt from this rule.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<SocketGuildChannel> ExemptChannels { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset CreatedAt
|
||||
=> SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
private ulong _creatorId;
|
||||
|
||||
internal SocketAutoModRule(DiscordSocketClient discord, ulong id, SocketGuild guild)
|
||||
: base(discord, id)
|
||||
{
|
||||
Guild = guild;
|
||||
}
|
||||
|
||||
internal static SocketAutoModRule Create(DiscordSocketClient discord, SocketGuild guild, Model model)
|
||||
{
|
||||
var entity = new SocketAutoModRule(discord, model.Id, guild);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
|
||||
internal void Update(Model model)
|
||||
{
|
||||
Name = model.Name;
|
||||
_creatorId = model.CreatorId;
|
||||
Creator ??= Guild.GetUser(_creatorId);
|
||||
EventType = model.EventType;
|
||||
TriggerType = model.TriggerType;
|
||||
KeywordFilter = model.TriggerMetadata.KeywordFilter.GetValueOrDefault(Array.Empty<string>()).ToImmutableArray();
|
||||
Presets = model.TriggerMetadata.Presets.GetValueOrDefault(Array.Empty<KeywordPresetTypes>()).ToImmutableArray();
|
||||
RegexPatterns = model.TriggerMetadata.RegexPatterns.GetValueOrDefault(Array.Empty<string>()).ToImmutableArray();
|
||||
AllowList = model.TriggerMetadata.AllowList.GetValueOrDefault(Array.Empty<string>()).ToImmutableArray();
|
||||
MentionTotalLimit = model.TriggerMetadata.MentionLimit.IsSpecified
|
||||
? model.TriggerMetadata.MentionLimit.Value
|
||||
: null;
|
||||
Actions = model.Actions.Select(x => new AutoModRuleAction(x.Type, x.Metadata.GetValueOrDefault()?.ChannelId.ToNullable(), x.Metadata.GetValueOrDefault()?.DurationSeconds.ToNullable())).ToImmutableArray();
|
||||
Enabled = model.Enabled;
|
||||
ExemptRoles = model.ExemptRoles.Select(x => Guild.GetRole(x)).ToImmutableArray();
|
||||
ExemptChannels = model.ExemptChannels.Select(x => Guild.GetChannel(x)).ToImmutableArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task ModifyAsync(Action<AutoModRuleProperties> func, RequestOptions options = null)
|
||||
{
|
||||
var model = await GuildHelper.ModifyRuleAsync(Discord, this, func, options);
|
||||
Guild.AddOrUpdateAutoModRule(model);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task DeleteAsync(RequestOptions options = null)
|
||||
=> GuildHelper.DeleteRuleAsync(Discord, this, options);
|
||||
|
||||
internal SocketAutoModRule Clone() => MemberwiseClone() as SocketAutoModRule;
|
||||
|
||||
#region IAutoModRule
|
||||
IReadOnlyCollection<ulong> IAutoModRule.ExemptRoles => ExemptRoles.Select(x => x.Id).ToImmutableArray();
|
||||
IReadOnlyCollection<ulong> IAutoModRule.ExemptChannels => ExemptChannels.Select(x => x.Id).ToImmutableArray();
|
||||
ulong IAutoModRule.GuildId => Guild.Id;
|
||||
ulong IAutoModRule.CreatorId => _creatorId;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AutoModRuleModel = Discord.API.AutoModerationRule;
|
||||
using ChannelModel = Discord.API.Channel;
|
||||
using EmojiUpdateModel = Discord.API.Gateway.GuildEmojiUpdateEvent;
|
||||
using EventModel = Discord.API.GuildScheduledEvent;
|
||||
@@ -43,6 +44,7 @@ namespace Discord.WebSocket
|
||||
private ConcurrentDictionary<ulong, SocketVoiceState> _voiceStates;
|
||||
private ConcurrentDictionary<ulong, SocketCustomSticker> _stickers;
|
||||
private ConcurrentDictionary<ulong, SocketGuildEvent> _events;
|
||||
private ConcurrentDictionary<ulong, SocketAutoModRule> _automodRules;
|
||||
private ImmutableArray<GuildEmote> _emotes;
|
||||
|
||||
private AudioClient _audioClient;
|
||||
@@ -391,6 +393,7 @@ namespace Discord.WebSocket
|
||||
{
|
||||
_audioLock = new SemaphoreSlim(1, 1);
|
||||
_emotes = ImmutableArray.Create<GuildEmote>();
|
||||
_automodRules = new ConcurrentDictionary<ulong, SocketAutoModRule>();
|
||||
}
|
||||
internal static SocketGuild Create(DiscordSocketClient discord, ClientState state, ExtendedModel model)
|
||||
{
|
||||
@@ -1809,6 +1812,78 @@ namespace Discord.WebSocket
|
||||
internal SocketGuild Clone() => MemberwiseClone() as SocketGuild;
|
||||
#endregion
|
||||
|
||||
#region AutoMod
|
||||
|
||||
internal SocketAutoModRule AddOrUpdateAutoModRule(AutoModRuleModel model)
|
||||
{
|
||||
if (_automodRules.TryGetValue(model.Id, out var rule))
|
||||
{
|
||||
rule.Update(model);
|
||||
return rule;
|
||||
}
|
||||
|
||||
var socketRule = SocketAutoModRule.Create(Discord, this, model);
|
||||
_automodRules.TryAdd(model.Id, socketRule);
|
||||
return socketRule;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single rule configured in a guild from cache. Returns <see langword="null"/> if the rule was not found.
|
||||
/// </summary>
|
||||
public SocketAutoModRule GetAutoModRule(ulong id)
|
||||
{
|
||||
return _automodRules.TryGetValue(id, out var rule) ? rule : null;
|
||||
}
|
||||
|
||||
internal SocketAutoModRule RemoveAutoModRule(ulong id)
|
||||
{
|
||||
return _automodRules.TryRemove(id, out var rule) ? rule : null;
|
||||
}
|
||||
|
||||
internal SocketAutoModRule RemoveAutoModRule(AutoModRuleModel model)
|
||||
{
|
||||
if (_automodRules.TryRemove(model.Id, out var rule))
|
||||
{
|
||||
rule.Update(model);
|
||||
}
|
||||
|
||||
return rule ?? SocketAutoModRule.Create(Discord, this, model);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IGuild.GetAutoModRuleAsync"/>
|
||||
public async Task<SocketAutoModRule> GetAutoModRuleAsync(ulong ruleId, RequestOptions options = null)
|
||||
{
|
||||
var rule = await GuildHelper.GetAutoModRuleAsync(ruleId, this, Discord, options);
|
||||
|
||||
return AddOrUpdateAutoModRule(rule);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IGuild.GetAutoModRulesAsync"/>
|
||||
public async Task<SocketAutoModRule[]> GetAutoModRulesAsync(RequestOptions options = null)
|
||||
{
|
||||
var rules = await GuildHelper.GetAutoModRulesAsync(this, Discord, options);
|
||||
|
||||
return rules.Select(AddOrUpdateAutoModRule).ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IGuild.CreateAutoModRuleAsync"/>
|
||||
public async Task<SocketAutoModRule> CreateAutoModRuleAsync(Action<AutoModRuleProperties> props, RequestOptions options = null)
|
||||
{
|
||||
var rule = await GuildHelper.CreateAutoModRuleAsync(this, props, Discord, options);
|
||||
|
||||
return AddOrUpdateAutoModRule(rule);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the auto moderation rules defined in this guild.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property may not always return all auto moderation rules if they haven't been cached.
|
||||
/// </remarks>
|
||||
public IReadOnlyCollection<SocketAutoModRule> AutoModRules => _automodRules.ToReadOnlyCollection();
|
||||
|
||||
#endregion
|
||||
|
||||
#region IGuild
|
||||
/// <inheritdoc />
|
||||
ulong? IGuild.AFKChannelId => AFKChannelId;
|
||||
@@ -2053,6 +2128,19 @@ namespace Discord.WebSocket
|
||||
_audioLock?.Dispose();
|
||||
_audioClient?.Dispose();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
async Task<IAutoModRule> IGuild.GetAutoModRuleAsync(ulong ruleId, RequestOptions options)
|
||||
=> await GetAutoModRuleAsync(ruleId, options).ConfigureAwait(false);
|
||||
|
||||
/// <inheritdoc/>
|
||||
async Task<IAutoModRule[]> IGuild.GetAutoModRulesAsync(RequestOptions options)
|
||||
=> await GetAutoModRulesAsync(options).ConfigureAwait(false);
|
||||
|
||||
/// <inheritdoc/>
|
||||
async Task<IAutoModRule> IGuild.CreateAutoModRuleAsync(Action<AutoModRuleProperties> props, RequestOptions options)
|
||||
=> await CreateAutoModRuleAsync(props, options).ConfigureAwait(false);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user