Refactoring Settings.cs

This commit is contained in:
BruceChen 2022-10-05 15:02:30 +08:00
parent f16b1c118b
commit 16c1d1fd77
59 changed files with 3425 additions and 2180 deletions

View file

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Text;
using Tomlet.Attributes;
namespace MinecraftClient.ChatBots
{
@ -10,28 +11,34 @@ namespace MinecraftClient.ChatBots
public class PlayerListLogger : ChatBot
{
private int count;
private readonly int timeping;
private readonly string file;
public static Configs Config = new();
/// <summary>
/// This bot sends a /list command every X seconds and save the result.
/// </summary>
/// <param name="pingparam">Time amount between each list ping (10 = 1s, 600 = 1 minute, etc.)</param>
public PlayerListLogger(int pingparam, string filetosavein)
[TomlDoNotInlineObject]
public class Configs
{
count = 0;
file = filetosavein;
timeping = pingparam;
if (timeping < 10) { timeping = 10; } //To avoid flooding
[NonSerialized]
private const string BotName = "PlayerListLogger";
public bool Enabled = false;
public string File = "playerlog.txt";
[TomlInlineComment("$config.ChatBot.PlayerListLogger.Delay$")]
public int Delay = 600;
public void OnSettingUpdate()
{
if (Delay < 10)
Delay = 10;
}
}
private int count = 0;
public override void Update()
{
count++;
if (count == timeping)
if (count == Config.Delay)
{
DateTime now = DateTime.Now;
@ -40,7 +47,7 @@ namespace MinecraftClient.ChatBots
StringBuilder sb = new();
sb.AppendLine(string.Format("[{0}/{1}/{2} {3}:{4}]", now.Year, now.Month, now.Day, now.Hour, now.Minute));
sb.AppendLine(string.Join(", ", GetOnlinePlayers())).AppendLine();
System.IO.File.AppendAllText(file, sb.ToString());
System.IO.File.AppendAllText(Settings.Config.AppVar.ExpandVars(Config.File), sb.ToString());
count = 0;
}