From 986d4338869dc4dd51afd3cd107908479060bae8 Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Tue, 4 Jul 2023 13:31:19 -0400 Subject: [PATCH] filterlevels used on (almost) all features --- Behavior/DefinitionSnarkCogDiss.cs | 9 +++++++++ Behavior/DefinitionSnarkGaslight.cs | 9 +++++++++ Behavior/GeneralSnarkCloudNative.cs | 8 ++++++++ Behavior/GeneralSnarkPlaying.cs | 6 ++++++ Behavior/PulseCheck.cs | 5 ++++- Behavior/QRify.cs | 12 +++++++++++- Behavior/WishLuck.cs | 9 +++++---- DiscordInterface/DiscordInterface.cs | 4 ++-- Models/Channel.cs | 4 ++-- Models/Enums.cs | 2 ++ Models/PermissionSettings.cs | 26 ++++++++++++++++++++++++-- TwitchInterface/TwitchInterface.cs | 4 ++-- 12 files changed, 84 insertions(+), 14 deletions(-) diff --git a/Behavior/DefinitionSnarkCogDiss.cs b/Behavior/DefinitionSnarkCogDiss.cs index 318de64..9c88939 100644 --- a/Behavior/DefinitionSnarkCogDiss.cs +++ b/Behavior/DefinitionSnarkCogDiss.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using vassago.Models; +using static vassago.Models.Enumerations; [StaticPlz] public class DefinitionSnarkCogDiss : Behavior @@ -17,6 +18,14 @@ public class DefinitionSnarkCogDiss : Behavior public override string Description => "snarkiness about the rampant misuse of the term cognitive dissonance"; + public override bool ShouldAct(Message message) + { + if((MeannessFilterLevel)message.Channel.EffectivePermissions.MeannessFilterLevel < MeannessFilterLevel.Medium) + return false; + + return base.ShouldAct(message); + } + public override async Task ActOn(Message message) { await message.Reply("that's not what cognitive dissonance means. Did you mean \"hypocrisy\"?"); diff --git a/Behavior/DefinitionSnarkGaslight.cs b/Behavior/DefinitionSnarkGaslight.cs index 7ca9bed..ecb31c4 100644 --- a/Behavior/DefinitionSnarkGaslight.cs +++ b/Behavior/DefinitionSnarkGaslight.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using vassago.Models; +using static vassago.Models.Enumerations; [StaticPlz] public class DefinitionSnarkGaslight : Behavior @@ -17,6 +18,14 @@ public class DefinitionSnarkGaslight : Behavior public override string Description => "snarkiness about the rampant misuse of the term gaslighting"; + public override bool ShouldAct(Message message) + { + if((MeannessFilterLevel)message.Channel.EffectivePermissions.MeannessFilterLevel < MeannessFilterLevel.Unrestricted) + return false; + + return base.ShouldAct(message); + } + public override async Task ActOn(Message message) { await message.Channel.SendMessage("that's not what gaslight means. Did you mean \"say something that (you believe) is wrong\"?"); diff --git a/Behavior/GeneralSnarkCloudNative.cs b/Behavior/GeneralSnarkCloudNative.cs index b0d442b..0c0090f 100644 --- a/Behavior/GeneralSnarkCloudNative.cs +++ b/Behavior/GeneralSnarkCloudNative.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Newtonsoft.Json; using vassago.Models; +using static vassago.Models.Enumerations; [StaticPlz] public class GeneralSnarkCloudNative : Behavior @@ -20,6 +21,13 @@ public class GeneralSnarkCloudNative : Behavior { if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) return false; + + if(message.Channel.EffectivePermissions.ReactionsPossible == true) + return false; + + if((MeannessFilterLevel)message.Channel.EffectivePermissions.MeannessFilterLevel < MeannessFilterLevel.Medium) + return false; + return Regex.IsMatch(message.Content, "\\bcloud( |-)?native\\b", RegexOptions.IgnoreCase) || Regex.IsMatch(message.Content, "\\benterprise( |-)?(level|solution)\\b", RegexOptions.IgnoreCase); } diff --git a/Behavior/GeneralSnarkPlaying.cs b/Behavior/GeneralSnarkPlaying.cs index 62d13c0..0a12eee 100644 --- a/Behavior/GeneralSnarkPlaying.cs +++ b/Behavior/GeneralSnarkPlaying.cs @@ -8,6 +8,7 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using vassago.Models; +using static vassago.Models.Enumerations; [StaticPlz] public class GeneralSnarkPlaying : Behavior @@ -22,6 +23,11 @@ public class GeneralSnarkPlaying : Behavior { if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) return false; + + if((MeannessFilterLevel)message.Channel.EffectivePermissions.MeannessFilterLevel < MeannessFilterLevel.Medium || + (LewdnessFilterLevel)message.Channel.EffectivePermissions.LewdnessFilterLevel < LewdnessFilterLevel.Moderate) + return false; + return Regex.IsMatch(message.Content, "^(s?he|(yo)?u|y'?all|they) thinks? i'?m (playin|jokin|kiddin)g?$", RegexOptions.IgnoreCase); } public override async Task ActOn(Message message) diff --git a/Behavior/PulseCheck.cs b/Behavior/PulseCheck.cs index 5a1d5a3..fddb6cf 100644 --- a/Behavior/PulseCheck.cs +++ b/Behavior/PulseCheck.cs @@ -17,7 +17,10 @@ public class PulseCheck : Behavior public override async Task ActOn(Message message) { - await message.Channel.SendFile("assets/ekgblip.png", null); + if(message.Channel.EffectivePermissions.MaxAttachmentBytes >= 16258) + await message.Channel.SendFile("assets/ekgblip.png", null); + else + await message.Channel.SendMessage("[lub-dub]"); return true; } } \ No newline at end of file diff --git a/Behavior/QRify.cs b/Behavior/QRify.cs index 37cdd7f..37b9ff5 100644 --- a/Behavior/QRify.cs +++ b/Behavior/QRify.cs @@ -19,6 +19,13 @@ public class QRify : Behavior public override string Description => "generate text QR codes"; + public override bool ShouldAct(Message message) + { + if(message.Channel.EffectivePermissions.MaxAttachmentBytes < 1024) + return false; + return base.ShouldAct(message); + } + public override async Task ActOn(Message message) { var qrContent = message.Content.Substring($"{Trigger} ".Length + message.Content.IndexOf(Trigger)); @@ -35,7 +42,10 @@ public class QRify : Behavior File.WriteAllText($"tmp/qr{todaysnumber}.svg", qrCodeAsSvg); if (ExternalProcess.GoPlz("convert", $"tmp/qr{todaysnumber}.svg tmp/qr{todaysnumber}.png")) { - await message.Channel.SendFile($"tmp/qr{todaysnumber}.png", null); + if(message.Channel.EffectivePermissions.MaxAttachmentBytes < (ulong)(new System.IO.FileInfo($"tmp/qr{todaysnumber}.png").Length)) + await message.Channel.SendFile($"tmp/qr{todaysnumber}.png", null); + else + message.Channel.SendMessage("resulting qr image 2 big 4 here"); File.Delete($"tmp/qr{todaysnumber}.svg"); File.Delete($"tmp/qr{todaysnumber}.png"); } diff --git a/Behavior/WishLuck.cs b/Behavior/WishLuck.cs index 550c088..cf14a6e 100644 --- a/Behavior/WishLuck.cs +++ b/Behavior/WishLuck.cs @@ -19,14 +19,15 @@ public class WishLuck : Behavior public override async Task ActOn(Message message) { + var toSend = "☘️"; if (Shared.r.Next(20) == 0) { - await message.React("\U0001f340");//4-leaf clover + toSend = "\U0001f340";//4-leaf clover } + if(message.Channel.EffectivePermissions.ReactionsPossible == true) + await message.React(toSend); else - { - await message.React("☘️"); - } + await message.Channel.SendMessage(toSend); return true; } } \ No newline at end of file diff --git a/DiscordInterface/DiscordInterface.cs b/DiscordInterface/DiscordInterface.cs index ffb8280..49bbb7c 100644 --- a/DiscordInterface/DiscordInterface.cs +++ b/DiscordInterface/DiscordInterface.cs @@ -60,8 +60,8 @@ public class DiscordInterface DisplayName = "discord (itself)", Permissions = new PermissionSettings() { - MeannessFilterLevel = 1, - LewdnessFilterLevel = 3, + MeannessFilterLevel = Enumerations.MeannessFilterLevel.Strict, + LewdnessFilterLevel = Enumerations.LewdnessFilterLevel.Moderate, MaxTextChars = 2000, MaxAttachmentBytes = 25 * 1024 * 1024, //allegedly it's 25, but I worry it's not actually. LinksAllowed = true, diff --git a/Models/Channel.cs b/Models/Channel.cs index ce509b9..9fbd356 100644 --- a/Models/Channel.cs +++ b/Models/Channel.cs @@ -29,12 +29,12 @@ public class Channel public Func SendMessage; - public PermissionSettings EffectivePermissions + public DefinitePermissionSettings EffectivePermissions { get { PermissionSettings toReturn = Permissions ?? new PermissionSettings(); - return GetEffectivePermissions(ref toReturn); + return GetEffectivePermissions(ref toReturn).Definite(); } } private PermissionSettings GetEffectivePermissions(ref PermissionSettings settings) diff --git a/Models/Enums.cs b/Models/Enums.cs index 394c7a8..05cce67 100644 --- a/Models/Enums.cs +++ b/Models/Enums.cs @@ -21,6 +21,8 @@ public static class Enumerations { [Description("good vibes only")] Strict, + [Description("a bit cheeky")] + Medium, [Description("387.44 million miles of printed circuits, etc")] Unrestricted } diff --git a/Models/PermissionSettings.cs b/Models/PermissionSettings.cs index 831fa67..95c9aa4 100644 --- a/Models/PermissionSettings.cs +++ b/Models/PermissionSettings.cs @@ -11,6 +11,28 @@ public class PermissionSettings public uint? MaxTextChars { get; set; } public bool? LinksAllowed { get; set; } public bool? ReactionsPossible { get; set; } - public int? LewdnessFilterLevel { get; set; } - public int? MeannessFilterLevel { get; set; } + public Enumerations.LewdnessFilterLevel? LewdnessFilterLevel { get; set; } + public Enumerations.MeannessFilterLevel? MeannessFilterLevel { get; set; } + + internal DefinitePermissionSettings Definite() + { + return new DefinitePermissionSettings() + { + MaxAttachmentBytes = this.MaxAttachmentBytes ?? 0, + MaxTextChars = this.MaxTextChars ?? 0, + LinksAllowed = this.LinksAllowed ?? false, + LewdnessFilterLevel = this.LewdnessFilterLevel ?? Enumerations.LewdnessFilterLevel.G, + MeannessFilterLevel = this.MeannessFilterLevel ?? Enumerations.MeannessFilterLevel.Strict, + ReactionsPossible = this.ReactionsPossible ?? false + }; + } } +public class DefinitePermissionSettings +{ + public ulong MaxAttachmentBytes { get; set; } + public uint MaxTextChars { get; set; } + public bool LinksAllowed { get; set; } + public bool ReactionsPossible { get; set; } + public Enumerations.LewdnessFilterLevel LewdnessFilterLevel { get; set; } + public Enumerations.MeannessFilterLevel MeannessFilterLevel { get; set; } +} \ No newline at end of file diff --git a/TwitchInterface/TwitchInterface.cs b/TwitchInterface/TwitchInterface.cs index da93043..ee499af 100644 --- a/TwitchInterface/TwitchInterface.cs +++ b/TwitchInterface/TwitchInterface.cs @@ -39,8 +39,8 @@ public class TwitchInterface DisplayName = "discord (itself)", Permissions = new PermissionSettings() { - MeannessFilterLevel = 1, - LewdnessFilterLevel = 3, + MeannessFilterLevel = Enumerations.MeannessFilterLevel.Medium, + LewdnessFilterLevel = Enumerations.LewdnessFilterLevel.G, MaxTextChars = 500, MaxAttachmentBytes = 0, LinksAllowed = false,