Ejemplo n.º 1
0
        public static string ToTwitterStatus(this ItemLookUpResult.Item item)
        {
            // 트위터는 140자까지 적을 수 있으나, 영문-숫자-특문은 2자당 한칸만을 차지한다.
            // 링크가 23자를 차지하므로 140 - 12 = 128자까지 가능하다.
            string additionalInfo = $" ({item.author} / {item.publisher} / {item.pubDate} / {item.priceStandard}원) ";
            string status         = item.title + additionalInfo;

            if (status.Length > 128)
            {
                // 제목이 긴건가 추가 정보가 긴건가
                int maxTitleLength = 128 - additionalInfo.Length;
                if (maxTitleLength >= 2)
                {
                    // 제목을 적당히 줄임
                    status = item.title.Substring(0, maxTitleLength - 1) + "…" + additionalInfo;
                }
                else
                {
                    // 제목만 표시
                    if (item.title.Length < 128)
                    {
                        status = item.title + " ";
                    }
                    else
                    {
                        // 제목도 길다!
                        status = item.title.Substring(0, 126) + "… ";
                    }
                }
            }
            return(status + Aladin.Utils.UnescapeUrl(item.link));
        }
Ejemplo n.º 2
0
        /// <summary>상품정보 트윗(비동기 처리)</summary>
        private static async Task TweetItemAsync(Tokens tokens, ItemLookUpResult.Item item, CancellationToken cancellationToken)
        {
            var stream = await httpClient.GetStreamAsync(item.hqCover);

            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            var mediaUploadResult = await tokens.Media.UploadAsync(stream, cancellationToken : cancellationToken);

            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            long[] mediaIds       = { mediaUploadResult.MediaId };
            string status         = Twitter.Utils.ToTwitterStatus(item);
            var    statusResponse = await tokens.Statuses.UpdateAsync(status, media_ids : mediaIds, cancellationToken : cancellationToken);
        }
Ejemplo n.º 3
0
        public static BubbleContainer ToBubbleContainer(this ItemLookUpResult.Item item)
        {
            string linkUrl  = Aladin.Utils.UnescapeUrl(item.link);
            string coverUrl = item.hqCover;

            UriTemplateAction linkAction = new UriTemplateAction("상품 페이지로 이동", linkUrl);

            // 이미지
            ImageComponent hero = new ImageComponent(coverUrl);

            hero.Size        = ComponentSize.Full;
            hero.AspectMode  = AspectMode.Cover;
            hero.AspectRatio = AspectRatio._151_1;   // 잘려도 여러개(그래봐야 2개까지지만) 나오는게 낫다고 의견이 나와서
            hero.Action      = linkAction;

            // 바디
            // 부제가 있으면 따로 처리를 해준다.
            string titleStr    = item.title;
            string subTitleStr = item.subInfo.subTitle;

            if (!string.IsNullOrEmpty(subTitleStr))
            {
                int index = titleStr.IndexOf(subTitleStr);
                if (index >= 0)
                {
                    titleStr = titleStr.Substring(0, index - 3);
                }
            }

            // 성인물이면 추가로 표시를 해준다.
            if (item.adult)
            {
                string emoji = char.ConvertFromUtf32(0x1f51e);
                titleStr = emoji + " " + titleStr;
            }

            TextComponent title = new TextComponent(titleStr);

            title.Size   = ComponentSize.Lg;
            title.Weight = Weight.Bold;
            TextComponent subTitle = null;

            if (!string.IsNullOrEmpty(subTitleStr))
            {
                subTitle      = new TextComponent(subTitleStr);
                subTitle.Size = ComponentSize.Sm;
            }
            TextComponent author = new TextComponent(item.author);

            author.Size   = ComponentSize.Sm;
            author.Margin = Spacing.Sm;
            TextComponent publisher = new TextComponent(item.publisher);

            publisher.Size = ComponentSize.Sm;
            TextComponent pubDate = new TextComponent(item.pubDate);

            pubDate.Size = ComponentSize.Sm;
            TextComponent priceStandard = new TextComponent($"정가 {item.priceStandard}원 / ");

            priceStandard.Size = ComponentSize.Sm;
            priceStandard.Flex = 0;
            TextComponent priceSales = new TextComponent($"판매가 {item.priceSales}원 ");

            priceSales.Size   = ComponentSize.Sm;
            priceSales.Weight = Weight.Bold;
            priceSales.Flex   = 0;
            BoxComponent price = new BoxComponent(BoxLayout.Baseline);

            price.Contents.Add(priceStandard);
            price.Contents.Add(priceSales);

            BoxComponent body = new BoxComponent(BoxLayout.Vertical);

            body.Contents.Add(title);
            if (subTitle != null)
            {
                body.Contents.Add(subTitle);
            }
            body.Contents.Add(author);
            body.Contents.Add(publisher);
            body.Contents.Add(pubDate);
            body.Contents.Add(price);
            body.Action = linkAction;

            BubbleContainer container = new BubbleContainer();

            container.Hero = hero;
            container.Body = body;

            return(container);
        }