From 13324999cca2a30658977c1bdc000e65693c65bd Mon Sep 17 00:00:00 2001 From: Noi Date: Fri, 17 Jun 2022 23:23:25 -0700 Subject: [PATCH] Updates and changes to project files - Set up vscode tasks - Update Readme and License - Minor style and documentation changes --- .vscode/launch.json | 26 ++++++++++++++++++++++ .vscode/tasks.json | 41 +++++++++++++++++++++++++++++++++++ LICENSE.txt => License.txt | 2 +- README.md | 22 ------------------- Readme.md | 34 +++++++++++++++++++++++++++++ RegexBot.sln | 32 +++++++++++---------------- RegexBot/Common/EntityList.cs | 2 ++ RegexBot/Common/EntityName.cs | 22 +++++++++---------- RegexBot/RegexbotModule.cs | 3 ++- 9 files changed, 130 insertions(+), 54 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json rename LICENSE.txt => License.txt (94%) delete mode 100644 README.md create mode 100644 Readme.md diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..226ef29 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/output/Debug/net6.0/RegexBot.dll", + "args": [], + "cwd": "${workspaceFolder}/RegexBot", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..d900e19 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/RegexBot.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/RegexBot.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/RegexBot.sln" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/LICENSE.txt b/License.txt similarity index 94% rename from LICENSE.txt rename to License.txt index 4c9506d..d55e9ed 100644 --- a/LICENSE.txt +++ b/License.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Noikoio +Copyright (c) 2018-2022 Noi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md deleted file mode 100644 index de83269..0000000 --- a/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# RegexBot -**This branch contains code that is still a major work in progress, and is unusable in its current state. See the master branch for the current working version.** - -RegexBot is a self-hosted Discord moderation bot that takes some inspiration from Reddit's Automoderator. It provides a number of features to assist in watching over the tedious details in a busy server with no hidden details, arbitrary restrictions, or unmodifiable behavior. Its configuration allows for a very high level of flexibility, ensuring that the bot behaves in accordance to the exact needs of your server. - -### Feature overview for 3.0: -* Modular structure allows for extra features to be written, further enhancing the bot's customizability wherever it may be deployed. -* Versatile JSON-based configuration, support for separate servers. -* High detail logging and record-keeping prevents gaps in moderation that might occur with large public bots. - -### Feature overview for RegexBotModule 3.0: -* Create rules based on regular expression patterns - * Follow up with custom responses ranging from sending a DM to disciplinary action -* Create pattern-based triggers to provide information and fun to your users - * Adjustable rate limits per-trigger to prevent spam - * Specify multiple different responses to display at random when triggered - * Make things interesting by setting triggers that only activate at random -* Individual rules and triggers can be whitelisted or blacklisted per-user, per-channel, or per-role - * Exemptions to these filters can be applied for additional flexibility - -## Documentation -Coming soon. diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..60bfc15 --- /dev/null +++ b/Readme.md @@ -0,0 +1,34 @@ +# RegexBot +**This branch is still a major work in progress, and is highly incomplete. See the legacy branch for the current working version.** + +RegexBot is a Discord moderation bot framework of sorts, inspired by the terrible state of Discord moderation tools a few years ago +combined with my tendency to overengineer things until they into pseudo-libraries of their own right. + +### Features: +* Provides a sort of in-between interface to Discord.Net that allows modules to be written for it, its benefits being: + * Putting together disparate bot features under a common interface. + * Reducing duplicate code potentially leading to an inconsistent user experience. +* Versatile JSON-based configuration. +* High detail logging and record-keeping prevents gaps in moderation that might occur with large public bots. + +This repository also contains... + +# RegexBot-Modules +An optional set of features to add to RegexBot, some of them inspired by Reddit's Automoderator. + +This module provides a number of features to assist in watching over the tedious details in a busy server with no hidden details, +arbitrary restrictions, or unmodifiable behavior. Its configuration allows for a very high level of flexibility, ensuring that the bot +behaves in accordance to the exact needs of your server. + +### Features: +* Create rules based on regular expression patterns + * Follow up with custom responses ranging from sending a DM to disciplinary action +* Create pattern-based triggers to provide information and fun to your users + * Adjustable rate limits per-trigger to prevent spam + * Specify multiple different responses to display at random when triggered + * Make things interesting by setting triggers that only activate at random +* Individual rules and triggers can be whitelisted or blacklisted per-user, per-channel, or per-role + * Exemptions to these filters can be applied for additional flexibility + +## Documentation +Coming soon? diff --git a/RegexBot.sln b/RegexBot.sln index 95b0a64..ac74113 100644 --- a/RegexBot.sln +++ b/RegexBot.sln @@ -1,34 +1,28 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.32112.339 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RegexBot", "RegexBot\RegexBot.csproj", "{6FA3A92F-F1FC-4BA8-8018-1A05CB4C7FA3}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegexBot", "RegexBot\RegexBot.csproj", "{F7CDACE1-C74E-451E-A9C2-ED717BF72C1C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegexBot-Modules", "RegexBot-Modules\RegexBot-Modules.csproj", "{03111D82-30ED-4FDF-A512-87BDC05C6DA1}" - ProjectSection(ProjectDependencies) = postProject - {6FA3A92F-F1FC-4BA8-8018-1A05CB4C7FA3} = {6FA3A92F-F1FC-4BA8-8018-1A05CB4C7FA3} - EndProjectSection +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegexBot-Modules", "RegexBot-Modules\RegexBot-Modules.csproj", "{347A1912-4F7D-419B-A159-6671791568CC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6FA3A92F-F1FC-4BA8-8018-1A05CB4C7FA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6FA3A92F-F1FC-4BA8-8018-1A05CB4C7FA3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6FA3A92F-F1FC-4BA8-8018-1A05CB4C7FA3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6FA3A92F-F1FC-4BA8-8018-1A05CB4C7FA3}.Release|Any CPU.Build.0 = Release|Any CPU - {03111D82-30ED-4FDF-A512-87BDC05C6DA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {03111D82-30ED-4FDF-A512-87BDC05C6DA1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {03111D82-30ED-4FDF-A512-87BDC05C6DA1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {03111D82-30ED-4FDF-A512-87BDC05C6DA1}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {C823EC9C-CF20-4437-8B99-72158A6DD113} + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F7CDACE1-C74E-451E-A9C2-ED717BF72C1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7CDACE1-C74E-451E-A9C2-ED717BF72C1C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7CDACE1-C74E-451E-A9C2-ED717BF72C1C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7CDACE1-C74E-451E-A9C2-ED717BF72C1C}.Release|Any CPU.Build.0 = Release|Any CPU + {347A1912-4F7D-419B-A159-6671791568CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {347A1912-4F7D-419B-A159-6671791568CC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {347A1912-4F7D-419B-A159-6671791568CC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {347A1912-4F7D-419B-A159-6671791568CC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/RegexBot/Common/EntityList.cs b/RegexBot/Common/EntityList.cs index 303c068..a09f036 100644 --- a/RegexBot/Common/EntityList.cs +++ b/RegexBot/Common/EntityList.cs @@ -115,8 +115,10 @@ public class EntityList : IEnumerable { /// public bool IsEmpty() => _innerList.Count == 0; + /// public override string ToString() => $"Entity list contains {_innerList.Count} item(s)."; + /// public IEnumerator GetEnumerator() => _innerList.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/RegexBot/Common/EntityName.cs b/RegexBot/Common/EntityName.cs index 022305b..3407f87 100644 --- a/RegexBot/Common/EntityName.cs +++ b/RegexBot/Common/EntityName.cs @@ -50,7 +50,7 @@ public class EntityName { input = input[1..]; // Remove prefix // Input contains ID/Label separator? - int separator = input.IndexOf("::"); + var separator = input.IndexOf("::"); if (separator != -1) { Name = input[(separator + 2)..]; if (ulong.TryParse(input.AsSpan(0, separator), out var parseOut)) { @@ -93,7 +93,7 @@ public class EntityName { /// Returns a string representation of this item in proper EntityName format. /// public override string ToString() { - char pf = Prefix(Type); + var pf = Prefix(Type); if (Id.HasValue && Name != null) return $"{pf}{Id.Value}::{Name}"; @@ -109,14 +109,14 @@ public class EntityName { /// /// The guild in which to search for the role. /// - /// Specifies if this EntityName instance should keep the snowflake ID of the - /// corresponding role found in this guild, if it is not already known by this instance. + /// Specifies if this EntityName instance should cache the snowflake ID of the + /// corresponding role found in this guild if it is not already known by this instance. /// public SocketRole? FindRoleIn(SocketGuild guild, bool updateMissingID = false) { if (Type != EntityType.Role) throw new ArgumentException("This EntityName instance must correspond to a Role."); - bool dirty = false; // flag for updating ID if possible regardless of updateMissingId setting + var dirty = false; // flag for updating ID if possible regardless of updateMissingId setting if (Id.HasValue) { var role = guild.GetRole(Id.Value); if (role != null) return role; @@ -134,14 +134,14 @@ public class EntityName { /// /// The guild in which to search for the user. /// - /// Specifies if this EntityName instance should keep the snowflake ID of the - /// corresponding user found in this guild, if it is not already known by this instance. + /// Specifies if this EntityName instance should cache the snowflake ID of the + /// corresponding user found in this guild if it is not already known by this instance. /// public SocketGuildUser? FindUserIn(SocketGuild guild, bool updateMissingID = false) { if (Type != EntityType.User) throw new ArgumentException("This EntityName instance must correspond to a User."); - bool dirty = false; // flag for updating ID if possible regardless of updateMissingId setting + var dirty = false; // flag for updating ID if possible regardless of updateMissingId setting if (Id.HasValue) { var user = guild.GetUser(Id.Value); if (user != null) return user; @@ -159,14 +159,14 @@ public class EntityName { /// /// The guild in which to search for the channel. /// - /// Specifies if this EntityName instance should keep the snowflake ID of the - /// corresponding channel found in this guild, if it is not already known by this instance. + /// Specifies if this EntityName instance should cache the snowflake ID of the + /// corresponding channel found in this guild if it is not already known by this instance. /// public SocketTextChannel? FindChannelIn(SocketGuild guild, bool updateMissingID = false) { if (Type != EntityType.Channel) throw new ArgumentException("This EntityName instance must correspond to a Channel."); - bool dirty = false; // flag for updating ID if possible regardless of updateMissingId setting + var dirty = false; // flag for updating ID if possible regardless of updateMissingId setting if (Id.HasValue) { var channel = guild.GetTextChannel(Id.Value); if (channel != null) return channel; diff --git a/RegexBot/RegexbotModule.cs b/RegexBot/RegexbotModule.cs index 2a6fb16..bf4ccb2 100644 --- a/RegexBot/RegexbotModule.cs +++ b/RegexBot/RegexbotModule.cs @@ -71,7 +71,8 @@ public abstract class RegexbotModule { /// /// Emits a log message to the bot console that is associated with the specified guild. /// - /// /// The log message to send. Multi-line messages are acceptable. + /// The guld for which this log message is associated with. + /// The log message to send. Multi-line messages are acceptable. protected void Log(SocketGuild guild, string? message) { var gname = guild.Name ?? $"Guild ID {guild.Id}"; Bot._svcLogging.DoLog(false, $"{Name}] [{gname}", message);