Skip to content

Commit

Permalink
Send "do nothing" flag - if we tried to unban not banned user (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keroosha authored Aug 15, 2023
1 parent 508b3cb commit e405e34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/Grinder/Funogram.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ let callApiWithDefaultRetry config = callApiWithRetry config 5
module ApiExt =
type UnbanChatMemberReq =
{ ChatId: ChatId
UserId: int64 }
UserId: int64
OnlyIfBanned: Boolean }
interface IRequestBase<bool> with
member __.MethodName = "unbanChatMember"

Expand All @@ -54,8 +55,8 @@ module ApiExt =
interface IRequestBase<bool> with
member __.MethodName = "restrictChatMember"

let unbanChatMemberByChatNameExt chatName userId : UnbanChatMemberReq =
{ ChatId = ChatId.String chatName; UserId = userId }
let unbanChatMemberByChatNameExt chatName userId onlyIfBanned : UnbanChatMemberReq =
{ ChatId = ChatId.String chatName; UserId = userId; OnlyIfBanned = onlyIfBanned }

let restrictChatMemberBaseExt chatId userId (untilDate: DateTime) canSendMessages canSendMediaMessages canSendOtherMessages canAddWebPagePreviews =
let seconds = int64 (untilDate.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds
Expand Down Expand Up @@ -92,11 +93,11 @@ module ApiExt =
return Error <| sprintf "Failed to ban %i in chat %s. Description: %s" userId chat e.Description
}

let unbanUserByUsername context chat username = async {
let unbanUserByUsername context chat username onlyIfBanned = async {
match! Datastore.findUserIdByUsername username with
| UserIdFound userId ->
let! unbanResult =
unbanChatMemberByChatNameExt chat userId
unbanChatMemberByChatNameExt chat userId onlyIfBanned
|> callApiWithDefaultRetry context
match unbanResult with
| Ok _ ->
Expand Down
2 changes: 1 addition & 1 deletion src/Grinder/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module Program =
member __.UnbanUser chatUsername username: Async<Result<unit, string>> =
sprintf "Unbanning user %A in chat %A" username chatUsername
|> logInfo
ApiExt.unbanUserByUsername config %chatUsername %username
ApiExt.unbanUserByUsername config %chatUsername %username true // Do nothing if user not banned

member __.SendTextMessage chatId text: Async<unit> =
sprintf "Sending {%s} into chat %A" text chatId
Expand Down

0 comments on commit e405e34

Please sign in to comment.