public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel) { ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.LicenseDuration); ShopUserRepository.UpdateUserBuyLicenseKey(userModel, this.licenseKey); await telegramShop.SendMessage(e.Message.Chat.Id, AnswerMessage.LicenseDurationMenu, GetKeyboard(userModel.CurrentDialogState)); }
public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel) { ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.PaymentMethod); ShopUserRepository.UpdateUserLicenseDuration(userModel, this.daysCount, this.price); await telegramShop.SendMessage(e.Message.Chat.Id, this.GetPaymentMethodMessage(userModel), GetKeyboard(userModel.CurrentDialogState)); }
public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel) { ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.LicenseRenewSubscription); var keyboard = GetKeyboard(userModel.CurrentDialogState); await telegramShop.SendMessage(e.Message.Chat.Id, GetAllUsersLicenseMessage(userModel), keyboard); await telegramShop.SendMessage(e.Message.Chat.Id, AnswerMessage.SendMeLicenseKeyToStartRenew, keyboard); }
private static string GetQiwiPaymentMessage(ShopUserModel user) { var comment = GetUniqueComment(); ShopUserRepository.UpdatePurchaseUniqueComment(user, comment); return(AnswerMessage.QiwiPaymentMethod .Replace("{price}", user.LicenseBuyProcess.Price.ToString(CultureInfo.InvariantCulture)) .Replace("{comment}", comment)); }
public static bool StillBlocked(ShopUserModel user) { var minutes = (DateTime.Now - user.LastMessageDate).TotalMinutes; var stillBlocked = minutes < 60; if (stillBlocked == false) { ShopUserRepository.UpdateSpamLevelWarning(user, 0); } return(stillBlocked); }
private static TelegramShopMessageHandler GetLicenseKeyAddPageProcessor(MessageEventArgs e, ShopUserModel user) { if (e.Message.Text == MenuMessage.Back) { return(new BackMessageHandler(EDialogState.Main, AnswerMessage.MainMenu)); } if (LicenseServerHandler.IsLicenseExist(e.Message.Text)) { ShopUserRepository.AddLicenseKey(user, e.Message.Text); return(new LicenseRenewSubscriptionMessageHandler()); } throw new ArgumentException(AnswerMessage.LicenseKeyNotExist); }
private static TelegramShopMessageHandler GetLicenseKeyRemovePageProcessor( MessageEventArgs e, ShopUserModel user) { if (e.Message.Text == MenuMessage.Back) { return(new BackMessageHandler(EDialogState.Main, AnswerMessage.MainMenu)); } if (user.LicenseKeys.Contains(e.Message.Text)) { ShopUserRepository.RemoveLicenseKey(user, e.Message.Text); return(new LicenseRenewSubscriptionMessageHandler()); } throw new ArgumentException(AnswerMessage.LicenseKeyNotBelongsToYou); }
public static async Task <bool> IsSpamming( TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel user) { // if user is blocked if (user.SpamWarning >= 100 && StillBlocked(user)) { return(true); } // if user is not spamming if (ShopUserRepository.IsUserSpamming(user) == false) { ShopUserRepository.UpdateUserLastMessageDate(user); return(false); } ShopUserRepository.UpdateUserLastMessageDate(user); ShopUserRepository.UpdateSpamLevelWarning(user); // if we should ban user if (user.SpamWarning >= 10) { ShopUserRepository.UpdateSpamLevelWarning(user, 100); await telegramShop.SendMessage(e.Message.Chat.Id, AnswerMessage.SpamYouAreBlockedMessage, null); return(true); } await telegramShop.SendMessage( e.Message.Chat.Id, AnswerMessage.SpamWarningMessage.Replace("{times}", (10 - user.SpamWarning).ToString()), TelegramShopMessageHandler.GetKeyboard(user.CurrentDialogState)); return(true); }
public static async Task ProcessMessage(TelegramShopClient telegramShop, MessageEventArgs e) { var user = ShopUserRepository.GetUser(e.Message.From); await telegramShop.Log($"Message from @{user.Telegram} - {e.Message.Text}"); try { if (await SpamHandler.IsSpamming(telegramShop, e, user)) { return; } await GetMenuProcessor(user, e).Process(telegramShop, e, user); } catch (Exception ex) { await telegramShop.SendMessage( e.Message.Chat.Id, AnswerMessage.ErrorOnRequestProcessing + ex.Message, TelegramShopMessageHandler.GetKeyboard(user.CurrentDialogState)); } }
public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel) { ShopUserRepository.UpdateUserDialogState(userModel, this.dialogState); await telegramShop.SendMessage(e.Message.Chat.Id, this.message, GetKeyboard(userModel.CurrentDialogState)); }
public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel) { ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.QiwiPaymentVerification); await telegramShop.SendMessage(e.Message.Chat.Id, GetQiwiPaymentMessage(userModel), GetKeyboard(userModel.CurrentDialogState)); }
public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel) { ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.QiwiPaymentVerification); if (cachedPayments != null && IsCachedOld() == false) { await telegramShop.SendMessage( e.Message.Chat.Id, GetQiwiTimeToNewRequestLeftMessage(), GetKeyboard(userModel.CurrentDialogState)); return; } var payments = telegramShop.Qiwi.GetIncomingTransactions().Result; lastRequestDate = DateTime.Now; cachedPayments = payments; var isPaymentPresent = IsPaymentPresent( userModel.LicenseBuyProcess.Comment, userModel.LicenseBuyProcess.Price, payments); if (isPaymentPresent) { await telegramShop.BoldLog($"@{userModel.Telegram} bought license for {userModel.LicenseBuyProcess.Days} days for {userModel.LicenseBuyProcess.Price} RUB"); ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.Main); if (userModel.LicenseBuyProcess.LicenseKey == null) { var newLicenseKey = GetNewLicenseKey(userModel.Telegram); LicenseServerHandler.GetNewLicense(userModel.LicenseBuyProcess.Days); ShopUserRepository.AddLicenseKey(userModel, newLicenseKey); await telegramShop.SendMessage( e.Message.Chat.Id, GetQiwiNewLicenseKeyAddedMessage(newLicenseKey, userModel.LicenseBuyProcess.Days), GetKeyboard(userModel.CurrentDialogState)); } else { LicenseServerHandler.AddDaysForExistLicense( userModel.LicenseBuyProcess.LicenseKey, userModel.LicenseBuyProcess.Days); await telegramShop.SendMessage( e.Message.Chat.Id, GetQiwiLicenseKeyDaysAddedMessage( userModel.LicenseBuyProcess.LicenseKey, userModel.LicenseBuyProcess.Days), GetKeyboard(userModel.CurrentDialogState)); } ShopUserRepository.UpdatePurchaseUniqueComment(userModel, null); ShopUserRepository.UpdateUserBuyLicenseKey(userModel, null); ShopUserRepository.UpdateUserLicenseDuration(userModel, 0, 0); } else { await telegramShop.SendMessage( e.Message.Chat.Id, GetQiwiTimeToNewRequestLeftMessage(), GetKeyboard(userModel.CurrentDialogState)); } }
public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel) { ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.ManageLicense); await telegramShop.SendMessage(e.Message.Chat.Id, AnswerMessage.LicenseManageMenuTitle, GetKeyboard(userModel.CurrentDialogState)); }