Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start");

            try
            {
                TdLog.SetVerbosityLevel(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                Console.WriteLine("End");
            }

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static async Task Main(string[] args)
        {
            TdLog.SetVerbosityLevel(0);
            _client = new TdClient();

            _client.UpdateReceived += async(sender, update) =>
            {
                switch (update)
                {
                case TdApi.Update.UpdateOption option:
                    await _client.ExecuteAsync(new TdApi.SetOption
                    {
                        DataType = option.DataType,
                        Extra    = option.Extra,
                        Name     = option.Name,
                        Value    = option.Value
                    });

                    break;

                case TdApi.Update.UpdateAuthorizationState updateAuthorizationState when updateAuthorizationState.AuthorizationState.GetType() == typeof(TdApi.AuthorizationState.AuthorizationStateWaitTdlibParameters):
                    await _client.ExecuteAsync(new TdApi.SetTdlibParameters
                    {
                        Parameters = new TdApi.TdlibParameters
                        {
                            ApiId              = ApiId,
                            ApiHash            = ApiHash,
                            ApplicationVersion = "1.3.0",
                            DeviceModel        = "PC",
                            SystemLanguageCode = "en",
                            SystemVersion      = "Win 10.0"
                        }
                    });

                    break;

                case TdApi.Update.UpdateAuthorizationState updateAuthorizationState when updateAuthorizationState.AuthorizationState.GetType() == typeof(TdApi.AuthorizationState.AuthorizationStateWaitEncryptionKey):
                    await _client.ExecuteAsync(new TdApi.CheckDatabaseEncryptionKey());

                    break;

                case TdApi.Update.UpdateAuthorizationState updateAuthorizationState when updateAuthorizationState.AuthorizationState.GetType() == typeof(TdApi.AuthorizationState.AuthorizationStateWaitPhoneNumber):
                    _authNeeded = true;

                    ResetEvent.Set();
                    break;

                case TdApi.Update.UpdateAuthorizationState updateAuthorizationState when updateAuthorizationState.AuthorizationState.GetType() == typeof(TdApi.AuthorizationState.AuthorizationStateWaitCode):
                    _authNeeded = true;

                    ResetEvent.Set();
                    break;

                case TdApi.Update.UpdateUser updateUser:
                    ResetEvent.Set();
                    break;

                case TdApi.Update.UpdateConnectionState updateConnectionState when updateConnectionState.State.GetType() == typeof(TdApi.ConnectionState.ConnectionStateReady):
                    break;

                default:
                    ;     // add a breakpoint here to see other events
                    break;
                }
            };

            ResetEvent.Wait();
            if (_authNeeded)
            {
                await _client.ExecuteAsync(new TdApi.SetAuthenticationPhoneNumber
                {
                    PhoneNumber = PhoneNumber
                });

                Console.Write("Insert the login code: ");
                var code = Console.ReadLine();
                await _client.ExecuteAsync(new TdApi.CheckAuthenticationCode
                {
                    Code = code
                });
            }

            await foreach (var chat in GetChannels())
            {
                Console.WriteLine(chat.Title);
            }

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        public async Task CreateInstance()
        {
            TDLibHostBot = this;

            _client = new TdClient();
            TdLog.SetVerbosityLevel(0);

            _client.UpdateReceived += async(sender, update) =>
            {
                switch (update)
                {
                case Update.UpdateOption option:
                    await _client.ExecuteAsync(new SetOption
                    {
                        DataType = option.DataType,
                        Extra    = option.Extra,
                        Name     = option.Name,
                        Value    = option.Value
                    });

                    break;

                case Update.UpdateAuthorizationState updateAuthorizationState when updateAuthorizationState.AuthorizationState.GetType() == typeof(AuthorizationState.AuthorizationStateWaitTdlibParameters):
                    await _client.ExecuteAsync(new SetTdlibParameters
                    {
                        Parameters = new TdlibParameters
                        {
                            ApiId                  = SecretKeys.API_ID,
                            ApiHash                = SecretKeys.API_HASH,
                            ApplicationVersion     = "1.0.0",
                            DeviceModel            = "PC",
                            SystemLanguageCode     = "en",
                            SystemVersion          = "Win 10.0",
                            DatabaseDirectory      = Path.Combine(Directory.GetCurrentDirectory(), "tdlib"),
                            EnableStorageOptimizer = true,
                            FilesDirectory         = Path.Combine(Directory.GetCurrentDirectory(), "tdlib")
                        }
                    });

                    break;

                case Update.UpdateAuthorizationState updateAuthorizationState when updateAuthorizationState.AuthorizationState.GetType() == typeof(AuthorizationState.AuthorizationStateWaitEncryptionKey):
                    await _client.ExecuteAsync(new CheckDatabaseEncryptionKey());

                    break;

                case Update.UpdateAuthorizationState updateAuthorizationState when updateAuthorizationState.AuthorizationState.GetType() == typeof(AuthorizationState.AuthorizationStateWaitCode):
                case Update.UpdateAuthorizationState updateAuthorizationState2 when updateAuthorizationState2.AuthorizationState.GetType() == typeof(AuthorizationState.AuthorizationStateWaitPhoneNumber):
                    _authNeeded = true;

                    ResetEvent.Set();
                    break;

                case Update.UpdateUser updateUser:
                    break;

                case Update.UpdateConnectionState updateConnectionState when updateConnectionState.State.GetType() == typeof(ConnectionState.ConnectionStateReady):
                    ResetEvent.Set();

                    ReadyEvent.Set();
                    break;

                case Update.UpdateMessageSendFailed uwu:
                case Update.UpdateMessageSendSucceeded uwu2:
                    //what happens ?
                    //BIG *RIP*
                    UploadedEvent.Set();
                    break;

                default:
                    break;
                }
            };

#if !PRODUCTION
            await Cont(TelegramBotSettings.DEV_CHANNEL);
#else
            await Cont(TelegramBotSettings.PROD_CHANNEL);
#endif
        }
Ejemplo n.º 4
0
 public void StartSession()
 {
     TdLog.SetVerbosityLevel(0);
     _client = new TdClient();
     _client.UpdateReceived += client_UpdateReceived;
 }