Esempio n. 1
0
 public bool InsertRoom(string name, ChatRoomType chatRoomType = ChatRoomType.Public)
 {
     try
     {
         using (var dbContext = new AsanaDbContext())
         {
             ChatRoom chat = new ChatRoom()
             {
                 Name = name, ProjectId = CurrentProject.Instance.Project.Id, ChatRoomType = chatRoomType, Desc = "Don't have description."
             };
             dbContext.ChatRooms.Add(chat);
             dbContext.ChatRoomUsers.Add(new ChatRoomUsers()
             {
                 UserId = CurrentUser.Instance.User.Id, ChatRoomId = chat.ID
             });
             dbContext.SaveChanges();
         }
         return(true);
     }
     catch (Exception err)
     {
         Log.Error(err.Message);
         return(false);
     }
 }
Esempio n. 2
0
 public bool InsertDirectMessage(string email, ChatRoomType chatRoomType = ChatRoomType.Direct)
 {
     try
     {
         using (var dbContext = new AsanaDbContext())
         {
             var friendUser = dbContext.Users.SingleOrDefault(x => x.Email == email);
             if (friendUser == null || dbContext.ChatRooms.Any(x => x.Name == email + " - " + CurrentUser.Instance.User.Email) || !dbContext.Projects.Any(x => x.UserId == friendUser.Id && x.Id == CurrentProject.Instance.Project.Id))
             {
                 throw new Exception();
             }
             ChatRoom chat = new ChatRoom()
             {
                 Name = email + " - " + CurrentUser.Instance.User.Email, ProjectId = CurrentProject.Instance.Project.Id, ChatRoomType = chatRoomType, Desc = "Don't have description."
             };
             dbContext.ChatRooms.Add(chat);
             dbContext.ChatRoomUsers.Add(new ChatRoomUsers()
             {
                 UserId = CurrentUser.Instance.User.Id, ChatRoomId = chat.ID
             });
             dbContext.ChatRoomUsers.Add(new ChatRoomUsers()
             {
                 UserId = friendUser.Id, ChatRoomId = chat.ID
             });
             dbContext.SaveChanges();
         }
         return(true);
     }
     catch (Exception err)
     {
         Errors.SeacrhFriendErrorMsg();
         return(false);
     }
 }
        public int CreateChatRoom(string title, ChatRoomType type)
        {
            var obj = new
            {
                Title     = title,
                Type      = type,
                SessionId = _sessionId
            };

            var query = _urlBase + "app/new-chat-room";

            var jsonObject = JsonConvert.SerializeObject(obj);

            using (var httpClient = new HttpClient())
            {
                var content  = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");
                var response = httpClient.PostAsync(query, content).Result;

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    return(Int32.Parse(response.Content.ReadAsStringAsync().Result));
                }
                else
                {
                    return(-1);
                }
            }
        }
        internal ChatRoom(ChatRoomType type, uint creatorUserId, string name, string pass, string note)
        {
            this.Clients       = new ClientSessionCollection(removeCallback: this.Leave0);
            this.BannedClients = new ConcurrentBag <IUserIdentifier>();

            this.RecentMessages = new ConcurrentQueue <ChatOutgoingMessage>();

            this.CreatorUserId = creatorUserId;
            this.Type          = type;
            this.Name          = name;
            this.Pass          = pass;
            this.Note          = note;
        }
        internal ChatRoom(ChatRoomType type, uint creatorUserId, string name, string pass, string note, params ClientSession[] clientSessions)
        {
            this.Clients       = new ClientSessionCollection(this.OnDisconnect);
            this.BannedClients = new ConcurrentBag <IUserIdentifier>();

            this.RecentMessages = new ConcurrentQueue <ChatOutgoingMessage>();

            this.CreatorUserId = creatorUserId;
            this.Type          = type;
            this.Name          = name;
            this.Pass          = pass;
            this.Note          = note;

            foreach (ClientSession session in clientSessions)
            {
                this.Join(session);
            }
        }
