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

90 lines
3.8 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 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.Water
{
public class SelectWaterNotifyCountCommand : Command
{
public override string Name => "{\"button\":\"selectWaterNotifyCount-";
public override void ExecutePL(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
var chatId = update.@object.message.from_id;
MessagesSendParams @params = new MessagesSendParams();
var keyboardBuilder = new KeyboardBuilder().Clear();
List<UserObject> users = new List<UserObject>();
List<int> chatIds = new List<int>();
string name = "";
Regex regex = new Regex("[^0-9]");
try
{
string[] payload = update.@object.message.payload.Split('-');
int count = Convert.ToInt32(regex.Replace(payload[1], ""));
var user = db.Users.Single(usr => usr.chatId == chatId);
user.waterNotify = count;
db.SaveChanges();
//SqlCommand updUser = new SqlCommand("UPDATE Users SET waterNotify = @waterNotify WHERE chatId = @chatId;", Con);
//updUser.Parameters.AddWithValue("@chatId", chatId);
//updUser.Parameters.AddWithValue("@waterNotify", count);
//updUser.ExecuteNonQuery();
if (count == 10)
{
@params.Message = "Хорошо! Мы не будем присылать Вам рассылку о воде.\n" +
"Если что-то изменится, данную функцию Вы можете подключить в Личном кабинете, в разделе \"Редактировать данные\"";
keyboardBuilder
.AddButton("Личный кабинет", "startPL", KeyboardButtonColor.Primary)
.SetInline();
@params.Keyboard = keyboardBuilder.Build();
}
else
@params.Message = "Отлично! Напоминания включены.\n" +
"Самое время выпить воду😉";
//@params.Message = "Сколько раз в день Вы готовы получать напоминания?";
//keyboardBuilder
// .AddButton("1", "selectWaterNotifyCount-1", KeyboardButtonColor.Primary)
// .AddButton("3", "selectWaterNotifyCount-2", KeyboardButtonColor.Primary)
// .AddButton("6", "selectWaterNotifyCount-3", KeyboardButtonColor.Primary)
// .SetInline();
//@params.Keyboard = keyboardBuilder.Build();
@params.UserId = chatId;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
catch (Exception ee)
{
@params.Message = "Ошибка в SelectWaterNotifyCountCommand: " + ee.Message;
@params.Attachments = null;
@params.Keyboard = null;
@params.UserId = 59111081;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
}
public override void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
}
}
}