public static bool IsAuthorized(PermissionLevel permission, User user) { if (permission == PermissionLevel.None) return true; return IsRegistered(user) != null && IsAuthorised(permission, IsRegistered(user)); }
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; }
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); } }
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); }
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; } })); }
public void AppendPing(User targetUser, WhiteSpace appendWhiteSpace = WhiteSpace.Space) { if (targetUser == null) { throw new ArgumentNullException("targetUser"); } AppendPing(targetUser.Name, appendWhiteSpace); }
public bool SetUserRoomAccess(UserRoomAccess access, User user) { return SetUserRoomAccess(access, user.ID); }
public bool KickMute(User user) { return KickMute(user.ID); }
/// <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; }
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; }
public static ChatUser IsRegistered(User user) { return Users.FirstOrDefault(u => u.UserId == user.ID); }
public static List<Message> GetMessagesByUser(this IEnumerable<Message> messages, User user) { if (user == null) { throw new ArgumentNullException("user"); } return messages.GetMessagesByUser(user.ID); }
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); }