Skip to content

Commit

Permalink
feat: 新增内置fsprocess模块
Browse files Browse the repository at this point in the history
style: 更改代码格式
  • Loading branch information
Zaitonn committed Dec 8, 2024
1 parent 8b09e77 commit 3d22f40
Show file tree
Hide file tree
Showing 235 changed files with 1,201 additions and 832 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ dotnet_code_quality.enable_platform_analyzer_on_pre_net5_target = false
dotnet_diagnostic.CS1416.severity = none

# Organize usings
dotnet_separate_import_directive_groups = true
dotnet_sort_system_directives_first = true
file_header_template = unset

Expand Down
2 changes: 1 addition & 1 deletion src/Serein.Cli/Models/CommandChildrenAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public class CommandChildrenAttribute(string command, string description) : Attr
{
public string Command { get; } = command;
public string Description { get; } = description;
}
}
2 changes: 0 additions & 2 deletions src/Serein.Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using System.CommandLine;
using System.CommandLine.Parsing;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using Serein.Cli.Services;
using Serein.Cli.Services.Interaction;
using Serein.Cli.Services.Interaction.Handlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using Serein.Core.Models.Server;
using Serein.Core.Services.Servers;

namespace Serein.Cli.Services.Interaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

using PrettyPrompt.Completion;
using PrettyPrompt.Highlighting;

using Serein.Cli.Models;
using Serein.Cli.Services.Interaction.Handlers;
using Serein.Core.Models.Plugins;
using Serein.Core.Models.Plugins.Js;
using Serein.Core.Models.Server;
using Serein.Core.Services.Servers;