Esempio n. 6
0
        public void IssueFinesFromReactions(DateTime startDateTime, ChatRoomType chatRoomType)
        {
            var chatRoomIds = chatRoomType == ChatRoomType.Channel
                ? channelApi.ListChannels(ConfigurationManager.AppSettings["BotKey"]).channels.Select(x => x.id)
                : groupApi.ListGroups(ConfigurationManager.AppSettings["BotKey"]).groups.Select(x => x.id);

            foreach (var chatRoomId in chatRoomIds)
            {
                var history = new GroupsHistoryResponseModel();
                var hasMore = true;

                while (hasMore)
                {
                    history = chatRoomType == ChatRoomType.Channel
                        ? channelApi.GetChannelHistory(
                            ConfigurationManager.AppSettings["BotKey"],
                            chatRoomId,
                            startDateTime,
                            history.messages.Any() ? history.messages.Last().TimeStamp : DateTime.Now,
                            100)
                        : groupApi.GetGroupHistory(ConfigurationManager.AppSettings["BotKey"],
                            chatRoomId,
                            startDateTime,
                            history.messages.Any() ? history.messages.Last().TimeStamp : DateTime.Now,
                            100);

                    var unacknowledgedMessagesWithFineReaction = history.messages.Where(
                        x => x.reactions != null
                        && x.reactions.Any(y => y.name.Equals("fine"))
                        && !x.reactions.Any(y => y.name.Equals("ok_hand") && y.users.Any(z => z.Equals("U0DR7JG3G") || z.Equals("U0DR7KZNJ"))));

                    foreach (var message in unacknowledgedMessagesWithFineReaction)
                    {
                        var fineReaction = message.reactions.First(x => x.name.Equals("fine"));

                        IList<UserModel> reactionUsers = fineReaction.users
                            .Select(x => userApi.GetUserBySlackId(x.FormatUserId()))
                            .ToList();

                        if (reactionUsers.Any(x => x.IsBotToIgnore()))
                        {
                            continue;
                        }

                        var validIssuers = this.userApi.GetValidFineIssuers(reactionUsers);

                        if (validIssuers != null && validIssuers.Any())
                        {
                            var recipient = userApi.GetUserBySlackId(message.user.FormatUserId());
                            if (recipient.DisplayName != null && recipient.DisplayName.Equals(ConfigurationManager.AppSettings["FinesbotName"]))
                            {
                                reactionApi.AddReaction(ConfigurationManager.AppSettings["BotKey"], "middle_finger", chatRoomId, message.ts);
                                continue;
                            }

                            if (recipient.DisplayName != null && recipient.DisplayName.Equals(ConfigurationManager.AppSettings["FinebotsSecondCousinName"]))
                            {
                                reactionApi.AddReaction(ConfigurationManager.AppSettings["SeconderBotKey"], "middle_finger", chatRoomId, message.ts);
                                continue;
                            }

                            string reason = string.Format("{0} said \"{1}\"", recipient.DisplayName ?? recipient.EmailAddress.LocalPart(), message.text);

                            UserModel issuer;

                            if (validIssuers.Count == 1 && reactionUsers.Count == 1)
                            {
                                issuer = validIssuers.First();
                                this.IssueFine(issuer.Id, recipient.Id, reason);

                                var notification = string.Format("{0} fined you for saying \"{1}\" although no one has seconded it yet.", issuer.DisplayName ?? issuer.EmailAddress.LocalPart(), message.text);
                                this.chatApi.PostMessage(ConfigurationManager.AppSettings["BotKey"], recipient.SlackId.CleanSlackId(), notification);
                                this.reactionApi.AddReaction(ConfigurationManager.AppSettings["BotKey"], "ok_hand", chatRoomId, message.ts);
                            }
                            else
                            {
                                var isFineIssued = false;
                                for (var i = 0; i < validIssuers.Count && !isFineIssued; i++)
                                {
                                    for (var j = 0; j < reactionUsers.Count && !isFineIssued; j++)
                                    {
                                        if (!reactionUsers[j].Id.Equals(validIssuers[i].Id))
                                        {
                                            issuer = validIssuers[i];
                                            var seconder = reactionUsers[j];
                                            this.IssueAutoFine(issuer.Id, recipient.Id, seconder.Id, reason);
                                            isFineIssued = true;

                                            var notification = string.Format("{0} (and {2} others) fined you for saying \"{1}\"", issuer.DisplayName ?? issuer.EmailAddress.LocalPart(), message.text, validIssuers.Count - 1);

                                            this.reactionApi.AddReaction(ConfigurationManager.AppSettings["BotKey"], "ok_hand", chatRoomId, message.ts);
                                            this.chatApi.PostMessage(ConfigurationManager.AppSettings["BotKey"], recipient.SlackId.CleanSlackId(), notification);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            reactionApi.AddReaction(ConfigurationManager.AppSettings["BotKey"], "raised_hand", chatRoomId, message.ts);
                        }
                    }

                    hasMore = history.has_more;
                }
            }
        }
 internal ChatRoom(ChatRoomType type, string name, string pass, string note) : this(type, 0, name, pass, note)
 {
 }
 internal ChatRoom(ChatRoomType type, string name, string pass, string note, params ClientSession[] clientSessions) : this(type, 0, name, pass, note, clientSessions)
 {
 }
 internal bool TryCreate(ChatRoomType type, uint creatorUserId, string name, string pass, string note, out ChatRoom room) => this.ChatRooms.TryAdd(name, room = new ChatRoom(type, creatorUserId, name, pass, note));
Esempio n. 10
0
 internal ChatRoom(ChatRoomManager chatRoomManager, CommandManager commandManager, ChatRoomType type, string name, string pass, string note) : this(chatRoomManager, commandManager, type, 0, name, pass, note)
 {
 }
Esempio n. 11
0
 public ChatRoomAddViewModel(ChatRoomType chatRoomType)
 {
     this.chatRoomType = chatRoomType;
 }
Esempio n. 12
0
 //Dont really like these methods tho I can't come up with better names and funcitonaly
 internal bool TryCreate(ChatRoomType type, string name, string pass, string note, out ChatRoom room) => this.ChatRooms.TryAdd(name, room = new ChatRoom(this, this.commandManager, type, name, pass, note));
Esempio n. 13
0
 protected Chat(ChatRoomType type) => this.type = type;
Esempio n. 14
0
		public static void SaveMessage(string message, Player sender, List<Player> targets, ChatRoomType chatRoomType)
		{
			LiteDatabase.GetCollection<Room>().Insert(new Room()
			{
				Message = new Message()
				{
					Sender = sender,
					Targets = targets,
					Content = message,
					Timestamp = DateTime.Now
				},
				Type = chatRoomType
			});
		}