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

115 lines
5.6 KiB
C#
Raw Permalink 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 SvetoforVKBot.Models.Updates;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using VkNet;
using VkNet.Model.RequestParams;
using System.Security.Cryptography;
using VkNet.Model.Keyboard;
using VkNet.Model.Attachments;
using VkNet.Enums.SafetyEnums;
using System.Collections.ObjectModel;
using System.Threading;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using SvetoforVKBot.Models.Commands.LK;
using System.Linq;
namespace SvetoforVKBot.Models.Commands.Registration
{
public class GetKorpusCommand
{
public void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
MessagesSendParams @params = new MessagesSendParams();
MessagesSendParams @params2 = new MessagesSendParams();
var chatId = update.@object.message.from_id;
Regex regex = new Regex("[^0-9]");
int i = 0;
var row = new List<MessageKeyboardButton>();
var listButtons = new List<ReadOnlyCollection<MessageKeyboardButton>>();
var keyboardBuilder = new KeyboardBuilder().Clear();
string korpus = "";
try
{
if (update.@object.message.text.Trim().ToLower().Contains("продолжить"))
korpus = "0";
else
{
if (update.@object.message.text.Trim().Length > 0)
//if (int.TryParse(update.@object.message.text.Trim(), out int korp))
{
korpus = update.@object.message.text.Trim();
//if (korp <= 24)
//else
//{
// @params.Message = "Вы некорректно ввели номер корпуса. Попробуйте, пожалуйста, ещё раз.";
// @params.UserId = chatId;
// @params.RandomId = GetRandomId();
// client.Messages.SendAsync(@params);
// return;
//}
}
else
{
@params.Message = "Вы некорректно ввели номер корпуса. Попробуйте, пожалуйста, ещё раз.";
@params.UserId = chatId;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
return;
}
}
var user = db.Users.Single(usr => usr.chatId == chatId);
user.korpus = korpus;
user.tag = "Регистрация - Активность - Вид";
db.SaveChanges();
//editUser.Parameters.AddWithValue("@tag", "Регистрация - Активность - Вид");
@params.Message = "Вы заниматесь спортом или физкультурой?\n" +
"Выберите на клавиатуре вариант, который наиболее точно описывает Ваш образ жизни.\n\n" +
"👉🏻 Если Вы профессионально занимаетесь спортом или Ваша работа связана с тяжёлым физическим трудом, выберите вариант \"Занимаюсь спортом\"\n" +
"👉🏻 Если Вы не занимаетесь спортом профессионально, но регулярно поддерживаете физическую активность (занятия физкультурой), выберите вариант \"Занимаюсь физкультурой\"\n" +
"👉🏻 Если у Вас сидячая работа или нерегулярная физическая активность (менее одного раза в неделю), выберите вариант \"Ничем не занимаюсь\".\n";
keyboardBuilder
.AddButton("Занимаюсь спортом", "selectActivityKind-1", KeyboardButtonColor.Primary)
.AddLine()
.AddButton("Занимаюсь физкультурой", "selectActivityKind-2", KeyboardButtonColor.Primary)
.AddLine()
.AddButton("Ничем не занимаюсь", "selectActivityKind-3", KeyboardButtonColor.Primary)
.AddLine()
.AddButton("Отменить", "startPL", KeyboardButtonColor.Default);
@params.Keyboard = keyboardBuilder.Build();
@params.UserId = chatId;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
catch (Exception ee)
{
@params.Message = "‼Ошибка в GetKorpusCommand: " + ee.Message;
@params.Attachments = null;
@params.Keyboard = null;
@params.UserId = 59111081;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
return;
}
return;
}
private static readonly RandomNumberGenerator Rng = RandomNumberGenerator.Create();
public int GetRandomId()
{
var intBytes = new byte[4];
Rng.GetBytes(intBytes);
return BitConverter.ToInt32(intBytes, 0);
}
}
}