Exemple #1
0
        public async Task <InlineKeyboardMarkup> DynamicButtonsForReal(int userid)
        {
            DBCheck c = new DBCheck();

            using var client = new HttpClient();
            //UserList dBUserItemsDBFind = JsonConvert.DeserializeObject<UserList>(System.IO.File.ReadAllText(path));
            string money = await client.GetStringAsync("https://crmonapi.azurewebsites.net/crypto/user/realget/" + userid);

            money = JsonConvert.DeserializeObject <string>(money);
            //int ind = c.DBIndex(dBUserItemsDBFind, userid);
            //string[] cur = dBUserItemsDBFind.users[ind].Real.Split(new char[] { ',' });
            string[]      cur  = money.Split(new char[] { ',' });
            List <string> list = new List <string>(cur);

            for (int i = 0; i < list.Count; i++)
            {
                list[i] = list[i].ToUpper();
            }
            List <List <InlineKeyboardButton> > inlineKeyboardList = new List <List <InlineKeyboardButton> >();

            foreach (var a in list)//динамичные кнопочки
            {
                List <InlineKeyboardButton> ts = new List <InlineKeyboardButton>();
                ts.Add(InlineKeyboardButton.WithCallbackData(a, a));
                inlineKeyboardList.Add(ts);
            }
            var inline = new InlineKeyboardMarkup(inlineKeyboardList);

            return(inline);
        }
