Exemplo n.º 1
0
        public static bool IsAuthorized(PermissionLevel permission, User user)
        {
            if (permission == PermissionLevel.None)
                return true;

            return IsRegistered(user) != null && IsAuthorised(permission, IsRegistered(user));
        }
Exemplo n.º 2
0
 public ChatEventArgs(EventType t, Message m, User u, Room r, string rawData)
 {
     this.Type = t;
     this.Message = m;
     this.User = u;
     this.Room = r;
     this.Handled = false;
 }
Exemplo n.º 3
0
 public void Execute(string command, string arguments, User user, Room room, Client client)
 {
     if (!AdaPermissions.IsAuthorized(permissionLevel, user))
     {
         var messageBuilder = new MessageBuilder();
         messageBuilder.AppendPing(user);
         messageBuilder.AppendText("You are not authorised to make this command.");
         room.PostMessage(messageBuilder);
     }
     else
     {
         Action(command, arguments, user, room, client);
     }
 }
Exemplo n.º 4
0
        public Message(Room room, int messageID, User author, int parentID = -1)
        {
            if (room == null) { throw new ArgumentException("room"); }
            if (messageID < 0) { throw new ArgumentOutOfRangeException("messageID", "'messageID' can not be less than 0."); }
            if (author == null) { throw new ArgumentNullException("author"); }

            Content = GetMessageContent(room.Host, messageID, room.StripMention);
            Host = room.Host;
            RoomID = room.ID;
            ID = messageID;
            ParentID = parentID;
            Author = author;

            var historyHtml = RequestManager.Get("", "http://chat." + Host + "/messages/" + ID + "/history");

            SetStarPinCount(historyHtml);
            EditCount = GetEditCount(historyHtml);
        }
Exemplo n.º 5
0
        internal void TrackUser(User user)
        {
            if (user == null) { throw new ArgumentNullException("user"); }

            ConnectListener(EventType.UserAccessLevelChanged, new Action<User, User, UserRoomAccess>((granter, targetUser, newAccess) =>
            {
                if (targetUser.ID == user.ID)
                {
                    user.IsRoomOwner = newAccess == UserRoomAccess.Owner;
                }
            }));
        }
Exemplo n.º 6
0
        public void AppendPing(User targetUser, WhiteSpace appendWhiteSpace = WhiteSpace.Space)
        {
            if (targetUser == null) { throw new ArgumentNullException("targetUser"); }

            AppendPing(targetUser.Name, appendWhiteSpace);
        }
Exemplo n.º 7
0
 public bool SetUserRoomAccess(UserRoomAccess access, User user)
 {
     return SetUserRoomAccess(access, user.ID);
 }
Exemplo n.º 8
0
 public bool KickMute(User user)
 {
     return KickMute(user.ID);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Fetches user data for the specified user ID.
        /// </summary>
        /// <param name="userID">The user ID to look up.</param>
        public User GetUser(int userID)
        {
            var u = new User(Host, ID, userID, cookieKey);

            evMan.TrackUser(u);

            return u;
        }
Exemplo n.º 10
0
        public bool HandleEvent(object sender, ChatEventArgs e)
        {
            if (activeUser == null)
            {
                if (startReorderCmdPattern.IsMatch(e.Message.Content))
                {
                    activeUser = e.Message.Author;
                    PrintCommandListReply(e.Message, e.Room);
                    e.Handled = true;
                    return true; // stay as the active trigger
                }
            }
            else if (e.Message.Author.Name.Equals(activeUser.Name))
            {
                List<int> args = ParseCommandArgs(e.Message.Content);
                if (switchCmdPattern.IsMatch(e.Message.Content))
                {
                    // need 2 args
                    if (args.Count < 2)
                    {
                        e.Room.PostReplyLight(e.Message, "Not enough parameters. Try again, dummy.");
                        e.Handled = true;
                        return true;
                    }
                    // sanity check
                    if (args[0] > router.Commands.Count || args[1] > router.Commands.Count)
                    {
                        e.Room.PostReplyLight(e.Message, "Message failed sanity check. You're crazy.");
                        e.Handled = true;
                        return true;
                    }

                    //swap
                    ICommand first = router.Commands[args[0] - 1];
                    router.Commands[args[0] - 1] = router.Commands[args[1] - 1];
                    router.Commands[args[1] - 1] = first;

                    PrintCommandListReply(e.Message, e.Room);

                    e.Handled = true;
                    return true;

                }
                else if (toggleCmdPattern.IsMatch(e.Message.Content))
                {
                    if (args.Count <1)
                    {
                        e.Room.PostReplyLight(e.Message, "Not enough parameters. Try again, dummy.");
                        e.Handled = true;
                        return true;
                    }
                    if (args[0] > router.Commands.Count)
                    {
                        e.Room.PostReplyLight(e.Message, "Message failed sanity check. You're crazy.");
                        e.Handled = true;
                        return true;
                    }

                    // toggle the state.
                    router.CommandStates[router.Commands[args[0] - 1]] = !router.CommandStates[router.Commands[args[0] - 1]];
                    PrintCommandListReply(e.Message, e.Room);
                    e.Handled = true;
                    return true;
                }
                else if (doneReorderCmd.IsMatch(e.Message.Content))
                {
                    activeUser = null;
                    e.Room.PostReplyLight(e.Message, "Done.");
                    e.Handled = true;
                }
                else
                {
                    e.Room.PostReplyLight(e.Message, "Try not mumbling so much.");
                }
            }

            return false;
        }
Exemplo n.º 11
0
 public static ChatUser IsRegistered(User user)
 {
     return Users.FirstOrDefault(u => u.UserId == user.ID);
 }
Exemplo n.º 12
0
 public static List<Message> GetMessagesByUser(this IEnumerable<Message> messages, User user)
 {
     if (user == null) { throw new ArgumentNullException("user"); }
     return messages.GetMessagesByUser(user.ID);
 }
Exemplo n.º 13
0
        private void EventCallback(EventType evt, Message m, User u, Room r, string raw)
        {
            if (evt == EventType.UserMentioned)
            {
                if (Regex.IsMatch(m.Content, @"(?i)^(die|stop|shutdown)$"))
                {
                    ShutdownMre.Set();
                    return;
                }
            }

            Console.WriteLine("{0} - {1} - {2}",
                evt,
                u != null ? u.GetChatFriendlyUsername() : (m != null ? m.Author.GetChatFriendlyUsername() : ""),
                m != null ? m.Content : "");

            ChatEventArgs args = new ChatEventArgs(evt, m, u, r, raw);
            bool handled = HandleTriggerEvent(args);
            if (!handled && m != null && evt == EventType.UserMentioned) HandleCommandEvent(args);
        }