private async void SendMoneyRequest(string text, Gamer me, List <Gamer> list, MessageEventArgs args) { var user = GetGamer(text[0], list); text = text.Remove(0, 1); text = text.Trim(); try { float tempMoney = Convert.ToSingle(text); me.PayTo(tempMoney, user); } catch (FormatException) { await Client.SendTextMessageAsync(args.Message.Chat.Id, "Неверный ввод", ParseMode.Default, false, false, 0, KeyboardConstructor.Keyboard()); } }
private async void MessageHandlerAsync(object sender, MessageEventArgs args) { if (sender is TelegramBotClient && args.Message.Text != null) { var CommandsList = new Commands(); if (!CommandsList.ContainsActivatedCommand(args) && args.Message.Text[0] != '/') { AddText($"Попытка взаимодействия пользователя {args.Message.Chat.FirstName} {args.Message.Chat.LastName} ({args.Message.Chat.Id} - {args.Message.Chat.Username})"); var GamerList = JsonConvert.DeserializeObject <List <Gamer> >(File.ReadAllText(usersPath)); if (IsPlayerExist(args.Message.Chat.Id, GamerList)) { var Me = GetGamer(args.Message.Chat.Id, GamerList); if (IsSendMoneyRequest(args.Message.Text, GamerList)) { SendMoneyRequest(args.Message.Text, Me, GamerList, args); } else if (IsHouseRequest(args.Message.Text, Me, args)) { string[] cities = GetGoodRequest(GetBuildHouseRequest(args.Message.Text), Me); if (args.Message.Text[0] == '+') { for (int i = 0; i < cities.Length; i++) { Me.BuildHouse(Me.properties.Find(item => item.name == cities[i])); } } else { for (int i = 0; i < cities.Length; i++) { Me.DemolishHouse(Me.properties.Find(item => item.name == cities[i])); } } } else if (IsPayRentOrBuyCityRequest(args.Message.Text)) { if (IsPayRentRequest(args.Message.Text, GamerList)) { Me.PayRent(GetPayRentProp(args.Message.Text, GamerList), GamerList); } else { Me.Buy(new Property(args.Message.Text)); } } else if (IsSendPropertyRequest(args.Message.Text, Me)) { var tempGamer = FindGamer(args.Message.Text[0], GamerList); Me.SendPropertyTo(GetProperty(args.Message.Text, Me), tempGamer); } else if (args.Message.Text[0] == '+' || args.Message.Text[0] == '-') { Stonks(args.Message.Text, Me, args); } else if (args.Message.Text == "Вперед") { Me.PayMe(2); } else { await Client.SendTextMessageAsync(args.Message.Chat.Id, "Неверный ввод", ParseMode.Default, false, false, 0, KeyboardConstructor.Keyboard()); } await Client.SendTextMessageAsync(args.Message.Chat.Id, $"Ваш баланс: {Me.money.ToString("0.000")}M", ParseMode.Default, false, false, 0, KeyboardConstructor.Keyboard()); } else { await Client.SendTextMessageAsync(args.Message.Chat.Id, "Ты не в игре лол", ParseMode.Default, false, false, 0, KeyboardConstructor.Keyboard()); } File.WriteAllText(usersPath, JsonConvert.SerializeObject(GamerList, Formatting.Indented)); } } }
private async void Stonks(string text, Gamer me, MessageEventArgs args) { bool addMoney; if (text[0] == '+') { addMoney = true; } else if (text[0] == '-') { addMoney = false; } else { throw new ArgumentException("Непонятно, какое действие с деньгами проводить"); } try { float tempMoney = Convert.ToSingle(text.Remove(0, 1)); if (addMoney) { me.PayMe(tempMoney); } else { me.PayTo(tempMoney); } } catch (FormatException) { await Client.SendTextMessageAsync(args.Message.Chat.Id, "Неверный ввод", ParseMode.Default, false, false, 0, KeyboardConstructor.Keyboard()); } }