コード例 #1
0
 public TelegramUser(ITelegramUser user) : this()
 {
     Id           = user.Id;
     Username     = user.Username;
     FirstName    = user.FirstName;
     LastName     = user.LastName;
     LanguageCode = user.LanguageCode;
 }
コード例 #2
0
        /// <summary>
        /// Check if the user data is the same as another user.
        /// </summary>
        /// <typeparam name="TUser">User type.</typeparam>
        /// <param name="user">User data.</param>
        /// <param name="anotherUser">Another chat.</param>
        /// <returns>True, is data of the users aren't the same.</returns>
        public static bool HasChanges <TUser>(this TUser user, ITelegramUser anotherUser)
            where TUser : ITelegramUser
        {
            var hasChanges = user.FirstName != anotherUser.FirstName ||
                             user.LastName != anotherUser.LastName ||
                             user.Username != anotherUser.Username ||
                             user.LanguageCode != anotherUser.LanguageCode;

            return(hasChanges);
        }
コード例 #3
0
 /// <summary>
 /// Get the fullname from a telegram user.
 /// </summary>
 /// <param name="user">The telegram user.</param>
 /// <returns><see cref="string"/></returns>
 public static string GetFullname(this ITelegramUser user)
 {
     if (string.IsNullOrEmpty(user.LastName))
     {
         return(user.FirstName);
     }
     else
     {
         return(string.Format("{0} {1}", user.FirstName, user.LastName));
     }
 }
コード例 #4
0
        /// <summary>
        /// Merge user data from one user with another user.
        /// </summary>
        /// <typeparam name="TUser">User type.</typeparam>
        /// <param name="user">User data.</param>
        /// <param name="anotherUser">Another user.</param>
        /// <returns>Updated user data.</returns>
        public static TUser Merge <TUser>(this TUser user, ITelegramUser anotherUser)
            where TUser : ITelegramUser
        {
            var mergeLang = string.IsNullOrEmpty(anotherUser.LanguageCode) && anotherUser.LanguageCode != user.LanguageCode;

            user.FirstName = anotherUser.FirstName;
            user.LastName  = anotherUser.LastName;
            user.Username  = anotherUser.Username;

            if (mergeLang)
            {
                user.LanguageCode = anotherUser.LanguageCode;
            }

            return(user);
        }
コード例 #5
0
        public bool TryGetCurrentCommandType(ITelegramUser user, out ICommandType commandType)
        {
            if (!userState.ContainsKey(user))
            {
                commandType = null;
                return(false);
            }

            var type = userState[user].GetType()
                       .GetInterfaces()
                       .Where(T => T.IsGenericType).
                       First(T => T.GetGenericTypeDefinition().Equals(typeof(ICommandState <>)))
                       .GetGenericArguments().First();

            commandType = (ICommandType)Activator.CreateInstance(type);
            return(true);
        }
コード例 #6
0
 public bool DeleteState(ITelegramUser user)
 {
     userState.TryRemove(user, out _);
     return(true);
 }
コード例 #7
0
 public bool SaveState(ITelegramUser user, ICommandState state)
 {
     userState[user] = state;
     return(true);
 }
コード例 #8
0
 public ICommandState GetCurrentState(ITelegramUser user)
 {
     return(userState.ContainsKey(user) ? userState[user] : null);
 }
コード例 #9
0
 /// <summary>
 /// Creates a user mention using Html.
 /// </summary>
 /// <param name="user">The telegram user.</param>
 /// <returns><see cref="string"/></returns>
 public static string GetHtmlMention(this ITelegramUser user)
 {
     return(user.GetFullname().AsHtmlTextMention(user.Id));
 }