240 lines
12 KiB
C#
240 lines
12 KiB
C#
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;
|
||
|
||
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/");
|
||
#region UTM
|
||
/*
|
||
utm = update.@object.message.@ref;
|
||
|
||
if (utm != "" && utm != null)
|
||
{
|
||
if (int.TryParse(utm, out int refer))
|
||
{
|
||
if (refer != chatId)
|
||
{
|
||
int referId = 1;
|
||
|
||
//Проверяем приглашали ли этого пользователя раннее
|
||
getUser = new SqlCommand("SELECT referId FROM Users WHERE chatId = @chatId;", Con);
|
||
getUser.Parameters.AddWithValue("@chatId", chatId);
|
||
rgetUser = getUser.ExecuteReader();
|
||
rgetUser.Read();
|
||
int uReferId = Convert.ToInt32(rgetUser["referId"]);
|
||
rgetUser.Close();
|
||
|
||
if (uReferId == 0) // 0 - не приглашали
|
||
{
|
||
//Ищем пользователя, который пригласил
|
||
SqlCommand getRefer = new SqlCommand("SELECT chatId FROM Users WHERE chatId = @refer;", Con);
|
||
getRefer.Parameters.AddWithValue("@refer", refer);
|
||
SqlDataReader rgetRefer = getRefer.ExecuteReader();
|
||
if (rgetRefer.HasRows) // если пользователь существует
|
||
{
|
||
rgetRefer.Close();
|
||
|
||
SqlCommand updReferId = new SqlCommand("UPDATE Users SET referId = @referId WHERE chatId = @chatId;", Con);
|
||
updReferId.Parameters.AddWithValue("@chatId", chatId);
|
||
updReferId.Parameters.AddWithValue("@referId", refer);
|
||
updReferId.ExecuteNonQuery();
|
||
|
||
selectQuestRoom.ExecutePL(update, client, Con);
|
||
return;
|
||
}
|
||
else
|
||
rgetRefer.Close();
|
||
}
|
||
else
|
||
{
|
||
selectQuestRoom.ExecutePL(update, client, Con);
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
selectQuestRoom.ExecutePL(update, client, Con);
|
||
return;
|
||
}
|
||
}
|
||
|
||
SourceUpdate sourceUpdate = new SourceUpdate();
|
||
sourceUpdate.Execute(update, client, Con);
|
||
|
||
switch (utm)
|
||
{
|
||
case "afisha":
|
||
SelectEventsCommand selectEvents = new SelectEventsCommand();
|
||
selectEvents.ExecutePL(update, client, Con);
|
||
return;
|
||
|
||
case "quest":
|
||
selectQuestRoom.ExecutePL(update, client, Con);
|
||
return;
|
||
|
||
case "project":
|
||
SelectProjectOfficeCommand selectProjectOffice = new SelectProjectOfficeCommand();
|
||
selectProjectOffice.ExecutePL(update, client, Con);
|
||
return;
|
||
|
||
case "faq":
|
||
SelectOSCommand selectOS = new SelectOSCommand();
|
||
selectOS.ExecutePL(update, client, Con);
|
||
return;
|
||
}
|
||
|
||
}
|
||
*/
|
||
#endregion UTM
|
||
|
||
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 (activityKind == 2 || activityKind == 3)
|
||
{
|
||
ShowLKCommand showLK = new ShowLKCommand();
|
||
showLK.Execute(update, client, db);
|
||
}
|
||
else // спортсмены
|
||
{
|
||
ShowLKCommand showLK = new ShowLKCommand();
|
||
showLK.Execute(update, client, db);
|
||
//ShowSportsLKCommand showSportsLK = new ShowSportsLKCommand();
|
||
//showSportsLK.Execute(update, client, Con);
|
||
}
|
||
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)
|
||
{
|
||
}
|
||
}
|
||
} |