Exemple #1
0
        public static async Task <int> Set(string?botToken, string?serviceName, bool?usersCanSeeAllUsers, bool?usersCanSeeAllGroups, bool?usersCanSeeGroupDataUsage, bool?usersCanSeeGroupDataLimit, bool?allowChatAssociation, CancellationToken cancellationToken = default)
        {
            var(botConfig, loadBotConfigErrMsg) = await BotConfig.LoadBotConfigAsync(cancellationToken);

            if (loadBotConfigErrMsg is not null)
            {
                Console.WriteLine(loadBotConfigErrMsg);
                return(1);
            }

            if (!string.IsNullOrEmpty(botToken))
            {
                botConfig.BotToken = botToken;
            }
            if (!string.IsNullOrEmpty(serviceName))
            {
                botConfig.ServiceName = serviceName;
            }
            if (usersCanSeeAllUsers is bool canSeeUsers)
            {
                botConfig.UsersCanSeeAllUsers = canSeeUsers;
            }
            if (usersCanSeeAllGroups is bool canSeeGroups)
            {
                botConfig.UsersCanSeeAllGroups = canSeeGroups;
            }
            if (usersCanSeeGroupDataUsage is bool canSeeGroupDataUsage)
            {
                botConfig.UsersCanSeeGroupDataUsage = canSeeGroupDataUsage;
            }
            if (usersCanSeeGroupDataLimit is bool canSeeGroupDataLimit)
            {
                botConfig.UsersCanSeeGroupDataLimit = canSeeGroupDataLimit;
            }
            if (allowChatAssociation is bool allowLinking)
            {
                botConfig.AllowChatAssociation = allowLinking;
            }

            var saveBotConfigErrMsg = await BotConfig.SaveBotConfigAsync(botConfig, cancellationToken);

            if (saveBotConfigErrMsg is not null)
            {
                Console.WriteLine(loadBotConfigErrMsg);
                return(1);
            }

            return(0);
        }