From 690b7fe5f1296bd16318664a85cf6da734f9ebd5 Mon Sep 17 00:00:00 2001 From: Wizzy69 Date: Sat, 4 Jun 2022 19:30:08 +0300 Subject: [PATCH] --- EVE_LevelingSystem/Level.cs | 19 +++++++++++++++---- .../LevelingSystemCore/LevelCalculator.cs | 3 ++- EVE_LevelingSystem/Settings.cs | 13 +++++++++++++ PluginManager/Others/Functions.cs | 2 +- 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 EVE_LevelingSystem/Settings.cs diff --git a/EVE_LevelingSystem/Level.cs b/EVE_LevelingSystem/Level.cs index 2d9b6bd..e4d6376 100644 --- a/EVE_LevelingSystem/Level.cs +++ b/EVE_LevelingSystem/Level.cs @@ -8,15 +8,26 @@ namespace EVE_LevelingSystem { internal class Level : DBEvent { - public string name => "Leveling System Event Handler"; - public string description => "The Leveling System Event Handler"; + public string name => "Leveling System Event Handler"; + public string description => "The Leveling System Event Handler"; + internal static Settings globalSettings = new(); - public void Start(DiscordSocketClient client) + public async void Start(DiscordSocketClient client) { Directory.CreateDirectory("./Data/Resources/LevelingSystem"); Config.AddValueToVariables("LevelingSystemPath", "./Data/Resources/LevelingSystem"); + Config.AddValueToVariables("LevelingSystemSettingsFile", "./Data/Resources/LevelingSystemSettings.txt"); + if (!File.Exists(Config.GetValue("LevelingSystemSettingsFile"))) + { + globalSettings = new Settings { TimeToWaitBetweenMessages = 5 }; + await Functions.SaveToJsonFile(Config.GetValue("LevelingSystemSettingsFile"), globalSettings); + } + else + globalSettings = await Functions.ConvertFromJson(Config.GetValue("LevelingSystemSettingsFile")); + + // Console.WriteLine(globalSettings.TimeToWaitBetweenMessages); client.MessageReceived += ClientOnMessageReceived; } @@ -28,7 +39,7 @@ namespace EVE_LevelingSystem if (File.Exists($"{Config.GetValue("LevelingSystemPath")}/{userID}.dat")) { user = await Functions.ConvertFromJson(Config.GetValue("LevelingSystemPath")! + $"/{userID}.dat"); - Console.WriteLine(Config.GetValue("LevelingSystemPath")); + // Console.WriteLine(Config.GetValue("LevelingSystemPath")); if (user.AddEXP()) await arg.Channel.SendMessageAsync($"{arg.Author.Mention} is now level {user.CurrentLevel}"); await Functions.SaveToJsonFile(Config.GetValue("LevelingSystemPath") + $"/{userID}.dat", user); return; diff --git a/EVE_LevelingSystem/LevelingSystemCore/LevelCalculator.cs b/EVE_LevelingSystem/LevelingSystemCore/LevelCalculator.cs index 9df66dc..62c6d1c 100644 --- a/EVE_LevelingSystem/LevelingSystemCore/LevelCalculator.cs +++ b/EVE_LevelingSystem/LevelingSystemCore/LevelCalculator.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using PluginManager; namespace EVE_LevelingSystem.LevelingSystemCore { @@ -44,7 +45,7 @@ namespace EVE_LevelingSystem.LevelingSystemCore new Thread(() => { - int minutesToWait = 0; + int minutesToWait = Level.globalSettings.TimeToWaitBetweenMessages; Thread.Sleep(60000 * minutesToWait); OnWaitingList.Remove(user.userID); } diff --git a/EVE_LevelingSystem/Settings.cs b/EVE_LevelingSystem/Settings.cs new file mode 100644 index 0000000..38a8caa --- /dev/null +++ b/EVE_LevelingSystem/Settings.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EVE_LevelingSystem +{ + public class Settings + { + public int TimeToWaitBetweenMessages { get; set; } + } +} diff --git a/PluginManager/Others/Functions.cs b/PluginManager/Others/Functions.cs index 6eef7e0..5f6fb5f 100644 --- a/PluginManager/Others/Functions.cs +++ b/PluginManager/Others/Functions.cs @@ -264,7 +264,7 @@ namespace PluginManager.Others public static async Task SaveToJsonFile(string file, T Data) { - string jsonText = JsonSerializer.Serialize(Data, typeof(T)); + string jsonText = JsonSerializer.Serialize(Data, typeof(T), new JsonSerializerOptions() { WriteIndented = true }); await File.WriteAllTextAsync(file, jsonText); }