Skip to content

Commit

Permalink
RSS refactor, nyaa rss, test bot nuke command.
Browse files Browse the repository at this point in the history
  • Loading branch information
SquirrelKiev committed Oct 31, 2024
1 parent cf58bdd commit 7764f0b
Show file tree
Hide file tree
Showing 38 changed files with 5,140 additions and 540 deletions.
7 changes: 7 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"dotnet-csharpier"
],
"rollForward": false
},
"strawberryshake.tools": {
"version": "14.0.0",
"commands": [
"dotnet-graphql"
],
"rollForward": false
}
}
}
13 changes: 13 additions & 0 deletions .idea/.idea.Asahi/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.Asahi/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.Asahi/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.Asahi/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Asahi/.graphqlrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"schema": "schema.graphql",
"documents": "**/*.graphql",
"extensions": {
"strawberryShake": {
"name": "AnilistClient",
"namespace": "Asahi",
"url": "https://graphql.anilist.co",
"records": {
"inputs": false,
"entities": false
},
"transportProfiles": [
{
"default": "Http",
"subscription": "WebSocket"
}
]
}
}
}
112 changes: 63 additions & 49 deletions Asahi/Asahi.csproj
Original file line number Diff line number Diff line change
@@ -1,53 +1,67 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ApplicationIcon>Asahi.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CodeHollow.FeedReader" Version="1.2.6" />
<PackageReference Include="Discord.Net" Version="3.16.0" />
<PackageReference Include="EntityFrameworkCore.Sqlite.NodaTime" Version="8.0.1" />
<PackageReference Include="Fergun.Interactive" Version="1.8.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="JsonApiSerializer" Version="2.0.1" />
<!-- Cannot wait for EFC to support 4.10.0 -->
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Npgsql" Version="8.0.4" />
<PackageReference Include="Refit" Version="7.2.1" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.2.1" />
<PackageReference Include="Refit.Newtonsoft.Json" Version="7.2.1" />
<PackageReference Include="Scrutor" Version="4.2.2" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageReference Include="NodaTime" Version="3.1.12" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="8.0.4" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
<PackageReference Include="YamlDotNet" Version="16.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Asahi.Analyzers\Asahi.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<Folder Include="Modules\Statistics\" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ApplicationIcon>Asahi.ico</ApplicationIcon>

<Version>0.0.0</Version>

<Copyright>enonibobble</Copyright>

<!-- not necessary but -->
<RepositoryUrl>https://github.com/SquirrelKiev/Asahi.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>

<SourceControlInformationFeatureSupported>true</SourceControlInformationFeatureSupported>

<PackageReadmeFile>../README.md</PackageReadmeFile>
</PropertyGroup>

<Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
<Exec Command="git describe --long --always --dirty --exclude=* --abbrev=8" ConsoleToMSBuild="True" IgnoreExitCode="False">
<Output PropertyName="SourceRevisionId" TaskParameter="ConsoleOutput" />
</Exec>
</Target>

<ItemGroup>
<PackageReference Include="CodeHollow.FeedReader" Version="1.2.6" />
<PackageReference Include="Discord.Net" Version="3.16.0" />
<PackageReference Include="EntityFrameworkCore.Sqlite.NodaTime" Version="8.0.1" />
<PackageReference Include="Fergun.Interactive" Version="1.8.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="JsonApiSerializer" Version="2.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Npgsql" Version="8.0.5" />
<PackageReference Include="Refit" Version="7.2.1" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.2.1" />
<PackageReference Include="Refit.Newtonsoft.Json" Version="7.2.1" />
<PackageReference Include="Scrutor" Version="5.0.1" />
<PackageReference Include="Serilog" Version="4.0.2" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageReference Include="NodaTime" Version="3.2.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="8.0.10" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
<PackageReference Include="StrawberryShake.Server" Version="14.0.0" />
<PackageReference Include="YamlDotNet" Version="16.1.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Asahi.Analyzers\Asahi.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Asahi/Asahi.csproj.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=database_005Cmodels_005Cseigen/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=modules_005Ccommon/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=modules_005Ccore/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=modules_005Crssatomfeed_005Cmessagegenerators/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=modules_005Crssatomfeed_005Cmodels_005Creddit/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=modules_005Cseigen_005Cautocompletes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=modules_005Cseigen_005Crolemanagement/@EntryIndexedValue">True</s:Boolean>
Expand Down
19 changes: 17 additions & 2 deletions Asahi/Core/BotConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ public class BotConfig

[YamlMember(Description = "The default UserAgent to use when making web requests.")]
public string UserAgent { get; set; } = "AsahiBot/NoSetVersion (https://github.com/SquirrelKiev/Asahi)";

[YamlMember(Description = "The App ID to use for the Wolfram command. Can get one from https://developer.wolframalpha.com/.")]
public string WolframAppId { get; set; } = "";

[YamlMember(Description = "The token of the test bot. This is only used for /bot nuke-test-commands at present. Optional.")]
public string TestingBotToken { get; set; } = "BOT_TOKEN_HERE";

[YamlMember(Description = "Any users in this list are banned from ever making it to highlights.")]
public HashSet<ulong> BannedHighlightsUsers { get; set; } = [];

