コード例 #1
0
 public MildomGift(OnGiftMessage low, GiftItem item) : base(low.Raw)
 {
     GiftName = item.Name;
     //Coins = item.Coins;
     Count    = low.Count;
     PostedAt = low.PostedAt;
     UserId   = low.UserId;
     GiftUrl  = item.Url;
     UserName = low.UserName;
     UserId   = low.UserId;
 }
コード例 #2
0
        private MildomMessageContext CreateMessageContext(IInternalMessage message)
        {
            if (message is OnChatMessage chat)
            {
                var userId   = chat.UserId.ToString();
                var isFirst  = _first.IsFirstComment(userId);
                var user     = GetUser(userId);
                var comment  = new MildomComment(chat, chat.Raw);
                var metadata = new CommentMessageMetadata(comment, _options, _siteOptions, user, this, isFirst)
                {
                    IsInitialComment = _isBeeingSentInitialComments,
                    SiteContextGuid  = SiteContextGuid,
                };
                var methods = new MildomMessageMethods();
                if (_siteOptions.NeedAutoSubNickname)
                {
                    var messageText = chat.MessageItems.ToText();
                    var nick        = SitePluginCommon.Utils.ExtractNickname(messageText);
                    if (!string.IsNullOrEmpty(nick))
                    {
                        user.Nickname = nick;
                    }
                }
                return(new MildomMessageContext(comment, metadata, methods));
            }
            else if (message is OnGiftMessage internalGift)
            {
                var userId = internalGift.UserId.ToString();
                //var isFirst = _first.IsFirstComment(userId);
                var user = GetUser(userId);

                if (!_giftDict.TryGetValue(internalGift.GiftId, out var item))
                {
                    item = new GiftItem("(未知のギフト)");
                }
                var gift     = new MildomGift(internalGift, item);
                var metadata = new GiftMessageMetadata(gift, _options, _siteOptions, user, this)
                {
                    IsInitialComment = _isBeeingSentInitialComments,
                    SiteContextGuid  = SiteContextGuid,
                };
                var methods = new MildomMessageMethods();
                return(new MildomMessageContext(gift, metadata, methods));
            }
            //if (message is IMildomComment comment)
            //{
            //    var userId = comment.UserId;
            //    var isFirst = _first.IsFirstComment(userId);
            //    var user = GetUser(userId);
            //    //var comment = new MildomComment(message, raw);
            //    var metadata = new CommentMessageMetadata(comment, _options, _siteOptions, user, this, isFirst)
            //    {
            //        IsInitialComment = false,
            //        SiteContextGuid = SiteContextGuid,
            //    };
            //    var methods = new MildomMessageMethods();
            //    if (_siteOptions.NeedAutoSubNickname)
            //    {
            //        var messageText = message.CommentItems.ToText();
            //        var nick = SitePluginCommon.Utils.ExtractNickname(messageText);
            //        if (!string.IsNullOrEmpty(nick))
            //        {
            //            user.Nickname = nick;
            //        }
            //    }
            //    return new MildomMessageContext(comment, metadata, methods);
            //}
            else if (message is OnAddMessage add && _siteOptions.IsShowJoinMessage)
            {
                var userId   = add.UserId.ToString();
                var user     = GetUser(userId);
                var join     = new MildomJoinRoom(add);
                var metadata = new JoinMessageMetadata(join, _options, _siteOptions, user, this)
                {
                    IsInitialComment = false,
                    SiteContextGuid  = SiteContextGuid,
                };
                var methods = new MildomMessageMethods();
                return(new MildomMessageContext(join, metadata, methods));
            }