Rework check invite logic a little

This commit is contained in:
Joseph Ferano 2022-06-18 22:09:15 +07:00
parent 9e85a53de1
commit f5336fb9b7

View File

@ -135,18 +135,14 @@ let private checkUserAlreadyInvited userId = async {
}
let checkInviteAccepted (userId : uint64) = async {
try
let! result =
connStr
|> Sql.connect
|> Sql.parameters [ "did" , Sql.string (string userId) ]
|> Sql.query "SELECT accepted FROM invited_user WHERE discord_id = @did"
|> Sql.executeRowAsync (fun read -> read.bool "accepted")
|> Sql.executeAsync (fun read -> read.bool "accepted")
|> Async.AwaitTask
return result
with ex ->
printfn "%s %u" ex.Message userId
return false
return List.tryHead result |> Option.defaultValue false
}
let private getInviteAttributions userId =
@ -306,7 +302,7 @@ let acceptInvite (guild : DiscordGuild) (user : DiscordMember) =
task {
match! checkInviteAccepted user.Id with
| false ->
let! _ = markInvitedAccepted user.Id |> Async.Ignore
do! markInvitedAccepted user.Id |> Async.Ignore
try
let! invite = getInviteFromInvitedUser user.Id
let! player = DbService.tryFindPlayer invite.Inviter