Пример #1
0
 /// <summary>
 /// Returns true if either a global or local alias is known by the given keyword
 /// </summary>
 public bool IsKnown(string keyword, string contextID)
 {
     lock (_lock)
     {
         keyword = keyword.ToUpperInvariant().Trim();
         return(UserAliases.ContainsKey(keyword) || LocalAliases.ContainsKey(contextID + "_" + keyword));
     }
 }
Пример #2
0
 /// <summary>
 /// Returns true if a global alias is known by the given keyword
 /// </summary>
 public bool IsKnown(string keyword)
 {
     lock (_lock)
     {
         keyword = keyword.ToUpperInvariant().Trim();
         return(UserAliases.ContainsKey(keyword));
     }
 }
Пример #3
0
        /// <summary>
        /// Adds an Alias to the User
        /// </summary>
        /// <param name="UserID">ulong UserID of the SocketUser we're saving information for</param>
        /// <param name="Alias">The Alias the User wants to add and keep track of</param>
        /// <returns></returns>
        public AddSuccess AddAlias(ulong UserID, string Alias)
        {
            Aliases tempAliases     = _aliases;
            var     SuccessLevel    = AddSuccess.Unknown;
            bool    SuccessfulWrite = false;

            //See if the user has Saved any Aliases previously
            if (UserAliases.ContainsKey(UserID))
            {
                //If they have make sure they aren't trying to save the same alias again
                if (!UserAliases[UserID].Contains(Alias, StringComparer.InvariantCultureIgnoreCase))
                {
                    UserAliases[UserID].Add(Alias);
                    UserAliases[UserID].Sort(StringComparer.InvariantCultureIgnoreCase);
                    SuccessLevel = AddSuccess.Success;
                }
                else
                {
                    SuccessLevel = AddSuccess.AlreadyExists;
                }
            }
            else              //If this is their first Alias, get the List for them set up.
            {
                var tempList = new List <string>();
                tempList.Add(Alias);
                UserAliases[UserID] = tempList;
                SuccessLevel        = AddSuccess.Success;
            }

            //If we had to make any changes, write them to disk
            if (SuccessLevel != AddSuccess.AlreadyExists)
            {
                SuccessfulWrite = WriteToDisk();
            }
            //Make sure the write was succesful, if not tell the user as such
            if (SuccessfulWrite || SuccessLevel == AddSuccess.AlreadyExists)
            {
                return(SuccessLevel);
            }
            else
            {
                _aliases = tempAliases;
                return(AddSuccess.WriteFailure);
            }
        }