Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- open System.Threading
- open TdLib
- let awaitTask task = task |> Async.AwaitTask |> Async.RunSynchronously
- let awaitTaskUnit task = task |> awaitTask |> ignore
- type Wtf() =
- static member ApiId = 0
- static member ApiHash = ""
- static member PhoneNumber = "" // must contain prefix
- static member ResetEvent = ManualResetEventSlim()
- static member val AuthNeeded = false with get, set
- static member val Client = TdClient() with get, set
- TdLog.SetVerbosityLevel(0)
- Wtf.Client <- TdClient()
- Wtf.Client.UpdateReceived.Add(
- fun (update : TdApi.Update) ->
- match update with
- | :? TdApi.Update.UpdateOption as o ->
- Wtf.Client.ExecuteAsync(TdApi.SetOption(Extra = o.Extra, Name = o.Name, Value = o.Value, DataType = o.DataType))
- |> awaitTaskUnit
- | :? TdApi.Update.UpdateAuthorizationState as updateAuthorizationState ->
- match updateAuthorizationState.AuthorizationState with
- | :? TdApi.AuthorizationState.AuthorizationStateWaitTdlibParameters ->
- Wtf.Client.ExecuteAsync(TdApi.SetTdlibParameters(
- Parameters = TdApi.TdlibParameters(
- ApiId = Wtf.ApiId,
- ApiHash = Wtf.ApiHash,
- ApplicationVersion = "1.3.0",
- DeviceModel = "PC",
- SystemLanguageCode = "en",
- SystemVersion = "Win 10.0")))
- |> awaitTaskUnit
- | :? TdApi.AuthorizationState.AuthorizationStateWaitEncryptionKey ->
- Wtf.Client.ExecuteAsync(TdApi.CheckDatabaseEncryptionKey())
- |> awaitTaskUnit
- | ( :? TdApi.AuthorizationState.AuthorizationStateWaitPhoneNumber
- | :? TdApi.AuthorizationState.AuthorizationStateWaitCode ) ->
- Wtf.AuthNeeded <- true
- Wtf.ResetEvent.Set()
- | _ -> ()
- | :? TdApi.Update.UpdateUser -> Wtf.ResetEvent.Set()
- | _ -> () (* add a breakpoint here to see other events *) )
- Wtf.ResetEvent.Wait()
- if Wtf.AuthNeeded then
- Wtf.Client.ExecuteAsync(TdApi.SetAuthenticationPhoneNumber(PhoneNumber = Wtf.PhoneNumber))
- |> awaitTaskUnit
- Console.Write("Insert the login code: ")
- let code = Console.ReadLine()
- Wtf.Client.ExecuteAsync(TdApi.CheckAuthenticationCode(Code = code))
- |> awaitTaskUnit
- let GetChannels(offsetOrder : int64 option, offsetId : int64 option, limit : int option) =
- let offsetOrder_ = defaultArg offsetOrder Int64.MaxValue
- let offsetId_ = defaultArg offsetId 0L
- let limit_ = defaultArg limit 1000
- let chats = Wtf.Client.ExecuteAsync(TdApi.GetChats(OffsetOrder=offsetOrder_, Limit=limit_, OffsetChatId=offsetId_))
- |> awaitTask
- seq {
- for chatId in chats.ChatIds do
- let chat = Wtf.Client.ExecuteAsync(TdApi.GetChat(ChatId = chatId)) |> awaitTask
- match chat.Type with
- | ( :? TdApi.ChatType.ChatTypeSupergroup
- | :? TdApi.ChatType.ChatTypeBasicGroup
- | :? TdApi.ChatType.ChatTypePrivate ) -> yield chat
- | _ -> ()
- }
- for chat in GetChannels(None, None, None) do Console.WriteLine(chat.Title)
- Console.ReadLine() |> ignore
Add Comment
Please, Sign In to add comment