mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Fixed a CommandAttributeGenerator crash
This commit is contained in:
@@ -75,7 +75,7 @@ public class CmdAttribute : System.Attribute
|
|||||||
static (node, _) => node is MethodDeclarationSyntax { AttributeLists.Count: > 0 },
|
static (node, _) => node is MethodDeclarationSyntax { AttributeLists.Count: > 0 },
|
||||||
static (ctx, cancel) => Transform(ctx, cancel))
|
static (ctx, cancel) => Transform(ctx, cancel))
|
||||||
.Where(static m => m is not null)
|
.Where(static m => m is not null)
|
||||||
.Where(static m => m!.ChildTokens().Any(static x => x.IsKind(SyntaxKind.PublicKeyword)));
|
.Where(static m => m?.ChildTokens().Any(static x => x.IsKind(SyntaxKind.PublicKeyword)) ?? false);
|
||||||
|
|
||||||
var compilationMethods = context.CompilationProvider.Combine(methods.Collect());
|
var compilationMethods = context.CompilationProvider.Combine(methods.Collect());
|
||||||
|
|
||||||
@@ -167,8 +167,14 @@ public class CmdAttribute : System.Attribute
|
|||||||
{
|
{
|
||||||
if (cancel.IsCancellationRequested)
|
if (cancel.IsCancellationRequested)
|
||||||
return new Collection<FileModel>();
|
return new Collection<FileModel>();
|
||||||
|
|
||||||
|
if (group is null)
|
||||||
|
continue;
|
||||||
|
|
||||||
var elems = group.ToList();
|
var elems = group.ToList();
|
||||||
|
if (elems.Count is 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
var model = new FileModel(
|
var model = new FileModel(
|
||||||
methods: elems,
|
methods: elems,
|
||||||
ns: elems[0].Namespace,
|
ns: elems[0].Namespace,
|
||||||
@@ -292,15 +298,17 @@ public class CmdAttribute : System.Attribute
|
|||||||
|
|
||||||
private static MethodDeclarationSyntax? Transform(GeneratorSyntaxContext ctx, CancellationToken cancel)
|
private static MethodDeclarationSyntax? Transform(GeneratorSyntaxContext ctx, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
var methodDecl = (MethodDeclarationSyntax)ctx.Node;
|
var methodDecl = ctx.Node as MethodDeclarationSyntax;
|
||||||
|
if (methodDecl is null)
|
||||||
|
return default;
|
||||||
|
|
||||||
foreach (var attListSyntax in methodDecl.AttributeLists)
|
foreach (var attListSyntax in methodDecl.AttributeLists)
|
||||||
{
|
{
|
||||||
foreach (var attSyntax in attListSyntax.Attributes)
|
foreach (var attSyntax in attListSyntax.Attributes)
|
||||||
{
|
{
|
||||||
if (cancel.IsCancellationRequested)
|
if (cancel.IsCancellationRequested)
|
||||||
return default;
|
return default;
|
||||||
|
|
||||||
var symbol = ctx.SemanticModel.GetSymbolInfo(attSyntax).Symbol;
|
var symbol = ctx.SemanticModel.GetSymbolInfo(attSyntax).Symbol;
|
||||||
if (symbol is not IMethodSymbol attSymbol)
|
if (symbol is not IMethodSymbol attSymbol)
|
||||||
continue;
|
continue;
|
||||||
|
@@ -62,6 +62,7 @@ public partial class NadekoExpressions : NadekoModule<NadekoExpressionsService>
|
|||||||
|
|
||||||
var ex = await _service.EditAsync(ctx.Guild?.Id, id, message);
|
var ex = await _service.EditAsync(ctx.Guild?.Id, id, message);
|
||||||
if (ex is not null)
|
if (ex is not null)
|
||||||
|
{
|
||||||
await ctx.Channel.EmbedAsync(_eb.Create()
|
await ctx.Channel.EmbedAsync(_eb.Create()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle(GetText(strs.edited_cust_react))
|
.WithTitle(GetText(strs.edited_cust_react))
|
||||||
@@ -69,6 +70,7 @@ public partial class NadekoExpressions : NadekoModule<NadekoExpressionsService>
|
|||||||
.AddField(GetText(strs.trigger), ex.Trigger)
|
.AddField(GetText(strs.trigger), ex.Trigger)
|
||||||
.AddField(GetText(strs.response),
|
.AddField(GetText(strs.response),
|
||||||
message.Length > 1024 ? GetText(strs.redacted_too_long) : message));
|
message.Length > 1024 ? GetText(strs.redacted_too_long) : message));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
await ReplyErrorLocalizedAsync(strs.edit_fail);
|
await ReplyErrorLocalizedAsync(strs.edit_fail);
|
||||||
}
|
}
|
||||||
@@ -140,12 +142,14 @@ public partial class NadekoExpressions : NadekoModule<NadekoExpressionsService>
|
|||||||
var ex = await _service.DeleteAsync(ctx.Guild?.Id, id);
|
var ex = await _service.DeleteAsync(ctx.Guild?.Id, id);
|
||||||
|
|
||||||
if (ex is not null)
|
if (ex is not null)
|
||||||
|
{
|
||||||
await ctx.Channel.EmbedAsync(_eb.Create()
|
await ctx.Channel.EmbedAsync(_eb.Create()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle(GetText(strs.deleted))
|
.WithTitle(GetText(strs.deleted))
|
||||||
.WithDescription($"#{id}")
|
.WithDescription($"#{id}")
|
||||||
.AddField(GetText(strs.trigger), ex.Trigger.TrimTo(1024))
|
.AddField(GetText(strs.trigger), ex.Trigger.TrimTo(1024))
|
||||||
.AddField(GetText(strs.response), ex.Response.TrimTo(1024)));
|
.AddField(GetText(strs.response), ex.Response.TrimTo(1024)));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
await ReplyErrorLocalizedAsync(strs.no_found_id);
|
await ReplyErrorLocalizedAsync(strs.no_found_id);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user