コード例 #1
0
ファイル: StatusModule.cs プロジェクト: oliver4888/OliBot
        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();
        }
コード例 #2
0
ファイル: StatusModule.cs プロジェクト: oliver4888/OliBot
 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");
     }
 }