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

103 lines
4.9 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 System;
using System.Data.SqlClient;
using SvetoforVKBot.Models.Updates;
using VkNet;
using VkNet.Enums.SafetyEnums;
using VkNet.Model.Keyboard;
using VkNet.Model.RequestParams;
using Newtonsoft.Json;
using VkNet.Enums.Filters;
using System.Text.RegularExpressions;
using SvetoforVKBot.Models.Commands.LK;
using System.Linq;
namespace SvetoforVKBot.Models.Commands.Registration
{
public class SelectActivityKindCommand : Command
{
public override string Name => "{\"button\":\"selectActivityKind-";
public override void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
}
public override void ExecutePL(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
MessagesSendParams @params = new MessagesSendParams();
var chatId = update.@object.message.from_id;
var keyboardBuilder = new KeyboardBuilder().Clear();
Regex regex = new Regex("[^0-9]");
string voronka = "";
double activityCoef = 0;
SqlCommand editUser;
try
{
string[] payload = update.@object.message.payload.Split('-');
int activityKind = Convert.ToInt32(regex.Replace(payload[1], ""));
var user = db.Users.Single(usr => usr.chatId == chatId);
switch (activityKind)
{
case 1:
case 2:
ShowSportKinds showSport = new ShowSportKinds();
showSport.Execute(update, client, db, activityKind);
return;
case 3:
activityCoef = 1.2;
if (user.reg == 0)
{
user.activityCoef = activityCoef;
user.activityKind = activityKind;
user.tag = "Регистрация - Напоминания";
db.SaveChanges();
keyboardBuilder
.AddButton("Раз в день", "selectNotifyCount-1", KeyboardButtonColor.Primary)
.AddLine()
.AddButton("Три раза в день", "selectNotifyCount-3", KeyboardButtonColor.Primary)
.AddLine()
.AddButton("Более 3х раз", "selectNotifyCount-4", KeyboardButtonColor.Primary)
.AddLine()
.AddButton("Никогда", "selectNotifyCount-0", KeyboardButtonColor.Default);
@params.Message = "Благодарим за регистрацию! Ваш личный кабинет сформирован.\n" +
"Последний вопрос: как часто Вы готовы получать напоминания от чат-бота?\n\n" +
"Вы будете получать уведомления о приёмах пищи и воды. Если Вы хотите сформировать привычку " +
"по режиму питания или употреблению достаточного количества воды, выберите вариант \"Более 3х раз\".\n" +
"Наш чат-бот не будет рассылать рекламу или спам. Только персональные уведомления и рекомендации по здоровому питанию.";
@params.Keyboard = keyboardBuilder.Build();
@params.UserId = chatId;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
else
{
user.activityCoef = activityCoef;
user.activityKind = activityKind;
user.tag = "Личный кабинет - Данные";
db.SaveChanges();
SelectEditDataCommand selectEditData = new SelectEditDataCommand();
selectEditData.Execute(update, client, db);
}
return;
}
}
catch (Exception ee)
{
@params.Message = "Ошибка в SelectActivityCoefCommand: " + ee.Message;
@params.Attachments = null;
@params.Keyboard = null;
@params.UserId = 59111081;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
}
}
}