예제 #1
0
        private void OnMessageReceived(Result result)
        {
            var commentData    = ParsePrivMsg(result);
            var userId         = commentData.UserId;
            var isFirstComment = _commentCounter.UpdateCount(userId);
            var user           = GetUser(userId);

            if (_siteOptions.NeedAutoSubNickname)
            {
                SitePluginCommon.Utils.SetNickname(commentData.Message, user);
            }
            var message = new TwitchComment(result.Raw)
            {
                CommentItems = Tools.GetMessageItems(result),
                Id           = commentData.Id,
                NameItems    = new List <IMessagePart> {
                    MessagePartFactory.CreateMessageText(commentData.Username)
                },
                PostTime = commentData.SentAt.ToString("HH:mm:ss"),
                UserId   = commentData.UserId,
            };
            var metadata = new MessageMetadata(message, _options, _siteOptions, user, this, isFirstComment)
            {
                IsInitialComment = false,
                SiteContextGuid  = SiteContextGuid,
            };
            var methods        = new TwitchMessageMethods();
            var messageContext = new TwitchMessageContext(message, metadata, methods);

            MessageReceived?.Invoke(this, messageContext);
        }
예제 #2
0
        public TwitchCommentViewModel(ICommentOptions options, ITwitchSiteOptions siteOptions,
                                      ICommentData commentData, bool isFirstComment, ICommentProvider commentProvider, IUser user)
            : base(options, user, commentProvider, isFirstComment)
        {
            MessageType  = MessageType.Comment;
            _siteOptions = siteOptions;
            Id           = commentData.Id;
            UserId       = commentData.UserId;
            DisplayName  = commentData.DisplayName;
            PostTime     = commentData.SentAt.ToString("HH:mm:ss");

            var name = commentData.Username;

            user.Name = new List <IMessagePart> {
                MessagePartFactory.CreateMessageText(name)
            };
            var message = commentData.Message;

            if (siteOptions.NeedAutoSubNickname)
            {
                var nick = ExtractNickname(message);
                if (!string.IsNullOrEmpty(nick))
                {
                    user.Nickname = nick;
                }
            }
            NameItemsInternal = new List <IMessagePart> {
                MessagePartFactory.CreateMessageText(name)
            };
            MessageItems = Tools.GetMessageItems(commentData.Message, commentData.Emotes);

            Init();
        }