about summary refs log tree commit diff
path: root/StateEventTypes
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2023-11-23 05:42:33 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2023-11-23 05:42:33 +0100
commit41316bb445790e7df34f55b7e2b1cfeae04f2adc (patch)
treef4970983f43baf209966c494242e9f56c42a37de /StateEventTypes
downloadModerationBot-41316bb445790e7df34f55b7e2b1cfeae04f2adc.tar.xz
Moderation bot work
Diffstat (limited to 'StateEventTypes')
-rw-r--r--StateEventTypes/Policies/BasePolicy.cs52
-rw-r--r--StateEventTypes/Policies/Implementations/MediaPolicyFile.cs16
-rw-r--r--StateEventTypes/Policies/Implementations/MediaPolicyHomeserver.cs11
-rw-r--r--StateEventTypes/Policies/Implementations/MessagePolicyContainsText.cs11
-rw-r--r--StateEventTypes/Policies/Implementations/UnknownPolicy.cs10
5 files changed, 100 insertions, 0 deletions
diff --git a/StateEventTypes/Policies/BasePolicy.cs b/StateEventTypes/Policies/BasePolicy.cs
new file mode 100644
index 0000000..94b2f63
--- /dev/null
+++ b/StateEventTypes/Policies/BasePolicy.cs
@@ -0,0 +1,52 @@
+using System.ComponentModel.DataAnnotations;
+using System.Text.Json.Serialization;
+using LibMatrix;
+using LibMatrix.Interfaces;
+
+namespace ModerationBot.StateEventTypes.Policies;
+
+public abstract class BasePolicy : EventContent {
+    /// <summary>
+    ///     Entity this policy applies to, null if event was redacted
+    /// </summary>
+    [JsonPropertyName("entity")]
+    public string? Entity { get; set; }
+
+    /// <summary>
+    ///     Reason this policy exists
+    /// </summary>
+    [JsonPropertyName("reason")]
+    public string? Reason { get; set; }
+
+    /// <summary>
+    ///     Suggested action to take, one of `ban`, `kick`, `mute`, `redact`, `spoiler`, `warn` or `warn_admins`
+    /// </summary>
+    [JsonPropertyName("recommendation")]
+    [AllowedValues("ban", "kick", "mute", "redact", "spoiler", "warn", "warn_admins")]
+    public string Recommendation { get; set; } = "warn";
+
+    /// <summary>
+    ///     Expiry time in milliseconds since the unix epoch, or null if the ban has no expiry.
+    /// </summary>
+    [JsonPropertyName("support.feline.policy.expiry.rev.2")] //stable prefix: expiry, msc pending
+    public long? Expiry { get; set; }
+
+    //utils
+    /// <summary>
+    ///     Readable expiry time, provided for easy interaction
+    /// </summary>
+    [JsonPropertyName("gay.rory.matrix_room_utils.readable_expiry_time_utc")]
+    public DateTime? ExpiryDateTime {
+        get => Expiry == null ? null : DateTimeOffset.FromUnixTimeMilliseconds(Expiry.Value).DateTime;
+        set => Expiry = value is null ? null : ((DateTimeOffset)value).ToUnixTimeMilliseconds();
+    }
+
+#region Internal metadata
+
+    [JsonIgnore]
+    public PolicyList PolicyList { get; set; }
+
+    public StateEventResponse OriginalEvent { get; set; }
+
+#endregion
+}
diff --git a/StateEventTypes/Policies/Implementations/MediaPolicyFile.cs b/StateEventTypes/Policies/Implementations/MediaPolicyFile.cs
new file mode 100644
index 0000000..c5b6ef2
--- /dev/null
+++ b/StateEventTypes/Policies/Implementations/MediaPolicyFile.cs
@@ -0,0 +1,16 @@
+using System.Text.Json.Serialization;
+using LibMatrix.EventTypes;
+
+namespace ModerationBot.StateEventTypes.Policies.Implementations;
+
+/// <summary>
+///     File policy event, entity is the MXC URI of the file, hashed with SHA3-256.
+/// </summary>
+[MatrixEvent(EventName = "gay.rory.moderation.rule.media")]
+public class MediaPolicyFile : BasePolicy {
+    /// <summary>
+    ///     Hash of the file
+    /// </summary>
+    [JsonPropertyName("file_hash")]
+    public string? FileHash { get; set; }
+}
diff --git a/StateEventTypes/Policies/Implementations/MediaPolicyHomeserver.cs b/StateEventTypes/Policies/Implementations/MediaPolicyHomeserver.cs
new file mode 100644
index 0000000..3dfd937
--- /dev/null
+++ b/StateEventTypes/Policies/Implementations/MediaPolicyHomeserver.cs
@@ -0,0 +1,11 @@
+using System.Text.Json.Serialization;
+using LibMatrix.EventTypes;
+
+namespace ModerationBot.StateEventTypes.Policies.Implementations;
+
+/// <summary>
+///     Homeserver media policy event, entity is the MXC URI of the file, hashed with SHA3-256.
+/// </summary>
+[MatrixEvent(EventName = "gay.rory.moderation.rule.media.homeserver")]
+public class MediaPolicyHomeserver : BasePolicy {
+}
diff --git a/StateEventTypes/Policies/Implementations/MessagePolicyContainsText.cs b/StateEventTypes/Policies/Implementations/MessagePolicyContainsText.cs
new file mode 100644
index 0000000..daac162
--- /dev/null
+++ b/StateEventTypes/Policies/Implementations/MessagePolicyContainsText.cs
@@ -0,0 +1,11 @@
+using System.Text.Json.Serialization;
+using LibMatrix.EventTypes;
+
+namespace ModerationBot.StateEventTypes.Policies.Implementations;
+
+/// <summary>
+///     Text contains policy event, entity is the text to contain.
+/// </summary>
+[MatrixEvent(EventName = "gay.rory.moderation.rule.text.contains")]
+public class MessagePolicyContainsText : BasePolicy {
+}
diff --git a/StateEventTypes/Policies/Implementations/UnknownPolicy.cs b/StateEventTypes/Policies/Implementations/UnknownPolicy.cs
new file mode 100644
index 0000000..8dc8258
--- /dev/null
+++ b/StateEventTypes/Policies/Implementations/UnknownPolicy.cs
@@ -0,0 +1,10 @@
+using System.Text.Json.Serialization;
+using LibMatrix.EventTypes;
+
+namespace ModerationBot.StateEventTypes.Policies.Implementations;
+
+/// <summary>
+///     Unknown policy event, usually used for handling unknown cases
+/// </summary>
+public class UnknownPolicy : BasePolicy {
+}