コード例 #1
0
        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);
        }
コード例 #2
0
        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));
            }
        }