コード例 #1
0
        private LineLiveMessageContext CreateMessageContext(ParseMessage.IMessage message, ParseMessage.IUser sender, string raw, bool isInitialComment)
        {
            LineLiveMessageContext messageContext;

            if (message is ParseMessage.IMessageData comment)
            {
                var user           = GetUser(sender.Id.ToString());
                var isFirstComment = _first.IsFirstComment(user.UserId);
                var m = new LineLiveComment(raw)
                {
                    Text        = comment.Message,
                    IsNgMessage = comment.IsNgMessage,
                    PostedAt    = SitePluginCommon.Utils.UnixtimeToDateTime(comment.SentAt),
                    UserIconUrl = sender.IconUrl,
                    UserId      = sender.Id,
                    DisplayName = sender.DisplayName,
                };
                var metadata = new MessageMetadata(m, _options, _siteOptions, user, this, isFirstComment)
                {
                    IsInitialComment = isInitialComment,
                    SiteContextGuid  = SiteContextGuid,
                };
                var methods = new LineLiveMessageMethods();
                messageContext = new LineLiveMessageContext(m, metadata, methods);
            }
            else if (message is ParseMessage.ILove love)
            {
                var user           = GetUser(sender.Id.ToString());
                var isFirstComment = _first.IsFirstComment(user.UserId);
                var str            = sender.DisplayName + "さんがハートを送りました!";
                var m = new LineLiveItem(raw)
                {
                    CommentItems = Common.MessagePartFactory.CreateMessageItems(str),
                    PostedAt     = SitePluginCommon.Utils.UnixtimeToDateTime(love.SentAt),
                    UserIconUrl  = sender.IconUrl,
                    UserId       = sender.Id,
                    DisplayName  = sender.DisplayName,
                };
                var metadata = new MessageMetadata(m, _options, _siteOptions, user, this, isFirstComment)
                {
                    IsInitialComment = isInitialComment,
                    SiteContextGuid  = SiteContextGuid,
                };
                var methods = new LineLiveMessageMethods();
                messageContext = new LineLiveMessageContext(m, metadata, methods);
            }
            else if (message is ParseMessage.IFollowStartData follow)
            {
                var user           = GetUser(sender.Id.ToString());
                var isFirstComment = _first.IsFirstComment(user.UserId);
                var msg            = sender.DisplayName + "さんがフォローしました!";
                var m = new LineLiveItem(raw)
                {
                    CommentItems = Common.MessagePartFactory.CreateMessageItems(msg),
                    PostedAt     = SitePluginCommon.Utils.UnixtimeToDateTime(follow.FollowedAt),
                    UserIconUrl  = sender.IconUrl,
                    UserId       = sender.Id,
                    DisplayName  = sender.DisplayName,
                };
                var metadata = new MessageMetadata(m, _options, _siteOptions, user, this, isFirstComment)
                {
                    IsInitialComment = isInitialComment,
                    SiteContextGuid  = SiteContextGuid,
                };
                var methods = new LineLiveMessageMethods();
                messageContext = new LineLiveMessageContext(m, metadata, methods);
            }
            else if (message is ParseMessage.IGiftMessage gift)
            {
                var user           = GetUser(sender.Id.ToString());
                var isFirstComment = _first.IsFirstComment(user.UserId);
                if (_loveIconUrlDict.ContainsKey(gift.ItemId))
                {
                    gift.Url = _loveIconUrlDict[gift.ItemId];
                }
                else
                {
                    gift.Url = "";
                }
                List <IMessagePart> messageItems;
                if (gift.ItemId == "limited-love-gift" || string.IsNullOrEmpty(gift.Url))
                {
                    //{"type":"giftMessage","data":{"message":"","type":"LOVE","itemId":"limited-love-gift","quantity":1,"displayName":"limited.love.gift.item","sender":{"id":2903515,"hashedId":"715i4MKqyv","displayName":"上杉The Times","iconUrl":"https://scdn.line-apps.com/obs/0hmNs42D-0MmFOTR9H8JtNNnYQNBY3YzEpNmkpRHdEbQI3LnYxIX97UGIdaVdjKXVjd3ktVGNEP1VjenU1ew/f64x64","hashedIconId":"0hmNs42D-0MmFOTR9H8JtNNnYQNBY3YzEpNmkpRHdEbQI3LnYxIX97UGIdaVdjKXVjd3ktVGNEP1VjenU1ew","isGuest":false,"isBlocked":false},"isNGGift":false,"sentAt":1531445716,"key":"2426265.29035150000000000000","blockedByCms":false}}
                    var msg = sender.DisplayName + "さんがハートで応援ポイントを送りました!";
                    messageItems = new List <IMessagePart> {
                        MessagePartFactory.CreateMessageText(msg)
                    };
                }
                else
                {
                    var msg = sender.DisplayName + "さんが" + gift.Quantity + "コインプレゼントしました!";
                    messageItems = new List <IMessagePart> {
                        MessagePartFactory.CreateMessageText(msg), new MessageImage {
                            Url = gift.Url
                        }
                    };
                }

                var m = new LineLiveItem(raw)
                {
                    CommentItems = messageItems,
                    PostedAt     = SitePluginCommon.Utils.UnixtimeToDateTime(gift.SentAt),
                    UserIconUrl  = sender.IconUrl,
                    UserId       = sender.Id,
                    DisplayName  = sender.DisplayName,
                };
                var metadata = new MessageMetadata(m, _options, _siteOptions, user, this, isFirstComment)
                {
                    IsInitialComment = isInitialComment,
                    SiteContextGuid  = SiteContextGuid,
                };
                var methods = new LineLiveMessageMethods();
                messageContext = new LineLiveMessageContext(m, metadata, methods);
            }
            else
            {
                messageContext = null;
            }
            return(messageContext);
        }
コード例 #2
0
 public LineLiveMessageContext(ILineLiveMessage message, MessageMetadata metadata, IMessageMethods methods)
 {
     Message  = message;
     Metadata = metadata;
     Methods  = methods;
 }