namespace Serein.Cli.Services.Interaction;
Expand All @@ -35,18 +32,15 @@ public partial class CommandPromptCallbacks
private IEnumerable<CompletionItem> GetServerCompletionItem()
{
return _serverManager.Servers.Select(
(kv) =>
new CompletionItem(kv.Key, getExtendedDescription: (_) => GetDescription(kv))
(kv) => new CompletionItem(kv.Key, getExtendedDescription: (_) => GetDescription(kv))
);

static Task<FormattedString> GetDescription(KeyValuePair<string, Server> kv)
{
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine(kv.Value.Configuration.Name);
stringBuilder.AppendLine();
stringBuilder.AppendLine(
"状态:" + (kv.Value.Status ? "运行中" : "已停止")
);
stringBuilder.AppendLine("状态:" + (kv.Value.Status ? "运行中" : "已停止"));
stringBuilder.AppendLine(
"启动命令行:"
+ kv.Value.Configuration.FileName
Expand Down Expand Up @@ -77,8 +71,7 @@ private IEnumerable<CompletionItem> GetPluginIdCompletionItem()
}

return dictionary.Select(
(kv) =>
new CompletionItem(kv.Key, getExtendedDescription: (_) => GetDescription(kv))
(kv) => new CompletionItem(kv.Key, getExtendedDescription: (_) => GetDescription(kv))
);

static Task<FormattedString> GetDescription(KeyValuePair<string, IPlugin> kv)
Expand All @@ -91,7 +84,7 @@ static Task<FormattedString> GetDescription(KeyValuePair<string, IPlugin> kv)
stringBuilder.AppendLine($"描述:{kv.Value.Info.Description}");
stringBuilder.AppendLine(
$" 作者:{string.Join(',', kv.Value.Info.Authors.Select(author => author.ToString()))}"
);
);
return Task.FromResult(
new FormattedString(
stringBuilder.ToString(),
Expand Down
6 changes: 2 additions & 4 deletions src/Serein.Cli/Services/Interaction/CommandPromptCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using PrettyPrompt;
using PrettyPrompt.Completion;
using PrettyPrompt.Documents;

using Serein.Core.Services.Plugins.Js;
using Serein.Core.Services.Plugins.Net;
using Serein.Core.Services.Servers;
Expand Down Expand Up @@ -76,8 +74,8 @@ .. _pluginSubcommnads
);

case "plugin"
when args.Length == 3
&& args[1].Equals("disable", StringComparison.InvariantCultureIgnoreCase):
when args.Length == 3
&& args[1].Equals("disable", StringComparison.InvariantCultureIgnoreCase):
return Task.FromResult<IReadOnlyList<CompletionItem>>(
[
.. GetPluginIdCompletionItem()
Expand Down
7 changes: 2 additions & 5 deletions src/Serein.Cli/Services/Interaction/CommandProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Extensions.DependencyInjection;

using PrettyPrompt.Completion;
using PrettyPrompt.Highlighting;

using Serein.Cli.Models;
using Serein.Cli.Services.Interaction.Handlers;
using Serein.Core;
Expand Down Expand Up @@ -92,8 +89,8 @@ Type type
foreach (var child in childrenAttributes)
{
stringBuilder.AppendLine(
$" ▫ {nameAttribute.RootCommand} {child.Command} {child.Description}"
);
$" ▫ {nameAttribute.RootCommand} {child.Command} {child.Description}"
);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;

using Serein.Cli.Models;

namespace Serein.Cli.Services.Interaction.Handlers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;

using Microsoft.Extensions.Logging;

using Serein.Cli.Models;
using Serein.Core.Services.Network.Connection;

Expand Down
9 changes: 5 additions & 4 deletions src/Serein.Cli/Services/Interaction/Handlers/ExitHandler.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System.Collections.Generic;
using System.Linq;

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using Serein.Cli.Models;
using Serein.Core.Services.Servers;

namespace Serein.Cli.Services.Interaction.Handlers;

[CommandName("exit", "退出")]
[CommandDescription(["停止所有服务并退出Serein.Cli"])]
public sealed class ExitHandler(IHost host, ILogger<ExitHandler> logger, ServerManager serverManager)
: CommandHandler
public sealed class ExitHandler(
IHost host,
ILogger<ExitHandler> logger,
ServerManager serverManager
) : CommandHandler
{
private readonly IHost _host = host;
private readonly ILogger<ExitHandler> _logger = logger;
Expand Down
2 changes: 0 additions & 2 deletions src/Serein.Cli/Services/Interaction/Handlers/HelpHandler.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

using Serein.Cli.Models;

namespace Serein.Cli.Services.Interaction.Handlers;
Expand Down
10 changes: 6 additions & 4 deletions src/Serein.Cli/Services/Interaction/Handlers/PluginHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Extensions.Logging;

using Serein.Cli.Models;
using Serein.Core.Models.Plugins;
using Serein.Core.Services.Plugins;
Expand Down Expand Up @@ -35,7 +33,9 @@ public override void Invoke(IReadOnlyList<string> args)
{
if (args.Count == 1)
{
throw new InvalidArgumentException("缺少参数。可用值:\"reload\"\"list\"\"disable\"");
throw new InvalidArgumentException(
"缺少参数。可用值:\"reload\"\"list\"\"disable\""
);
}

switch (args[1].ToLowerInvariant())
Expand Down Expand Up @@ -96,7 +96,9 @@ public override void Invoke(IReadOnlyList<string> args)
break;

default:
throw new InvalidArgumentException("未知的参数。可用值:\"reload\"\"list\"\"disable\"");
throw new InvalidArgumentException(
"未知的参数。可用值:\"reload\"\"list\"\"disable\""
);
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/Serein.Cli/Services/Interaction/Handlers/ServerHandler.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Extensions.Logging;

using Serein.Cli.Models;
using Serein.Core.Services.Data;
using Serein.Core.Services.Servers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Collections.Generic;

using Microsoft.Extensions.Logging;

using Serein.Cli.Models;
using Serein.Core;

Expand Down
2 changes: 0 additions & 2 deletions src/Serein.Cli/Services/Interaction/InputHandler.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;

using Microsoft.Extensions.Logging;

using Serein.Cli.Models;

namespace Serein.Cli.Services.Interaction;
Expand Down
7 changes: 2 additions & 5 deletions src/Serein.Cli/Services/Interaction/InputLoopService.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using PrettyPrompt;
using PrettyPrompt.Highlighting;

using Serein.Cli.Utils;
using Serein.Core.Services.Data;
using Serein.Core.Services.Servers;
using Serein.Core.Utils.Extensions;
using Serein.Core.Utils;
using Serein.Cli.Utils;
using Serein.Core.Utils.Extensions;

namespace Serein.Cli.Services.Interaction;

Expand Down
2 changes: 0 additions & 2 deletions src/Serein.Cli/Services/Interaction/ServerSwitcher.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Linq;

using Microsoft.Extensions.Logging;

using Serein.Core.Models.Server;
using Serein.Core.Services.Data;
using Serein.Core.Services.Servers;
Expand Down
6 changes: 3 additions & 3 deletions src/Serein.Cli/Services/Loggers/CliLogger.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;

using Microsoft.Extensions.Logging;

using Serein.Cli.Utils;
using Serein.Core.Utils.Extensions;

Expand Down Expand Up @@ -45,7 +43,9 @@ public void Log<TState>(

if (exception != null)
{
text += Environment.NewLine + (EnableDebug ? exception.ToString() : exception.GetDetailString());
text +=
Environment.NewLine
+ (EnableDebug ? exception.ToString() : exception.GetDetailString());
}

CliConsole.WriteLine(logLevel, $"[{_name}] {text}");
Expand Down
1 change: 0 additions & 1 deletion src/Serein.Cli/Services/Loggers/CliLoggerProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;

using Microsoft.Extensions.Logging;

namespace Serein.Cli.Services.Loggers;
Expand Down
1 change: 0 additions & 1 deletion src/Serein.Cli/Services/Loggers/ConnectionLogger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;

using Serein.Core.Models.Output;

namespace Serein.Cli.Services.Loggers;
Expand Down
1 change: 0 additions & 1 deletion src/Serein.Cli/Services/Loggers/PluginLogger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;

using Serein.Cli.Utils;
using Serein.Core.Models.Output;

Expand Down
2 changes: 0 additions & 2 deletions src/Serein.Cli/Services/TitleUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Extensions.Hosting;

using Serein.Core.Services.Commands;
using Serein.Core.Services.Data;

Expand Down
1 change: 0 additions & 1 deletion src/Serein.Cli/Utils/CliConsole.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Linq;

using Microsoft.Extensions.Logging;

namespace Serein.Cli.Utils;
Expand Down
8 changes: 4 additions & 4 deletions src/Serein.Cli/Utils/CommandLineParserBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
using System.CommandLine.Invocation;
using System.CommandLine.Parsing;
using System.Text;

using Sentry;

using Serein.Core.Utils;

namespace Serein.Cli.Utils;
Expand All @@ -20,7 +18,9 @@ public static Parser Build(Action mainMethod)

rootCommnad.AddOption(new Option<bool>("--debug", "启用调试输出"));
rootCommnad.AddOption(new Option<bool>("--log", "启用日志模式"));
rootCommnad.AddOption(new Option<bool>("--no-color", "禁用控制台彩色输出(服务器输出不受影响)"));
rootCommnad.AddOption(
new Option<bool>("--no-color", "禁用控制台彩色输出(服务器输出不受影响)")
);

return new CommandLineBuilder(rootCommnad)
.UseExceptionHandler(OnException)
Expand Down Expand Up @@ -71,4 +71,4 @@ private static void OnException(Exception e, InvocationContext? context)
context.ExitCode = e.HResult;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Serein.Core/Models/Bindings/BindingFailureException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ namespace Serein.Core.Models.Bindings;
/// <summary>
/// 绑定失败异常
/// </summary>
public class BindingFailureException(string message) : Exception(message);
public class BindingFailureException(string message) : Exception(message);
8 changes: 6 additions & 2 deletions src/Serein.Core/Models/Bindings/BindingRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ public class BindingRecord

public string ShownName { get; set; } = string.Empty;

public DateTime Time { get => _time; init => _time = value; }
public DateTime Time
{
get => _time;
init => _time = value;
}

internal void Update()
{
_time = DateTime.Now;
}
}
}
2 changes: 0 additions & 2 deletions src/Serein.Core/Models/Commands/CommandContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Collections.Generic;

using Serein.Core.Models.Network.Connection.OneBot.Packets;

using RegexMatch = System.Text.RegularExpressions.Match;

namespace Serein.Core.Models.Commands;
Expand Down
Loading

0 comments on commit 3d22f40

Please sign in to comment.