예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="post"></param>
        /// <param name="jPost"></param>
        public static void GenerateChatPost(ref TumblrPost post, dynamic jPost)
        {
            if (post == null)
            {
                throw new ArgumentNullException(nameof(post));
            }
            if (jPost == null)
            {
                throw new ArgumentNullException(nameof(jPost));
            }

            post = new ChatPost
            {
                Title = !string.IsNullOrEmpty((string)jPost.title) ? jPost.title : null,
                Body  = !string.IsNullOrEmpty((string)jPost.body) ? jPost.body : null
            };

            if (jPost.dialogue != null)
            {
                post.Dialogue = new HashSet <ChatPostFragment>();
                foreach (dynamic jChatFragment in jPost.dialogue)
                {
                    ChatPostFragment chatFragment = new ChatPostFragment
                    {
                        Name   = !string.IsNullOrEmpty((string)jChatFragment.name) ? jChatFragment.name : null,
                        Label  = !string.IsNullOrEmpty((string)jChatFragment.label) ? jChatFragment.label : null,
                        Phrase = !string.IsNullOrEmpty((string)jChatFragment.phrase) ? jChatFragment.phrase : null
                    };
                    post.Dialogue.Add(chatFragment);
                }
            }
            IncludeCommonPostFields(ref post, jPost);
        }
예제 #2
0
        public async Task SendMessage(string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                await Clients.Caller.SendAsync("Error", "Write the message you want to send.");

                return;
            }

            // Identify message's owner
            var currentUser = await _chatPersistance.ChatUsers.FirstAsync(x => x.UserName == Context.User.Identity.Name);

            // Save the message in database using persistance service (EF)
            var cm = new ChatPost
            {
                ChatUserId  = currentUser.Id,
                PublishedOn = DateTime.Now,
                Message     = message
            };

            // Save the message unless it's a stock command

            if (!message.ToLower().StartsWith("/stock="))
            {
                // Add post to the unit of work
                await _chatPersistance.ChatPosts.AddAsync(cm);
            }

            // Broadcast the new message to all people in chat room
            await BroadCastMessage(currentUser.FullName, currentUser.ProfilePic, cm.PublishedOn, cm.Message);

            // Let the bot read the message
            var response = _chatBot.Read(message);

            // If the bot has a response for the message
            if (!string.IsNullOrEmpty(response.ResultText))
            {
                // Save bot message in database
                var botPost = new ChatPost
                {
                    ChatUserId  = _chatBot.ChatUserId,
                    PublishedOn = DateTime.Now,
                    Message     = response.ResultText
                };

                // Add post to the unit of work
                await _chatPersistance.ChatPosts.AddAsync(botPost);

                // Broadcast to all users in the room
                await BroadCastMessage(_chatBot.Name, _chatBot.ProfilePic, DateTime.Now, response.ResultText);
            }

            // Persist post messages
            await _chatPersistance.SaveChangesAsync();
        }
예제 #3
0
        public ModelStatus PostCommandPrivatPostActivChat(ChatCmdResult reason, string login, Chat chat, string msg)
        {
            var post = new ChatPost()
            {
                Time               = DateTime.UtcNow,
                Message            = msg,
                OwnerLogin         = "******",
                OnlyForPlayerLogin = login
            };

            chat.Posts.Add(post);

            return(new ModelStatus()
            {
                Status = (int)reason,
                Message = msg,
            });
        }
예제 #4
0
        public void Reply_CreatesNewPostWithThisPostAsRootPost_IfThisPostIsRoot()
        {
            var post = new Post {
                Id = POST_ID, ChannelId = CHANNEL_ID, RootId = string.Empty
            };
            var newPost = new Post
            {
                ChannelId = CHANNEL_ID,
                Message   = MESSAGE,
                RootId    = POST_ID
            };
            var restService = new Mock <IRestService>();

            restService.Setup(x => x.CreatePost(BaseUri, TOKEN, newPost));
            var sut = new ChatPost(restService.Object, BaseUri, TOKEN, TEAM_ID, post);

            sut.Reply(MESSAGE);

            restService.VerifyAll();
        }
예제 #5
0
        public async Task UserJoined()
        {
            var currentUser = await _chatPersistance.ChatUsers.FirstAsync(x => x.UserName == Context.User.Identity.Name);

            var response = _chatBot.Read($"/sayhi={currentUser.FullName}");

            var botPost = new ChatPost
            {
                ChatUserId  = _chatBot.ChatUserId,
                PublishedOn = DateTime.Now,
                Message     = response.ResultText
            };

            // Add post to the unit of work
            await _chatPersistance.ChatPosts.AddAsync(botPost);

            // Persist post message
            await _chatPersistance.SaveChangesAsync();

            // Broadcast welcome message to all users in room
            await BroadCastMessage(_chatBot.Name, _chatBot.ProfilePic, DateTime.Now, response.ResultText);
        }
예제 #6
0
        private ChatPost ParseChatPost(JObject jObject, HashSet <string> checkedProperties)
        {
            ChatPost newPost = new ChatPost();
            JToken   current;

            if (CheckProperty(jObject, "title", checkedProperties, out current))
            {
                newPost.Title = (string)current;
            }
            if (CheckProperty(jObject, "body", checkedProperties, out current))
            {
                newPost.Body = (string)current;
            }
            if (CheckProperty(jObject, "dialogue", checkedProperties, out current))
            {
                newPost.Dialogue = new List <Dialogue>();
                var children = current.Children();
                foreach (JObject child in children)
                {
                    newPost.Dialogue.Add(ParseDialogue(child));
                }
            }
            return(newPost);
        }