Пример #1
0
        public async Task <IActionResult> SaveAsync([FromBody] ChatClientsSettingsModel model)
        {
            if (!model.Client.Equals("discord", System.StringComparison.InvariantCultureIgnoreCase))
            {
                return(BadRequest("Invalid client was selected"));
            }

            _chatClientsSettings.Discord.BotToken      = model.BotToken.Trim();
            _chatClientsSettings.Discord.ClientId      = model.ClientId;
            _chatClientsSettings.Discord.StatusMessage = model.StatusMessage.Trim();
            _chatClientsSettings.Discord.TvShowRoles   = (model.TvShowRoles ?? Array.Empty <string>()).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray();
            _chatClientsSettings.Discord.MovieRoles    = (model.MovieRoles ?? Array.Empty <string>()).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray();
            _chatClientsSettings.Discord.EnableRequestsThroughDirectMessages = model.EnableRequestsThroughDirectMessages;
            _chatClientsSettings.Discord.MonitoredChannels = (model.MonitoredChannels ?? Array.Empty <string>()).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray();

            _chatClientsSettings.Discord.AutomaticallyNotifyRequesters = model.AutomaticallyNotifyRequesters;
            _chatClientsSettings.Discord.NotificationMode     = model.NotificationMode;
            _chatClientsSettings.Discord.NotificationChannels = (model.NotificationChannels ?? Array.Empty <string>()).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray();;
            _chatClientsSettings.Discord.AutomaticallyPurgeCommandMessages = model.AutomaticallyPurgeCommandMessages;
            _chatClientsSettings.Discord.DisplayHelpCommandInDMs           = model.DisplayHelpCommandInDMs;

            _botClientsSettings.Client        = model.Client;
            _botClientsSettings.CommandPrefix = model.CommandPrefix.Trim();

            ChatClientsSettingsRepository.Update(_botClientsSettings, _chatClientsSettings);

            return(Ok(new { ok = true }));
        }
Пример #2
0
        public async Task <IActionResult> SaveAsync([FromBody] ChatClientsSettingsModel model)
        {
            if (!model.Client.Equals("discord", System.StringComparison.InvariantCultureIgnoreCase))
            {
                return(BadRequest("Invalid client was selected"));
            }

            if (model.TvShowRoles.Any(x => !ulong.TryParse(x, System.Globalization.NumberStyles.Integer, null, out _)))
            {
                return(BadRequest("Invalid tv show roles, please make sure to enter the discord role ids."));
            }

            if (model.MovieRoles.Any(x => !ulong.TryParse(x, System.Globalization.NumberStyles.Integer, null, out _)))
            {
                return(BadRequest("Invalid movie roles, please make sure to enter the discord role ids."));
            }

            if (model.NotificationChannels.Any(x => !ulong.TryParse(x, System.Globalization.NumberStyles.Integer, null, out _)))
            {
                return(BadRequest("Invalid notification channels, please make sure to enter the discord channel ids."));
            }

            if (model.MonitoredChannels.Any(x => !ulong.TryParse(x, System.Globalization.NumberStyles.Integer, null, out _)))
            {
                return(BadRequest("Invalid monitored channels channels, please make sure to enter the monitored channel ids."));
            }

            _chatClientsSettings.Discord.BotToken      = model.BotToken.Trim();
            _chatClientsSettings.Discord.ClientId      = model.ClientId;
            _chatClientsSettings.Discord.StatusMessage = model.StatusMessage.Trim();
            _chatClientsSettings.Discord.TvShowRoles   = (model.TvShowRoles ?? Array.Empty <string>()).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray();
            _chatClientsSettings.Discord.MovieRoles    = (model.MovieRoles ?? Array.Empty <string>()).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray();
            _chatClientsSettings.Discord.EnableRequestsThroughDirectMessages = model.EnableRequestsThroughDirectMessages;
            _chatClientsSettings.Discord.MonitoredChannels = (model.MonitoredChannels ?? Array.Empty <string>()).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray();

            _chatClientsSettings.Discord.AutomaticallyNotifyRequesters = model.AutomaticallyNotifyRequesters;
            _chatClientsSettings.Discord.NotificationMode     = model.NotificationMode;
            _chatClientsSettings.Discord.NotificationChannels = (model.NotificationChannels ?? Array.Empty <string>()).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray();;
            _chatClientsSettings.Discord.AutomaticallyPurgeCommandMessages = model.AutomaticallyPurgeCommandMessages;
            _chatClientsSettings.Language = model.Language;

            _botClientsSettings.Client = model.Client;

            ChatClientsSettingsRepository.Update(_botClientsSettings, _chatClientsSettings);

            return(Ok(new { ok = true }));
        }
Пример #3
0
        public async Task <IActionResult> SaveAsync([FromBody] ChatClientsSettingsModel model)
        {
            if (!model.Client.Equals("discord", System.StringComparison.InvariantCultureIgnoreCase))
            {
                return(BadRequest("Invalid client was selected"));
            }

            _chatClientsSettings.Discord.BotToken      = model.BotToken.Trim();
            _chatClientsSettings.Discord.ClientId      = model.ClientId;
            _chatClientsSettings.Discord.StatusMessage = model.StatusMessage.Trim();
            _chatClientsSettings.Discord.EnableDirectMessageSupport = model.EnableDirectMessageSupport;

            _botClientsSettings.Client            = model.Client;
            _botClientsSettings.MonitoredChannels = model.MonitoredChannels.Trim();
            _botClientsSettings.CommandPrefix     = model.CommandPrefix.Trim();

            ChatClientsSettingsRepository.Update(_botClientsSettings, _chatClientsSettings);

            return(Ok(new { ok = true }));
        }