Skip to content

Commit

Permalink
emoji ban bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Lavshyak committed Dec 24, 2024
1 parent 71d1a09 commit 03124ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/VahterBanBot/Bot.fs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ let autoBan
let calculateCustomEmojiProportion
(message: Message) : float option =

let textLen = message.Text |> Seq.where(fun c -> not (" :.,\n\r".Contains c)) |> Seq.length
let textLen = message.TextOrCaption |> Seq.where(fun c -> not (" :.,\n\r".Contains c)) |> Seq.length
let customEmojiCount = message.Entities |> Array.where(fun e -> e.Type = MessageEntityType.CustomEmoji) |> Array.length

if customEmojiCount = 0 || textLen = 0 then
Expand All @@ -518,6 +518,7 @@ let calculateCustomEmojiProportion
let proportion = float customEmojiCount / float textLen
Some proportion


let justMessage
(botUser: DbUser)
(botClient: ITelegramBotClient)
Expand Down Expand Up @@ -591,7 +592,7 @@ let justMessage
if not messageIsDeleted
&& botConfig.BanCustomEmojiEnabled
&& message.TextOrCaption <> null
&& botUser.created_at > DateTime.Now.AddDays(-botConfig.BanCustomEmojiRegisteredInDbDaysToDontBan)
&& botUser.created_at <= DateTime.Now.AddDays(-botConfig.BanCustomEmojiRegisteredInDbDaysToDontBan)
&& message.TextOrCaption.Length >= botConfig.BanCustomEmojiTextMinLen
then
let! usrMsgCount = DB.countUniqueUserMsg message.From.Id
Expand Down
2 changes: 1 addition & 1 deletion src/VahterBanBot/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ let botConf =
BanCustomEmojiProportionToBan = getEnvOr "BAN_CUSTOM_EMOJI_PROPORTION_TO_BAN" "0.3" |> float
BanCustomEmojiPreviousMessagesCountToDontBan = getEnvOr "BAN_CUSTOM_EMOJI_PREVIOUS_MESSAGES_COUNT_TO_DONT_BAN" "5" |> int32
BanCustomEmojiRegisteredInDbDaysToDontBan = getEnvOr "BAN_CUSTOM_EMOJI_REGISTERED_IN_DB_DAYS_TO_DONT_BAN" "80" |> int32
BanCustomEmojiTextMinLen = getEnvOr "BAN_CUSTOM_TEXT_MIN_LEN" "10" |> int32}
BanCustomEmojiTextMinLen = getEnvOr "BAN_CUSTOM_EMOJI_TEXT_MIN_LEN" "10" |> int32}

let validateApiKey (ctx : HttpContext) =
match ctx.TryGetRequestHeader "X-Telegram-Bot-Api-Secret-Token" with
Expand Down

0 comments on commit 03124ea

Please sign in to comment.