112 lines
4.1 KiB
C#
112 lines
4.1 KiB
C#
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.SportsLK
|
||
{
|
||
public class ShowSportsLKCommand
|
||
{
|
||
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 = "";
|
||
try
|
||
{
|
||
msg = "📌Личный кабинет\n";
|
||
|
||
var user = db.Users.Single(usr => usr.chatId == chatId);
|
||
user.tag = "Личный кабинет";
|
||
user.day = 0;
|
||
user.colorId = 0;
|
||
db.SaveChanges();
|
||
|
||
age = (DateTime.Today.Year - user.birthday.Year);
|
||
|
||
if (user.gender == 1)
|
||
genderStr = "Мужчина";
|
||
else
|
||
genderStr = "Женщина";
|
||
|
||
msg += "🧬Показатели здоровья\n" +
|
||
"Вес: " + user.weight + " кг" +
|
||
"\n" +
|
||
"Рост: " + user.height + " см" +
|
||
"\n" +
|
||
"Возраст: " + age +
|
||
"\n" +
|
||
"Пол: " + genderStr +
|
||
"\n\n" +
|
||
IMT +
|
||
"\n\n";
|
||
|
||
if (user.kkal != 0)
|
||
msg += "Норма ккал на сегодня: " + user.kkal;
|
||
else
|
||
msg += "Норма ккал на сегодня: не рассчитана";
|
||
|
||
|
||
keyboardBuilder
|
||
.AddButton("📊Отправить отчёт", "selectCreateReport", KeyboardButtonColor.Positive)
|
||
.AddLine()
|
||
.AddButton("📝Редактировать данные", "selectEditData-0", KeyboardButtonColor.Primary)
|
||
.AddLine()
|
||
.AddButton("📈Набор мышечной массы", "selectCalculatorCcal", KeyboardButtonColor.Primary)
|
||
.AddLine()
|
||
.AddButton("📋Меню", "selectMenu-0", KeyboardButtonColor.Primary)
|
||
//.AddLine()
|
||
.AddButton("💬Консультация", "selectConsultation", KeyboardButtonColor.Primary); //✏
|
||
|
||
if (chatId == 59111081)
|
||
{
|
||
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 = "‼Ошибка в ShowSportsLKCommnad: " + 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);
|
||
}
|
||
}
|
||
} |