public TelegramUser(ITelegramUser user) : this() { Id = user.Id; Username = user.Username; FirstName = user.FirstName; LastName = user.LastName; LanguageCode = user.LanguageCode; }
/// <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); }
/// <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)); } }
/// <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); }
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); }
public bool DeleteState(ITelegramUser user) { userState.TryRemove(user, out _); return(true); }
public bool SaveState(ITelegramUser user, ICommandState state) { userState[user] = state; return(true); }
public ICommandState GetCurrentState(ITelegramUser user) { return(userState.ContainsKey(user) ? userState[user] : null); }
/// <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)); }