public override void OnDisable() { bot = null; canLog = false; counting = false; Info("LogBot has been disabled"); }
public async Task LoadConfig() { await Task.Delay(TimeSpan.FromSeconds(8)); string path = $"{this.PluginDirectory}{Path.DirectorySeparatorChar}{this.Server.Port}{Path.DirectorySeparatorChar}config.json"; try { settings = JsonConvert.DeserializeObject <Settings>(File.ReadAllText(path, Encoding.UTF8)); counting = true; } catch (Exception e) { if (!Directory.Exists(this.PluginDirectory)) { Directory.CreateDirectory(this.PluginDirectory); this.Warn($"Go to '{path}' and change webhook url!"); } if (!Directory.Exists(this.PluginDirectory + Path.DirectorySeparatorChar + this.Server.Port)) { Directory.CreateDirectory(this.PluginDirectory + Path.DirectorySeparatorChar + this.Server.Port); } if (!File.Exists(path)) { File.Create(path).Close(); if (File.Exists($"{this.PluginDirectory}{Path.DirectorySeparatorChar}config.json")) { settings = JsonConvert.DeserializeObject <Settings>(File.ReadAllText($"{this.PluginDirectory}{Path.DirectorySeparatorChar}config.json", Encoding.UTF8)); this.Warn($"Created a file with port {this.Server.Port} from config"); } File.WriteAllText(path, JsonConvert.SerializeObject(settings), Encoding.UTF8); } else { this.Error("Can't read plugin config, make sure your shared config is correct!"); this.Error("Reason: " + e.Message); return; } } if (!string.IsNullOrWhiteSpace(settings.webhook_url)) { bot = new BotHandler(settings.webhook_url); } this.AddEventHandlers(this); if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"{Path.DirectorySeparatorChar}SCP Secret Laboratory{Path.DirectorySeparatorChar}ServerLogs{Path.DirectorySeparatorChar}players_log_{this.Server.Port}.json")) { string context = File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"{Path.DirectorySeparatorChar}SCP Secret Laboratory{Path.DirectorySeparatorChar}ServerLogs{Path.DirectorySeparatorChar}players_log_{this.Server.Port}.json", Encoding.UTF8); if (!string.IsNullOrEmpty(context)) { GetKills = JsonConvert.DeserializeObject <List <KillCount> >(context); } } Info("LogBot has started"); }