Exemple #2
0
        private static async void Bot_OnCallbackQuery(object sender, Telegram.Bot.Args.CallbackQueryEventArgs e)
        {
            Keyboards            keyboards       = new Keyboards();
            InlineKeyboardMarkup keyboard_inline = keyboards.SwitchMenu();
            API_DBLogic          DBLogic         = new API_DBLogic();
            MsgReply             Reply           = new MsgReply();
            DBCheck c          = new DBCheck();
            string  buttonText = e.CallbackQuery.Data;
            string  name       = $"{e.CallbackQuery.From.FirstName} {e.CallbackQuery.From.LastName}";

            Console.WriteLine($"{name} with id {e.CallbackQuery.From.Id} clicked button: '{buttonText}'");
            //int maxvalue = await DBLogic.MaxValueCrypto();
            int  maxvalue  = 2115; //поставить выше или максимальное значение - тихий омут, теневой и криминальный сброд, неактивные криптовалюты, аут оф рейндж
            bool keyExists = user_status.ContainsKey(e.CallbackQuery.From.Id);

            if (keyExists == false)
            {
                await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.ChooseCommandPlease);

                return;
            }
            if (user_status[e.CallbackQuery.From.Id] == "change_crypto_mode")
            {
                var x = await c.CryptoCheck(buttonText);

                if (x == System.Net.HttpStatusCode.OK)
                {
                    bool exist = await c.CryptoExist(buttonText, e.CallbackQuery.From.Id.ToString());

                    if (exist == false)
                    {
                        await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.ButtonState);

                        return;
                    }
                    else
                    {
                        await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.ChangeCryptoInstruction2);
                    }
                }
                else
                {
                    await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.ButtonState);

                    return;
                }


                bool ex = currency_to_change_from_button.ContainsKey(e.CallbackQuery.From.Id);
                if (ex == false)
                {
                    currency_to_change_from_button.Add(e.CallbackQuery.From.Id, buttonText.ToLower());
                }
                else
                {
                    currency_to_change_from_button[e.CallbackQuery.From.Id] = buttonText.ToLower();
                }
                user_status[e.CallbackQuery.From.Id] = "change_crypto_mode_part2";
            }
            if (user_status[e.CallbackQuery.From.Id] == "remove_crypto_mode")
            {
                Thread.Sleep(900);
                var y = await c.CryptoCheck(buttonText);

                if (y != System.Net.HttpStatusCode.OK)
                {
                    await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.ButtonState);

                    return;
                }
                var x = await DBLogic.RemoveCrypto(buttonText, e.CallbackQuery.From.Id);

                if (x == System.Net.HttpStatusCode.NoContent)
                {
                    await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.Success);

                    //user_status[e.CallbackQuery.From.Id] = "normal";
                    return;
                }
                if (x == System.Net.HttpStatusCode.MethodNotAllowed)
                {
                    await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.RemoveCryptoFailure);

                    //user_status[e.CallbackQuery.From.Id] = "normal";
                    return;
                }
                if (x == System.Net.HttpStatusCode.NotFound)
                {
                    await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.Error_CryCurrNotFound);

                    //user_status[e.CallbackQuery.From.Id] = "normal";
                    return;
                }
            }
            if (user_status[e.CallbackQuery.From.Id] == "crypto_mode")
            {
                Thread.Sleep(755);
                try
                {
                    string x = await DBLogic.Crypto(buttonText, e.CallbackQuery.From.Id);

                    await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, x);

                    //user_status[e.CallbackQuery.From.Id] = "normal";
                    return;
                }
                catch
                {
                    await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.ButtonState);

                    return;
                }
                //string x = await DBLogic.Crypto(buttonText, e.CallbackQuery.From.Id);
                //await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, x);
                ////user_status[e.CallbackQuery.From.Id] = "normal";
                //return;
            }
            if (user_status[e.CallbackQuery.From.Id] == "remove_real_mode")
            {
                Thread.Sleep(751);
                var y = await c.RealCheck(buttonText);

                if (y != System.Net.HttpStatusCode.OK)
                {
                    await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.ButtonState);

                    return;
                }
                var x = await DBLogic.RemoveReal(buttonText, e.CallbackQuery.From.Id);

                if (x == System.Net.HttpStatusCode.NoContent)
                {
                    await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.Success);

                    //user_status[e.CallbackQuery.From.Id] = "normal";
                    return;
                }
                if (x == System.Net.HttpStatusCode.MethodNotAllowed)
                {
                    await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.RemoveRealFailure);

                    //user_status[e.CallbackQuery.From.Id] = "normal";
                    return;
                }
                if (x == System.Net.HttpStatusCode.NotFound)
                {
                    await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.Error_CurrNotFound);

                    //user_status[e.CallbackQuery.From.Id] = "normal";
                    return;
                }
            }
            if (user_status[e.CallbackQuery.From.Id] == "show_supported_cryptos_mode")
            {
                bool command = DBLogic.ChechCommand(e.CallbackQuery.Message.Text);
                if (command != true)
                {
                    if (buttonText == "Вперед")
                    {
                        if (message_to_edit == null)
                        {
                            return;
                        }
                        else
                        {
                            message_to_edit[e.CallbackQuery.From.Id].Count += 15;
                            if (message_to_edit[e.CallbackQuery.From.Id].Count > maxvalue)
                            {
                                message_to_edit[e.CallbackQuery.From.Id].Count = 0;
                            }
                            List <string> cryptos = await DBLogic.Forward(message_to_edit[e.CallbackQuery.From.Id].Count);

                            string combindedString = string.Join("; ", cryptos.ToArray());
                            try { await Bot.EditMessageTextAsync(e.CallbackQuery.From.Id, message_to_edit[e.CallbackQuery.From.Id].Message.MessageId, combindedString, replyMarkup : keyboard_inline); }
                            catch { }
                        }
                    }
                    if (buttonText == "Назад")
                    {
                        if (message_to_edit == null)
                        {
                            return;
                        }
                        else
                        {
                            message_to_edit[e.CallbackQuery.From.Id].Count -= 15;
                            if (message_to_edit[e.CallbackQuery.From.Id].Count < 0)
                            {
                                message_to_edit[e.CallbackQuery.From.Id].Count = maxvalue;
                            }
                            List <string> cryptos = await DBLogic.Forward(message_to_edit[e.CallbackQuery.From.Id].Count);

                            string combindedString = string.Join("; ", cryptos.ToArray());
                            try { await Bot.EditMessageTextAsync(e.CallbackQuery.From.Id, message_to_edit[e.CallbackQuery.From.Id].Message.MessageId, combindedString, replyMarkup : keyboard_inline); }
                            catch { }
                        }
                    }
                    if (buttonText != "Назад" && buttonText != "Вперед")
                    {
                        await Bot.SendTextMessageAsync(e.CallbackQuery.From.Id, Reply.ButtonState_supportedcrypto);
                    }
                }
                else
                {
                    user_status[e.CallbackQuery.From.Id] = "normal";
                }
            }
        }