Добавьте файлы проекта.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
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 SelectGoWaterNotifyCommand : Command
|
||||
{
|
||||
public override string Name => "{\"button\":\"selectGoWaterNotify\"}";
|
||||
|
||||
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 = "";
|
||||
try
|
||||
{
|
||||
var user = db.Users.Single(usr => usr.chatId == chatId);
|
||||
user.waterNotify = 1;
|
||||
db.SaveChanges();
|
||||
|
||||
//SqlCommand updUser = new SqlCommand("UPDATE Users SET waterNotify = 1 WHERE chatId = @chatId;", Con);
|
||||
//updUser.Parameters.AddWithValue("@chatId", chatId);
|
||||
//updUser.ExecuteNonQuery();
|
||||
|
||||
//@params.Message = "Отлично! Напоминания включены.\n" +
|
||||
// "Самое время выпить воду😉";
|
||||
|
||||
@params.Message = "Сколько раз в день Вы готовы получать напоминания?";
|
||||
|
||||
keyboardBuilder
|
||||
.AddButton("1", "selectWaterNotifyCount-1", KeyboardButtonColor.Primary)
|
||||
.AddButton("3", "selectWaterNotifyCount-3", KeyboardButtonColor.Primary)
|
||||
.AddButton("6", "selectWaterNotifyCount-6", KeyboardButtonColor.Primary)
|
||||
.SetInline();
|
||||
|
||||
@params.Keyboard = keyboardBuilder.Build();
|
||||
@params.UserId = chatId;
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
@params.Message = "Ошибка в SelectGoWaterNotifyCommand: " + 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using Newtonsoft.Json;
|
||||
using SvetoforVKBot.Models.Commands.LK;
|
||||
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 System.Threading;
|
||||
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 SelectOffWaterNotifyCommand : Command
|
||||
{
|
||||
public override string Name => "{\"button\":\"selectOffWaterNotify\"}";
|
||||
|
||||
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 = "";
|
||||
try
|
||||
{
|
||||
var user = db.Users.Single(usr => usr.chatId == chatId);
|
||||
user.waterNotify = 0;
|
||||
db.SaveChanges();
|
||||
|
||||
@params.Message = "Напоминания отключены.\n" +
|
||||
"Настроить напоминания можно в Личном кабинете, в разделе \"📝Редактировать данные\".";
|
||||
keyboardBuilder
|
||||
.AddButton("Личный кабинет", "startPL", KeyboardButtonColor.Primary)
|
||||
.SetInline();
|
||||
|
||||
@params.Keyboard = keyboardBuilder.Build();
|
||||
@params.UserId = chatId;
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
|
||||
//Thread.Sleep(1500);
|
||||
|
||||
//SelectEditDataCommand selectEditData = new SelectEditDataCommand();
|
||||
//selectEditData.Execute(update, client, Con);
|
||||
//return;
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
@params.Message = "Ошибка в SelectOffWaterNotifyCommand: " + 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user