Example #1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Freshy EdgeUpdate Bot!");
            Console.WriteLine("Release version: " + TelegramBotSettings.BOT_VERSION);

            Console.WriteLine("\nInitializing Directories...");
            InitializeDirectory();

            Console.WriteLine("\nInitializing Database...");
            Db = new DBEngine();

            Console.WriteLine("\nInitializing TDLIB engine...");
            TDLibHost tdHost = new TDLibHost();

            Console.WriteLine("\nTDLIB engine ready!");

            Task.Factory.StartNew(o => SearchAutomation.PreExecute(), null, TaskCreationOptions.LongRunning);

            string cmd = "";

            do
            {
                cmd = Console.ReadKey().KeyChar.ToString().ToLower();
            } while (cmd != "q");
        }
Example #2
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
        }