Пример #1
0
        protected override async Task <bool> ExecuteCommand(IDiscordBot bot, SocketMessage message, RegisterOption option)
        {
            var userId = message.Author.Id;

            using (var dbContext = _dbContextFactory.Create())
            {
                var existingUser = dbContext.Users.FirstOrDefault(t => t.DiscordId == userId);
                if (existingUser != null)
                {
                    await message.Channel.SendMessageAsync($"{message.Author.Username} already has a registered user.");
                }
                else
                {
                    var skillSet = new SkillSet();
                    skillSet.Init();
                    var applicationUser = new ApplicationUser
                    {
                        DiscordId          = userId,
                        UserName           = message.Author.Username,
                        NormalizedUserName = message.Author.Username.ToUpper(),
                        Id           = userId.ToString(),
                        PasswordHash = "TestAtm",
                        SkillSet     = skillSet,
                        CurrentTask  = new CurrentTask {
                            Notified = true, UserId = userId.ToString(), UnlockTime = DateTime.MinValue
                        },
                        Mention = message.Author.Mention
                    };
                    dbContext.Add(applicationUser);

                    await dbContext.SaveChangesAsync();

                    await message.Channel.SendMessageAsync($"{message.Author.Username} has registered their user. Type +help for commands. Each command has a --help switch .e.g. +buy --help.");
                }
            }
            return(true);
        }