filterlevels used on (almost) all features

This commit is contained in:
Adam R Grey 2023-07-04 13:31:19 -04:00
parent c393f657d1
commit 986d433886
12 changed files with 84 additions and 14 deletions

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using vassago.Models; using vassago.Models;
using static vassago.Models.Enumerations;
[StaticPlz] [StaticPlz]
public class DefinitionSnarkCogDiss : Behavior 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 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<bool> ActOn(Message message) public override async Task<bool> ActOn(Message message)
{ {
await message.Reply("that's not what cognitive dissonance means. Did you mean \"hypocrisy\"?"); await message.Reply("that's not what cognitive dissonance means. Did you mean \"hypocrisy\"?");

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using vassago.Models; using vassago.Models;
using static vassago.Models.Enumerations;
[StaticPlz] [StaticPlz]
public class DefinitionSnarkGaslight : Behavior 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 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<bool> ActOn(Message message) public override async Task<bool> ActOn(Message message)
{ {
await message.Channel.SendMessage("that's not what gaslight means. Did you mean \"say something that (you believe) is wrong\"?"); await message.Channel.SendMessage("that's not what gaslight means. Did you mean \"say something that (you believe) is wrong\"?");

View File

@ -9,6 +9,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using vassago.Models; using vassago.Models;
using static vassago.Models.Enumerations;
[StaticPlz] [StaticPlz]
public class GeneralSnarkCloudNative : Behavior public class GeneralSnarkCloudNative : Behavior
@ -20,6 +21,13 @@ public class GeneralSnarkCloudNative : Behavior
{ {
if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id))
return false; 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) || return Regex.IsMatch(message.Content, "\\bcloud( |-)?native\\b", RegexOptions.IgnoreCase) ||
Regex.IsMatch(message.Content, "\\benterprise( |-)?(level|solution)\\b", RegexOptions.IgnoreCase); Regex.IsMatch(message.Content, "\\benterprise( |-)?(level|solution)\\b", RegexOptions.IgnoreCase);
} }

View File

@ -8,6 +8,7 @@ using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using vassago.Models; using vassago.Models;
using static vassago.Models.Enumerations;
[StaticPlz] [StaticPlz]
public class GeneralSnarkPlaying : Behavior public class GeneralSnarkPlaying : Behavior
@ -22,6 +23,11 @@ public class GeneralSnarkPlaying : Behavior
{ {
if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id))
return false; 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); 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<bool> ActOn(Message message) public override async Task<bool> ActOn(Message message)

View File

@ -17,7 +17,10 @@ public class PulseCheck : Behavior
public override async Task<bool> ActOn(Message message) public override async Task<bool> ActOn(Message message)
{ {
if(message.Channel.EffectivePermissions.MaxAttachmentBytes >= 16258)
await message.Channel.SendFile("assets/ekgblip.png", null); await message.Channel.SendFile("assets/ekgblip.png", null);
else
await message.Channel.SendMessage("[lub-dub]");
return true; return true;
} }
} }

View File

@ -19,6 +19,13 @@ public class QRify : Behavior
public override string Description => "generate text QR codes"; 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<bool> ActOn(Message message) public override async Task<bool> ActOn(Message message)
{ {
var qrContent = message.Content.Substring($"{Trigger} ".Length + message.Content.IndexOf(Trigger)); 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); File.WriteAllText($"tmp/qr{todaysnumber}.svg", qrCodeAsSvg);
if (ExternalProcess.GoPlz("convert", $"tmp/qr{todaysnumber}.svg tmp/qr{todaysnumber}.png")) if (ExternalProcess.GoPlz("convert", $"tmp/qr{todaysnumber}.svg tmp/qr{todaysnumber}.png"))
{ {
if(message.Channel.EffectivePermissions.MaxAttachmentBytes < (ulong)(new System.IO.FileInfo($"tmp/qr{todaysnumber}.png").Length))
await message.Channel.SendFile($"tmp/qr{todaysnumber}.png", null); 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}.svg");
File.Delete($"tmp/qr{todaysnumber}.png"); File.Delete($"tmp/qr{todaysnumber}.png");
} }

View File

@ -19,14 +19,15 @@ public class WishLuck : Behavior
public override async Task<bool> ActOn(Message message) public override async Task<bool> ActOn(Message message)
{ {
var toSend = "☘️";
if (Shared.r.Next(20) == 0) 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 else
{ await message.Channel.SendMessage(toSend);
await message.React("☘️");
}
return true; return true;
} }
} }

View File

@ -60,8 +60,8 @@ public class DiscordInterface
DisplayName = "discord (itself)", DisplayName = "discord (itself)",
Permissions = new PermissionSettings() Permissions = new PermissionSettings()
{ {
MeannessFilterLevel = 1, MeannessFilterLevel = Enumerations.MeannessFilterLevel.Strict,
LewdnessFilterLevel = 3, LewdnessFilterLevel = Enumerations.LewdnessFilterLevel.Moderate,
MaxTextChars = 2000, MaxTextChars = 2000,
MaxAttachmentBytes = 25 * 1024 * 1024, //allegedly it's 25, but I worry it's not actually. MaxAttachmentBytes = 25 * 1024 * 1024, //allegedly it's 25, but I worry it's not actually.
LinksAllowed = true, LinksAllowed = true,

View File

@ -29,12 +29,12 @@ public class Channel
public Func<string, Task> SendMessage; public Func<string, Task> SendMessage;
public PermissionSettings EffectivePermissions public DefinitePermissionSettings EffectivePermissions
{ {
get get
{ {
PermissionSettings toReturn = Permissions ?? new PermissionSettings(); PermissionSettings toReturn = Permissions ?? new PermissionSettings();
return GetEffectivePermissions(ref toReturn); return GetEffectivePermissions(ref toReturn).Definite();
} }
} }
private PermissionSettings GetEffectivePermissions(ref PermissionSettings settings) private PermissionSettings GetEffectivePermissions(ref PermissionSettings settings)

View File

@ -21,6 +21,8 @@ public static class Enumerations
{ {
[Description("good vibes only")] [Description("good vibes only")]
Strict, Strict,
[Description("a bit cheeky")]
Medium,
[Description("387.44 million miles of printed circuits, etc")] [Description("387.44 million miles of printed circuits, etc")]
Unrestricted Unrestricted
} }

View File

@ -11,6 +11,28 @@ public class PermissionSettings
public uint? MaxTextChars { get; set; } public uint? MaxTextChars { get; set; }
public bool? LinksAllowed { get; set; } public bool? LinksAllowed { get; set; }
public bool? ReactionsPossible { get; set; } public bool? ReactionsPossible { get; set; }
public int? LewdnessFilterLevel { get; set; } public Enumerations.LewdnessFilterLevel? LewdnessFilterLevel { get; set; }
public int? MeannessFilterLevel { 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; }
} }

View File

@ -39,8 +39,8 @@ public class TwitchInterface
DisplayName = "discord (itself)", DisplayName = "discord (itself)",
Permissions = new PermissionSettings() Permissions = new PermissionSettings()
{ {
MeannessFilterLevel = 1, MeannessFilterLevel = Enumerations.MeannessFilterLevel.Medium,
LewdnessFilterLevel = 3, LewdnessFilterLevel = Enumerations.LewdnessFilterLevel.G,
MaxTextChars = 500, MaxTextChars = 500,
MaxAttachmentBytes = 0, MaxAttachmentBytes = 0,
LinksAllowed = false, LinksAllowed = false,