- Updated changelog

- Updated all projects to .net6
- Added some exception handling to the cmd source generator
This commit is contained in:
Kwoth
2022-02-01 08:52:40 +01:00
parent 2d90ecaa51
commit d31cfcc5a8
7 changed files with 28 additions and 32 deletions

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

View File

@@ -310,7 +310,7 @@ namespace NadekoBot.Coordinator
})
.ToList()
};
var jsonState = JsonSerializer.Serialize(coordState, new ()
var jsonState = JsonSerializer.Serialize(coordState, new JsonSerializerOptions()
{
WriteIndented = true,
});

View File

@@ -1,4 +1,5 @@
#nullable enable
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections.Immutable;
@@ -62,6 +63,9 @@ public class CmdAttribute : System.Attribute
public void Initialize(IncrementalGeneratorInitializationContext context)
{
// #if DEBUG
// SpinWait.SpinUntil(() => Debugger.IsAttached);
// #endif
context.RegisterPostInitializationOutput(static ctx => ctx.AddSource(
"CmdAttribute.g.cs",
SourceText.From(ATTRIBUTE, Encoding.UTF8)));
@@ -90,9 +94,17 @@ public class CmdAttribute : System.Attribute
foreach (var model in models)
{
var source = GetSourceText(model);
ctx.AddSource($"{model.Namespace}.{string.Join(".", model.ClassHierarchy)}.g.cs",
SourceText.From(source, Encoding.UTF8));
var name = $"{model.Namespace}.{string.Join(".", model.ClassHierarchy)}.g.cs";
try
{
Debug.WriteLine($"Writing {name}");
var source = GetSourceText(model);
ctx.AddSource(name, SourceText.From(source, Encoding.UTF8));
}
catch (Exception ex)
{
Debug.WriteLine($"Error writing source file {name}\n" + ex);
}
}
}
@@ -226,25 +238,6 @@ public class CmdAttribute : System.Attribute
return methodModel;
}
// private static IEnumerable<string> GetParams(Compilation compilation, MethodDeclarationSyntax method)
// {
// var semModel = compilation.GetSemanticModel(method.SyntaxTree);
// return method.ParameterList.Parameters.Select(p =>
// {
// var prefix = string.Empty;
//
// var typeSymbol = semModel.GetTypeInfo(p).Type;
//
// if (p.Modifiers.Any(static x => x.IsKind(SyntaxKind.ParamsKeyword)))
// prefix += "params ";
// return prefix + $"{typeSymbol?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)} {p.Identifier.ToString()}";
// });
// // foreach (var param in method.ParameterList.Parameters)
// // {
// // yield return param.ToString();
// // }
// }
//https://github.com/andrewlock/NetEscapades.EnumGenerators/blob/main/src/NetEscapades.EnumGenerators/EnumGenerator.cs
static string? GetNamespace(MethodDeclarationSyntax declarationSyntax)
{
@@ -308,7 +301,7 @@ public class CmdAttribute : System.Attribute
if (cancel.IsCancellationRequested)
return default;
var symbol = ModelExtensions.GetSymbolInfo(ctx.SemanticModel, attSyntax).Symbol;
var symbol = ctx.SemanticModel.GetSymbolInfo(attSyntax).Symbol;
if (symbol is not IMethodSymbol attSymbol)
continue;

View File

@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>
<ItemGroup>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

View File

@@ -23,6 +23,8 @@ public sealed class Bot
public string Mention { get; private set; }
public bool IsReady { get; private set; }
public int ShardId { get; set; }
private readonly IBotCredentials _creds;
private readonly CommandService _commandService;
private readonly DbService _db;
@@ -34,6 +36,7 @@ public sealed class Bot
if (shardId < 0)
throw new ArgumentOutOfRangeException(nameof(shardId));
ShardId = shardId;
_credsProvider = new BotCredsProvider(totalShards);
_creds = _credsProvider.GetCreds();
@@ -64,6 +67,7 @@ public sealed class Bot
#endif
}
public List<ulong> GetCurrentGuildIds()
=> Client.Guilds.Select(x => x.Id).ToList();