38 lines
1.5 KiB
C#
38 lines
1.5 KiB
C#
using Debugger;
|
|
using Lagrange.Core.Common.Interface.Api;
|
|
using Lagrange.Core.Event;
|
|
using Lagrange.Core.Message;
|
|
using Shrink.Config;
|
|
|
|
namespace Shrink.Service;
|
|
|
|
public class BotPassiveMsgHandler
|
|
{
|
|
private static readonly Lazy<BotPassiveMsgHandler> _instance = new(() => new BotPassiveMsgHandler());
|
|
public static BotPassiveMsgHandler Instance => _instance.Value;
|
|
public EventInvoker Invoker { get; } = BotService.Instance.Client!.Invoker;
|
|
|
|
public Task Init()
|
|
{
|
|
Invoker.OnGroupMessageReceived += async (context, @event) =>
|
|
{
|
|
if (!@event.Chain.ToPreviewText().StartsWith("/switchlevel")) return;
|
|
var temp = @event.Chain.ToPreviewText()[("/switchlevel".Length + 1)..];
|
|
Configuration.Instance.Config = temp switch
|
|
{
|
|
"debug" => new Config.Config(LogLevel.Debug),
|
|
"info" => new Config.Config(LogLevel.Info),
|
|
"verbose" => new Config.Config(LogLevel.Verbose),
|
|
"warn" => new Config.Config(LogLevel.Warn),
|
|
"error" => new Config.Config(LogLevel.Error),
|
|
"fatal" => new Config.Config(LogLevel.Fatal),
|
|
_ => Configuration.Instance.Config
|
|
};
|
|
await Configuration.Instance.Save();
|
|
var chain = MessageBuilder.Group((uint)@event.Chain.GroupUin!)
|
|
.Text($"已将日志输出级别调整为{Configuration.Instance.Config.LogLevel}");
|
|
await context.SendMessage(chain.Build());
|
|
};
|
|
return Task.CompletedTask;
|
|
}
|
|
} |