Files
Parasha/SvetoforVKBot/Models/Commands/Start/StartCommand.cs
2021-10-20 06:09:18 +03:00

157 lines
7.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 VkNet.Model.Attachments;
using System.Collections.Generic;
using System.Threading;
using SvetoforVKBot.Models.Dop;
using SvetoforVKBot.Models.Commands.LK;
using SvetoforVKBot.Models.Commands.LK.SportsLK;
using System.Collections.ObjectModel;
using System.Linq;
using SvetoforVKBot.Models.Commands.Registration;
namespace SvetoforVKBot.Models.Commands
{
public class StartCommand : Command
{
public override string Name => "Начать";
public override void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
var chatId = update.@object.message.from_id;
MessagesSendParams @params = new MessagesSendParams();
var keyboardBuilder = new KeyboardBuilder().Clear();
string tag = "";
string utm = "";
try
{
var ids = new long[] { chatId };
var user = client.Users.Get(ids, ProfileFields.Sex);
var gender = Convert.ToInt32(user[0].Sex);
var listButtons = new List<ReadOnlyCollection<MessageKeyboardButton>>();
Uri URL = new Uri("https://www.vyatsu.ru/");
var getUser = db.Users.Single(usr => usr.chatId == chatId);
int reg = getUser.reg;
int admin = getUser.admin;
int activityKind = getUser.activityKind;
getUser.tag = "Старт";
db.SaveChanges();
switch (reg)
{
case 1:
if (getUser.isAuthorized == 1)
{
ShowLKCommand showLK = new ShowLKCommand();
showLK.Execute(update, client, db);
}
else
{
SelectParticipateCommand selectParticipate = new SelectParticipateCommand();
selectParticipate.ExecutePL(update, client, db);
}
return;
default:
@params.Message = "Добрый день, " + user[0].FirstName + "!" +
"\n\n" +
"🍏Проект \"Здоровое питание\" это доступная возможность для каждого студента, сотрудника и любого желающего " +
"улучшить свою жизнь, здоровье и самочувствие." +
"\n\n" +
"👉🏻Проект направлен на формирование культуры правильного питания, мотивации к регулярным занятиям физическими упражнениями. " +
"Для участников проекта разработано меню правильного питания, будет осуществляться исследование морфофункционального " +
"состояния участников, разрабатываться комплекс физических упражнений." +
"\n\n" +
"💬Участники проекта будут обеспечены консультационной поддержкой от организаторов.";
//keyboardBuilder
// .AddButton("🚦Принять участие", "selectAgreement", KeyboardButtonColor.Positive); //✅ selectAgreement
//.AddLine()
var row2 = new List<MessageKeyboardButton>()
{
new MessageKeyboardButton() {
Action = new MessageKeyboardButtonAction(){
Label = "🚦Принять участие",
Payload = "{\"button\":\"selectParticipate\"}", //selectAgreement
Type = KeyboardButtonActionType.Text},
Color = KeyboardButtonColor.Positive
}
};
listButtons.Add(new ReadOnlyCollection<MessageKeyboardButton>(row2)); //.AddButton("❔Вопросы и ответы", "selectInProgress", KeyboardButtonColor.Primary);
//var row = new List<MessageKeyboardButton>()
//{
// new MessageKeyboardButton() {
// Action = new MessageKeyboardButtonAction(){
// Type = KeyboardButtonActionType.OpenLink,
// Link = URL,
// Label = "Узнать подробнее",
// Payload = "{\"button\":\"selectOpenSheet\"}"
// },
// }
//};
//listButtons.Add(new ReadOnlyCollection<MessageKeyboardButton>(row));
if (chatId == 59111081 || chatId == 10160301 || chatId == 369217524 || chatId == 178385801)
{
var row3 = new List<MessageKeyboardButton>()
{
new MessageKeyboardButton() {
Action = new MessageKeyboardButtonAction(){
Type = KeyboardButtonActionType.Text,
Label = "Администратору",
Payload = "{\"button\":\"selectAdminMenu\"}"
},
Color = KeyboardButtonColor.Default
}
};
listButtons.Add(new ReadOnlyCollection<MessageKeyboardButton>(row3));
//keyboardBuilder
// .AddLine()
// .AddButton("Администратору", "selectAdminMenu", KeyboardButtonColor.Default);
}
var buttons = new ReadOnlyCollection<ReadOnlyCollection<MessageKeyboardButton>>(listButtons);
var keyboard = new MessageKeyboard()
{
Buttons = buttons,
OneTime = false
};
@params.Keyboard = keyboard;
@params.UserId = chatId;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
return;
}
}
catch (Exception ee)
{
@params.Message = "‼Ошибка в StartCommand: " + ee.Message;
@params.Attachments = null;
@params.Keyboard = null;
@params.UserId = 59111081;
@params.RandomId = GetRandomId();
client.Messages.SendAsync(@params);
}
}
public override void ExecutePL(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
{
}
}
}