Files
Parasha/SvetoforVKBot/Models/Commands/LK/ShowLKCommand.cs
2021-10-19 06:04:52 +03:00

214 lines
11 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Newtonsoft.Json;
using SvetoforVKBot.Models.Updates;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using System.Linq;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using VkNet;
using VkNet.Enums.SafetyEnums;
using VkNet.Model.Attachments;
using VkNet.Model.Keyboard;
using VkNet.Model.RequestParams;
namespace SvetoforVKBot.Models.Commands.LK
{
public class ShowLKCommand
{
public void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
MessagesSendParams @params = new MessagesSendParams();
var chatId = update.@object.message.from_id;
var keyboardBuilder = new KeyboardBuilder().Clear();
List<StackObject> techStack = new List<StackObject>();
string msg = "";
int age = 0;
string genderStr = "";
double indexMT = 0;
string IMT = "";
double kkalLow = 0;
double kkalHigh = 0;
try
{
msg = "📌Личный кабинет\n";
var user = db.Users.Single(usr => usr.chatId == chatId);
user.tag = "Личный кабинет";
user.day = 0;
user.colorId = 0;
db.SaveChanges();
msg += user.fio + "\n\n";
if ((DateTime.Now.Month >= user.birthday.Month) && (DateTime.Now.Day >= user.birthday.Day))
age = DateTime.Now.Year - user.birthday.Year;
else
age = DateTime.Now.Year - user.birthday.Year - 1;
Dictionary<int, string> colors = new Dictionary<int, string>(3);
colors.Add(1, "🟩"); //З
colors.Add(2, "🟦"); //C
colors.Add(3, "🟨"); //Ж
Dictionary<int, string> tracks = new Dictionary<int, string>(7);
tracks.Add(1, "Оптимизация питания");
tracks.Add(2, "Снижение жировой массы");
tracks.Add(3, "Увеличение мышечной массы");
tracks.Add(4, "Персональный режим");
//if (personal == 1)
//{
// keyboardBuilder
// .AddButton("✅Персональный режим", "selectPersonalPlan", KeyboardButtonColor.Positive)
// .AddLine();
//}
if (user.track == 0)
{
msg += "Выберите желаемый трек оптимизации питания👇🏻";
keyboardBuilder
.AddButton("🟩Оптимизация питания", "selectTrack-1", KeyboardButtonColor.Primary) //З🟩
.AddLine()
.AddButton("🟦Снижение жировой массы", "selectTrack-2", KeyboardButtonColor.Primary) //С🟦
.AddLine()
.AddButton("🟨Увеличение мыш. массы", "selectTrack-3", KeyboardButtonColor.Primary) //Ж🟨
.AddLine()
.AddButton("Персональный режим", "selectTrack-4", KeyboardButtonColor.Primary);
}
else
{
if (user.gender == 1)
genderStr = "Мужчина";
else
genderStr = "Женщина";
if (user.weight != 0 && user.height != 0)
{
indexMT = Math.Round(user.weight / (double)(user.height / 100.0 * user.height / 100.0), 1);
IMT = "Индекс массы тела: " + indexMT + " кг/м2 \n";
if (indexMT < 18.5)
IMT += "🔴 Дефицит" + "\n" +
"Риск сопутствующих заболеваний: Низкий (повышен риск других заболеваний)";
else if (indexMT >= 18.5 && indexMT < 25)
IMT += "✅ Норма" + "\n" +
"Риск сопутствующих заболеваний: Обычный";
else if (indexMT >= 25 && indexMT < 30)
IMT += "⚠ Избыточная масса тела" + "\n" +
"Риск сопутствующих заболеваний: Повышенный";
else if (indexMT >= 30 && indexMT < 35)
IMT += "🔴 Ожирение I степени" + "\n" +
"Риск сопутствующих заболеваний: Высокий";
else if (indexMT >= 35 && indexMT < 40)
IMT += "🔴 Ожирение II степени" + "\n" +
"Риск сопутствующих заболеваний: Очень высокий";
else
IMT += "🔴 Ожирение III степени" + "\n" +
"Риск сопутствующих заболеваний: Чрезвычайно высокий";
}
else
{
IMT = "⚠Индекс массы тела: не рассчитан (укажите рост и вес в разделе \"Редактировать данные\").";
}
msg += "🧬Показатели здоровья\n" +
"Вес: " + user.weight + " кг" +
"\n" +
"Рост: " + user.height + " см" +
"\n" +
"Возраст: " + age +
"\n" +
"Пол: " + genderStr +
"\n\n" +
IMT +
"\n\n";
if (user.kkal != 0)
{
kkalLow = Math.Round(user.kkal * 0.9);
kkalHigh = Math.Round(user.kkal * 1.2);
msg += $"Норма на сегодня: {kkalLow}-{kkalHigh} ккал";
}
else
msg += "⚠Норма ккал на сегодня: не рассчитана (воспользуйтесь калькулятором калорий).";
if (user.kkal == 0 || user.height == 0 || user.weight == 0)
{
keyboardBuilder
//.AddButton("📊Отправить отчёт", "selectCreateReport", KeyboardButtonColor.Positive)
//.AddLine()
.AddButton("📝Редактировать данные", "selectEditData-0", KeyboardButtonColor.Positive)
.AddLine()
.AddButton("🧮Калькулятор калорий", "selectCalcCcalResult-" + user.track, KeyboardButtonColor.Primary)
.AddLine()
.AddButton("⭐Рекомендации", "selectTrack-" + user.track, KeyboardButtonColor.Primary)
//.AddLine()
//.AddButton("⭐Идеальный вес", "selectIdealWeight", KeyboardButtonColor.Primary)
//.AddLine()
//.AddButton("📈Набор мышечной массы", "selectCalculatorCcal", KeyboardButtonColor.Primary)
//.AddLine()
//.AddButton("📋Меню", "selectMenu-0", KeyboardButtonColor.Primary)
//.AddLine()
.AddButton("💬Есть вопрос?", "selectConsultation", KeyboardButtonColor.Primary); //✏
}
else
{
keyboardBuilder
.AddButton("📊Отправить отчёт", "selectCreateReport", KeyboardButtonColor.Positive)
.AddLine()
.AddButton("🥗Дневной рацион", "selectDayFood", KeyboardButtonColor.Positive)
.AddLine()
.AddButton("📝Редактировать данные", "selectEditData-0", KeyboardButtonColor.Primary)
.AddLine()
.AddButton("🧮Калькулятор калорий", "selectCalcCcalResult-" + user.track, KeyboardButtonColor.Primary)
.AddLine()
.AddButton("⭐Рекомендации", "selectTrack-" + user.track, KeyboardButtonColor.Primary)
//.AddLine()
//.AddButton("⭐Идеальный вес", "selectIdealWeight", KeyboardButtonColor.Primary)
//.AddLine()
//.AddButton("📈Набор мышечной массы", "selectCalculatorCcal", KeyboardButtonColor.Primary)
//.AddLine()
//.AddButton("📋Меню", "selectMenu-0", KeyboardButtonColor.Primary)
//.AddLine()
.AddButton("💬Есть вопрос?", "selectConsultation", KeyboardButtonColor.Primary); //✏
}
}
if (chatId == 59111081 || chatId == 10160301 || chatId == 369217524 || chatId == 178385801)
{
keyboardBuilder
.AddLine()
.AddButton("Администратору", "selectAdminMenu", KeyboardButtonColor.Default);
}
@params.Message = msg;
@params.UserId = chatId;
@params.Keyboard = keyboardBuilder.Build();
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
catch (Exception ee)
{
@params.Message = "‼Ошибка в ShowLKCommnad: " + ee.Message;
@params.Attachments = null;
@params.Keyboard = null;
@params.UserId = 59111081;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
}
private static readonly RandomNumberGenerator Rng = RandomNumberGenerator.Create();
private int GetRandomId()
{
var intBytes = new byte[4];
Rng.GetBytes(intBytes);
return BitConverter.ToInt32(intBytes, 0);
}
}
}