Expand Down Expand Up @@ -92,7 +96,7 @@ public class BotConfig
}
];

public virtual bool IsValid()
public bool IsValid()
{
try
{
Expand All @@ -103,6 +107,17 @@ public virtual bool IsValid()
Log.Fatal(ex, "Supplied bot token is invalid.");
return false;
}

try
{
if (TestingBotToken != "BOT_TOKEN_HERE")
TokenUtils.ValidateToken(TokenType.Bot, TestingBotToken);
}
catch (Exception ex)
{
Log.Fatal(ex, "Supplied testing bot token is invalid. Set as BOT_TOKEN_HERE if unwanted.");
return false;
}

return true;
}
Expand Down Expand Up @@ -136,4 +151,4 @@ public struct AboutField
/// </summary>
public bool Inline { get; set; }
}
}
}
6 changes: 2 additions & 4 deletions Asahi/Core/BotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ ModSpoilerService mss
"Asahi Webhook";
public CancellationTokenSource cts = new();

public static readonly DiscordRestConfig WebhookRestConfig = new()
{
LogLevel = LogSeverity.Verbose
};
public static readonly DiscordRestConfig WebhookRestConfig =
new() { LogLevel = LogSeverity.Verbose };

protected override async Task ExecuteAsync(CancellationToken cancellationToken)
{
Expand Down
1 change: 1 addition & 0 deletions Asahi/Core/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ protected async Task RunCommand(SocketUserMessage userMessage)
await commandService.ExecuteAsync(context, argPos, services);
}

// TODO: Cache!!!
protected async Task<string> GetPrefix(ISocketMessageChannel? channel)
{
var prefix = GuildConfig.DefaultPrefix;
Expand Down
7 changes: 6 additions & 1 deletion Asahi/Core/CompiledRegex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static partial class CompiledRegex
public static partial Regex RedditFeedRegex();

[GeneratedRegex(@"^[\w-]+$")]
public static partial Regex IsValidId();
public static partial Regex IsValidIdRegex();

[GeneratedRegex(@"^https:\/\/(?:\w*.)?discord.com\/channels\/(?<guild>\d*)\/(?<channel>\d*)\/(?<message>\d*)$")]
public static partial Regex MessageLinkRegex();
Expand All @@ -20,4 +20,9 @@ public static partial class CompiledRegex
// https://regexr.com/3dqa0
[GeneratedRegex(@"^(?:https?:\/\/)?(?:[\da-z\.-]+\.[a-z\.]{2,6}|[\d\.]+)(?:[\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?$", RegexOptions.IgnoreCase)]
public static partial Regex GenericLinkRegex();

[GeneratedRegex("""
href="(https:\/\/nyaa\.si/view/\d+)"
""")]
public static partial Regex NyaaATagRegex();
}
27 changes: 14 additions & 13 deletions Asahi/Database/Models/TrustedId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ namespace Asahi.Database.Models;

public class TrustedId
{
[Flags]
[JsonConverter(typeof(StringEnumConverter))]
public enum TrustedUserPerms
{
None = 0,
WolframPerms = 1,
TrustedUserEditPerms = 2,
StatusPerms = 4,
BotGuildManagementPerms = 8,
CodeExecutionPerms = 16,
}

public const int CommentMaxLength = 200;

[Key]
Expand All @@ -30,4 +18,17 @@ public enum TrustedUserPerms

[JsonIgnore]
public required BotWideConfig BotWideConfig { get; set; }
}
}

[Flags]
[JsonConverter(typeof(StringEnumConverter))]
public enum TrustedUserPerms
{
None = 0,
WolframPerms = 1 << 0,
TrustedUserEditPerms = 1 << 1,
StatusPerms = 1 << 2,
BotGuildManagementPerms = 1 << 3,
CodeExecutionPerms = 1 << 4,
TestCommandNukingPerms = 1 << 5
}
6 changes: 3 additions & 3 deletions Asahi/Modules/BirthdayRoles/BirthdayConfigModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private Task<bool> CommonBirthdayConfig(string? name, ulong guildId,

name = name.ToLowerInvariant();

if (!CompiledRegex.IsValidId().IsMatch(name))
if (!CompiledRegex.IsValidIdRegex().IsMatch(name))
{
return new ConfigChangeResult(false, $"`{name}` is not valid.");
}
Expand Down Expand Up @@ -288,7 +288,7 @@ await CommonConfig(async (context, eb) =>
{
name = name.ToLowerInvariant();

if (!CompiledRegex.IsValidId().IsMatch(name))
if (!CompiledRegex.IsValidIdRegex().IsMatch(name))
{
return new ConfigChangeResult(false, $"`{name}` is not valid.");
}
Expand Down Expand Up @@ -657,7 +657,7 @@ public static async Task<BirthdayConfig> ResolveConfig(BotDbContext context, str

name = name.ToLowerInvariant();

if (!CompiledRegex.IsValidId().IsMatch(name))
if (!CompiledRegex.IsValidIdRegex().IsMatch(name))
{
throw new ConfigException($"`{name}` is not valid.");
}
Expand Down
Loading

0 comments on commit 7764f0b

Please sign in to comment.