Ejemplo n.º 1
0
        public static void Bot_OnMessage(Update e, TelegramBotClient service_bot)
        {
            Chat chat = e.Message.Chat;

            bot = service_bot;
            //text handling
            if (e.Message.Type == MessageType.Text)
            {
                string message = e.Message.Text;
                settings = chat_options.Where(x => x.Id == chat.Id).FirstOrDefault();
                if (settings == null)
                {
                    settings = new Options_Handler {
                        Id = chat.Id, Lang = "en"
                    };
                    chat_options.Add(settings);
                }//else
                 //    settings.Read_Settings();

                replay = _Get_Command_Value("Welcome", settings.Lang);
                switch (message)
                {
                case @"/start":

                    replay = _Command_List(settings, out commands);
                    Send_Message(replay, chat, commands);
                    break;

                case @"/cancel":
                    settings.ExpectedEntry = "";
                    replay = _Command_List(settings, out commands);
                    Send_Message(replay, chat, commands);
                    break;

                case @"/add_user":
                    _Add_User(new Options_Handler {
                        Id = chat.Id, Email = "*****@*****.**", Password = "******", FirstName = chat.FirstName, LastName = chat.LastName
                    });
                    break;

                case "/cal":
                    settings         = chat_options.Where(x => x.Id == chat.Id).FirstOrDefault();
                    settings.Url_ext = 0.ToString();
                    var country_buttons = _Country_List_Filters(settings);
                    Send_Message(replay, chat, country_buttons, 0);
                    replay = _Country_List(settings, out commands);
                    Send_Message(replay, chat, commands);
                    break;

                case @"/display_param":
                    //chat_options.Clear();
                    settings = chat_options.Where(x => x.Id == chat.Id).FirstOrDefault();
                    if (settings != null)
                    {
                        Send_Message(
                            "Id: " + settings.Id +
                            " , Cat= " + settings.Cat +
                            " , Type= " + settings.Type +
                            " , Gar= " + settings.Garage +
                            " , grd= " + settings.Garden
                            , chat, commands);
                    }
                    break;

                default:
                    string command_en, command_ar;
                    _Get_Input_Commands(message, out command_en, out command_ar);
                    if (!(
                            _Lang(command_en, command_ar, chat) ||
                            _Search(command_en, command_ar, chat) ||
                            _Other(command_en, command_ar, chat) ||
                            _Login(command_en, command_ar, chat) ||
                            _Insert(command_en, command_ar, chat) ||
                            _Update(command_en, command_ar, chat) ||
                            _Check_Entry(settings, message, command_en, command_ar, chat)
                            ))
                    {
                        replay = _Command_List(settings, out commands);
                        settings.ExpectedEntry = "";
                        Send_Message(replay, chat, commands);
                    }
                    break;
                }
            }
            //location handling
            if (e.Message.Type == MessageType.Location)
            {
                var user_option = chat_options.Where(x => x.Id == chat.Id).FirstOrDefault();
                if (user_option == null)
                {
                    user_option = new Options_Handler {
                        Id = chat.Id
                    };
                    chat_options.Add(user_option);
                }
                _Check_Insert_Value_Location(user_option, e.Message.Location.Latitude.ToString(), e.Message.Location.Longitude.ToString());
                if (user_option.ExpectedEntry == "Insert_Location")
                {
                    user_option.ExpectedEntry = "Insert_Photo";
                    replay = _Get_Command_Value("Insert_Photo", settings.Lang);
                    Send_Message(replay, chat, null);
                }
                if (user_option.ExpectedEntry == "Update_Location")
                {
                    user_option.ExpectedEntry = "Update_Select_Option";
                    replay = _Update_Confirm_List(settings, out commands);
                    Send_Message(replay, chat, commands);
                }
            }
            //photo handling
            if (e.Message.Type == MessageType.Photo)
            {
                var photo = e.Message.Photo[e.Message.Photo.Length - 1];

                var user_option = chat_options.Where(x => x.Id == chat.Id).FirstOrDefault();
                if (user_option == null)
                {
                    user_option = new Options_Handler {
                        Id = chat.Id
                    };
                    chat_options.Add(user_option);
                }
                _Check_Insert_Value_Photo(user_option, photo);
                if (user_option.ExpectedEntry == "Insert_Photo")
                {
                    replay = _Insert_Confirm_List(user_option, out commands);
                    Send_Message(replay, chat, commands);
                }
                if (user_option.ExpectedEntry == "Update_Photo")
                {
                    user_option.ExpectedEntry = "Update_Select_Option";
                    replay = _Update_Confirm_List(settings, out commands);
                    Send_Message(replay, chat, commands);
                }
            }
            //callback query
            if (e.Type == UpdateType.CallbackQuery)
            {
                if (settings == null)
                {
                    settings = new Options_Handler {
                        Id = e.Message.Chat.Id, Date = DateTime.Now
                    };
                    chat_options.Add(settings);
                }
                if (e.CallbackQuery.Data.Contains("calender-day"))
                {
                    if (e.CallbackQuery.Data != "calender-day-")
                    {
                        string day = e.CallbackQuery.Data.Replace("calender-day-", "");
                        settings = chat_options.Where(x => x.Id == chat.Id).FirstOrDefault();
                        if (settings == null)
                        {
                            settings = new Options_Handler {
                                Id = chat.Id, Date = DateTime.Now
                            };
                            chat_options.Add(settings);
                        }
                        // day = settings.Date.Year + "-" + settings.Date.Month + "-" + day;
                        settings.Expire_Date = new DateTime(settings.Date.Year, settings.Date.Month, int.Parse(day));
                        bot.DeleteMessageAsync(chat, e.CallbackQuery.Message.MessageId);
                        settings.ExpectedEntry = "Insert_Floor_Num";
                        replay = _Get_Command_Value("Insert_Floor", settings.Lang);
                        Send_Message(replay, chat, null);
                    }
                }
                settings = chat_options.Where(x => x.Id == chat.Id).FirstOrDefault();
                if (e.CallbackQuery.Data == "next-month")
                {
                    bot.DeleteMessageAsync(chat, e.CallbackQuery.Message.MessageId);
                    settings.Date = settings.Date.AddMonths(1);
                    var calender = Calender.Create_Calender(null, settings.Date.Year, settings.Date.Month);
                    Send_Message(replay, chat, calender, 0);
                }
                if (e.CallbackQuery.Data == "previous-month")
                {
                    bot.DeleteMessageAsync(chat, e.CallbackQuery.Message.MessageId);
                    settings.Date = settings.Date.Month < DateTime.Now.Month ? settings.Date : settings.Date.AddMonths(-1);
                    var calender = Calender.Create_Calender(null, settings.Date.Year, settings.Date.Month);
                    Send_Message(replay, chat, calender, 0);
                }
                if (e.CallbackQuery.Data == "previous-country")
                {
                    bot.DeleteMessageAsync(chat, e.CallbackQuery.Message.MessageId);
                    if (!string.IsNullOrEmpty(settings.Url_ext))
                    {
                        settings.Url_ext = (int.Parse(settings.Url_ext) - 100).ToString();
                    }
                    else
                    {
                        settings.Url_ext = 0.ToString();
                    }
                    var country_buttons = _Country_List_Filters(settings);
                    Send_Message(replay, chat, country_buttons, 0);
                    replay = _Country_List(settings, out commands);
                    Send_Message(replay, chat, commands);
                }
                if (e.CallbackQuery.Data == "next-country")
                {
                    bot.DeleteMessageAsync(chat, e.CallbackQuery.Message.MessageId);
                    if (!string.IsNullOrEmpty(settings.Url_ext))
                    {
                        settings.Url_ext = (int.Parse(settings.Url_ext) < 0 ? 0 : int.Parse(settings.Url_ext) + 100).ToString();
                    }
                    else
                    {
                        settings.Url_ext = 0.ToString();
                    }
                    var country_buttons = _Country_List_Filters(settings);
                    Send_Message(replay, chat, country_buttons, 0);
                    replay = _Country_List(settings, out commands);
                    Send_Message(replay, chat, commands);
                }
            }
        }
