38
Service/BotPassiveMsgHandler.cs
Normal file
38
Service/BotPassiveMsgHandler.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user