From 49664064f66db0d4c05bb9d366ed2cf14cda7bf0 Mon Sep 17 00:00:00 2001 From: Sergey Gut Date: Wed, 16 Feb 2022 20:05:14 +0300 Subject: [PATCH] Notification when user is flooding, fixes --- Core/Service/MemoryAntiFloodService.cs | 2 +- Dockerfile | 14 ++------------ modules/Reputation/Handler/Reputation.cs | 7 +++++++ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Core/Service/MemoryAntiFloodService.cs b/Core/Service/MemoryAntiFloodService.cs index 0b877f5..b7d5269 100644 --- a/Core/Service/MemoryAntiFloodService.cs +++ b/Core/Service/MemoryAntiFloodService.cs @@ -27,7 +27,7 @@ public class MemoryAntiFloodService : IAntiFlood var dictKey = DictKey(chat, user); if (_bannedUsers.TryGetValue(dictKey, out var expirationTime)) { - if (DateTime.UtcNow <= expirationTime) + if (DateTime.UtcNow > expirationTime) { expirationTime = DateTime.MinValue; _bannedUsers.Remove(dictKey); diff --git a/Dockerfile b/Dockerfile index 64ae22a..d4b4d91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,19 +30,9 @@ FROM mcr.microsoft.com/dotnet/aspnet:6.0.1-alpine3.14 WORKDIR /user COPY --from=build /app /app -ENV MUSL_LOCPATH /usr/share/i18n/locales/musl \ - DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ Logging__Console__FormatterName=Simple -RUN apk add --no-cache cmake make musl-dev gcc gettext-dev libintl icu-libs \ - && wget https://gitlab.com/rilian-la-te/musl-locales/-/archive/master/musl-locales-master.zip \ - && unzip musl-locales-master.zip \ - && cd musl-locales-master \ - && cmake -DLOCALE_PROFILE=OFF -D CMAKE_INSTALL_PREFIX:PATH=/usr . && make && make install \ - && cd .. && rm -r musl-locales-master - -ENV LANG ru_RU.UTF-8 -ENV LANGUAGE ru_RU.UTF-8 -ENV LC_ALL ru_RU.UTF-8 +RUN apk add --no-cache icu-libs ENTRYPOINT ["dotnet", "/app/TelegramBot.dll"] diff --git a/modules/Reputation/Handler/Reputation.cs b/modules/Reputation/Handler/Reputation.cs index 36cd87b..8ef69ae 100644 --- a/modules/Reputation/Handler/Reputation.cs +++ b/modules/Reputation/Handler/Reputation.cs @@ -82,6 +82,13 @@ public class Reputation : CommonHandler } _antiFlood.RecordAction(Chat, From); + if (_antiFlood.IsUserFlooding(Chat, From)) + { + await Reply(new HtmlString() + .UserMention(From).Pre(": пользователь отправлен в игнор.") + .ToString()); + return; + } } var senderRepCount = await GetUserReputation(From);