예제 #1
0
        /// <summary>
        /// Создание бота (только телеграм)
        /// </summary>
        /// <param name="model"></param>
        /// <param name="masterId"></param>
        /// <returns></returns>
        public async Task <bool> CreateBotAsync(CreateBotViewModel model, Models.User user)
        {
            if (user.ConfirmEmail && user.BotCount < 3 && (await context.Bots.FirstOrDefaultAsync(b => b.Key == model.Key || b.Name == model.Name)) == null)
            {
                TelegramBot bot = new TelegramBot(model.Name, model.Key)
                {
                    DateOfReg    = DateTime.Now,
                    LastActivity = DateTime.Now,
                    MasterId     = user.Id,
                    IsActive     = true,
                };
                await bot.GetClient();

                Bot bot_ = bot.TakeAsParent();
                context.Bots.Add(bot_);
                user.BotCount++;
                await context.SaveChangesAsync();

                bot.Id = bot_.Id;
                Directory.CreateDirectory(AppConfig.UsersPath + $"/{user.Id}/bots/{bot.Id}/functional");
                bot.PhysicalPath = bot_.PhysicalPath = AppConfig.UsersPath + $"/{bot.MasterId}/bots/{bot_.Id}";
                await bot_.SaveFunctionalAsync(new Functional()
                {
                    BotId            = bot.Id,
                    CommandFunctions = bot.Functions
                });

                await context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
예제 #2
0
        public async Task<IActionResult> Create(CreateBotViewModel model)
        {
            if (ModelState.IsValid)
            {
                var authorBot = await CreateBot(model.Name);

                return RedirectToAction(nameof(Edit), new { id = authorBot.Id, version = authorBot.Version });
            }
            return RedirectToAction(nameof(Index));
        }
예제 #3
0
        public async Task <JsonResult> CreateBot([FromBody] CreateBotViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool suc = await botServ.CreateBotAsync(model, await accServ.GetCurrentUserAsync(User.Identity.Name));

                if (suc)
                {
                    return(Json(true));
                }
            }
            return(Json("Ошибка регистрации бота. Убедитесь, что имя содержит только латинские символы. Проверьте правильность ключа. Убедитесь, чтоб бот уже не зарегистрирован на нашем сайте."));
        }