Files
Parasha/SvetoforVKBot/Models/Commands/LK/Consultation/GetConsultationCommand.cs
2021-10-19 06:04:52 +03:00

85 lines
3.3 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.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using SvetoforVKBot.App_Start;
using SvetoforVKBot.Models.Updates;
using VkNet;
using VkNet.Enums.SafetyEnums;
using VkNet.Model.Keyboard;
using VkNet.Model.RequestParams;
namespace SvetoforVKBot.Models.Commands.LK.Consultation
{
public class GetConsultationCommand
{
public void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
var chatId = update.@object.message.from_id;
MessagesSendParams @params = new MessagesSendParams();
MessagesSendParams @params2 = new MessagesSendParams();
var keyboardBuilder = new KeyboardBuilder().Clear();
try
{
if (update.@object.message.text.Length > 0)
{
var ids = new long[] { chatId };
var user = db.Users.Single(usr => usr.chatId == chatId);
user.question = update.@object.message.text.Trim();
user.tag = "Личный кабинет";
db.SaveChanges();
keyboardBuilder
.AddButton("Личный кабинет", "startPL", KeyboardButtonColor.Default);
@params.Keyboard = keyboardBuilder.Build();
@params.Message = "✅Вопрос принят. Менеджер ответит Вам в ближайшее время!\n";
@params.UserId = chatId;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
@params2.Message = "❓Вопрос. \nСсылка на диалог: " + ((WebConfiguration)ConfigurationManager.GetSection("VKApi")).GroupDialogsLink + chatId;
List<long> listFrwMsg = new List<long>() { update.@object.message.id };
@params2.PeerId = 2000000002;
//@params2.UserId = 59111081;
@params2.ForwardMessages = listFrwMsg;
@params2.RandomId = GetRandomId();
client.Messages.Send(@params2);
}
else
{
@params.Message = "Не распознал сообщение 😕 Попробуйте, пожалуйста, ещё раз";
@params.UserId = chatId;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
}
catch (Exception ee)
{
@params.Message = "‼Ошибка в GetReportCommentCommand: " + 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();
public int GetRandomId()
{
var intBytes = new byte[4];
Rng.GetBytes(intBytes);
return BitConverter.ToInt32(intBytes, 0);
}
}
}