public StatusModule(ILogger <StatusModule> logger, IBotCoreModule botCoreModule) { _logger = logger; _botCoreModule = botCoreModule; _botCoreModule.CommandHandler.RegisterCommands <StatusCommands>(); _botCoreModule.DiscordClient.Ready += async(client, e) => await SetRandomStatus(); _configFile = Path.Combine(Environment.CurrentDirectory, _statusConfigFileName); if (!File.Exists(_configFile)) { _logger.LogInformation($"{nameof(StatusModule)}: No config file found. Creating default config at {_configFile}"); StatusConfig = new StatusModuleConfig { Mode = StatusMode.Automatic }; #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed AddStatus(ActivityType.ListeningTo, "Rick Astley", false); AddStatus(ActivityType.Playing, "Minecraft"); } else { LoadConfig(); } #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed StatusTimer.Elapsed += async(object sender, ElapsedEventArgs e) => { await SetRandomStatus(); }; StatusTimer.Start(); }
internal static async Task LoadConfig() { try { using FileStream fs = File.OpenRead(_configFile); StatusConfig = await JsonSerializer.DeserializeAsync <StatusModuleConfig>(fs); } catch (Exception ex) { _logger.LogError(ex, $"Error loading {nameof(StatusModule)} config"); } }