Ejemplo n.º 2
0
        public static bool _Check_Input_Insert(Options_Handler handler, string message, string command_en, string command_ar, Chat chat)
        {
            bool hit         = false;
            var  user_option = chat_options.Where(x => x.Id == handler.Id).FirstOrDefault();

            switch (user_option.ExpectedEntry)
            {
            case "Insert_Cat":
                user_option.ExpectedEntry = "Insert_Typ";
                string cat = _Category_List_Check(command_en, command_ar);
                replay      = _Get_Command_Value("Search_Select_Typ", settings.Lang);
                user_option = chat_options.Where(x => x.Id == handler.Id).FirstOrDefault();
                if (user_option != null)
                {
                    //command_en
                    user_option.Cat = cat;
                }
                else
                {
                    chat_options.Add(new Options_Handler {
                        Cat = cat, Id = chat.Id
                    });
                }
                _Type_List(settings, cat, out commands, true);
                Send_Message(replay, chat, commands); hit = true;
                break;

            case "Insert_Typ":
                user_option.ExpectedEntry = "Insert_Exp";
                replay = _Get_Command_Value("Search_Select_Exp", settings.Lang);
                string typ = _Type_List_Check(command_en, command_ar);
                user_option = chat_options.Where(x => x.Id == handler.Id).FirstOrDefault();
                if (user_option != null)
                {
                    user_option.Type = typ;
                }
                else
                {
                    chat_options.Add(new Options_Handler {
                        Type = typ, Id = chat.Id
                    });
                }
                if (user_option.Date.Year < DateTime.Now.Year - 1)
                {
                    user_option.Date = DateTime.Now;
                }
                var calender = Calender.Create_Calender(handler, DateTime.Now.Year, DateTime.Now.Month + 3);
                Send_Message(replay, chat, calender, 0); hit = true;
                break;

            case "Insert_Exp":
                user_option.ExpectedEntry = "Insert_Floor_Num";
                replay      = _Get_Command_Value("Insert_Floor", settings.Lang);
                user_option = chat_options.Where(x => x.Id == handler.Id).FirstOrDefault();
                if (user_option.Date == DateTime.Now)
                {
                    user_option.Date = DateTime.Now.AddMonths(3);
                }
                Send_Message(replay, chat, null); hit = true;
                break;

            case "Insert_Floor_Num":
                hit = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Num_Bed", "Insert_Floor_Invalid");
                break;

            case "Insert_Num_Bed":
                hit = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Num_Bath", "Insert_Num_Bed_Invalid");
                break;

            case "Insert_Num_Bath":
                hit = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Floors", "Insert_Num_Bath_Invalid");
                break;

            case "Insert_Floors":
                hit = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Size", "Insert_Floors_Invalid");
                break;

            case "Insert_Size":
                hit = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Zip_Code", "Insert_Size_Invalid");
                break;

            case "Insert_Zip_Code":
                hit = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Country", "Insert_Zip_Code_Invalid");
                if (!string.IsNullOrEmpty(settings.Url_ext))
                {
                    settings.Url_ext = (int.Parse(settings.Url_ext) - 100).ToString();
                }
                else
                {
                    settings.Url_ext = 0.ToString();
                }
                var country_buttons = _Country_List_Filters(settings);
                Send_Message(replay, chat, country_buttons, 0);
                replay = _Country_List(settings, out commands);
                Send_Message(replay, chat, commands);
                break;

            case "Insert_Country":
                hit    = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_City", "Insert_Country_Invalid");
                replay = _City_List(settings, out commands);
                Send_Message(replay, chat, commands); hit = true;
                break;

            case "Insert_City":
                hit    = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Garage", "Insert_City_Invalid");
                replay = _Garage_List(settings, out commands);
                Send_Message(replay, chat, commands); hit = true;
                break;

            case "Insert_Garage":
                hit    = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Garden", "Insert_Garage_Invalid");
                replay = _Garden_List(settings, out commands);
                Send_Message(replay, chat, commands); hit = true;
                break;

            case "Insert_Garden":
                hit = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Other_Details", "Insert_Garden_Invalid");
                break;

            case "Insert_Other_Details":
                hit = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Sale_Price", "Insert_Other_Details_Invalid");
                break;

            case "Insert_Sale_Price":
                hit = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Rent_Price", "Insert_Rent_Price_Invalid");
                break;

            case "Insert_Rent_Price":
                hit = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Address", "Insert_Rent_Price_Invalid");
                break;

            case "Insert_Address":
                hit = _Check_Insert_Value_Int(user_option, handler, message, chat, "Insert_Location", "Insert_Addess_Invalid");
                break;
            }
            return(hit);
        }