public override async Task OnEvent(EventArgs e)
        {
            var ev = (MessageCreateEventArgs)e;

            var msg     = ev.Message;
            var text    = msg.Content;
            var author  = msg.Author;
            var channel = msg.Channel;

            Logger.Log($"{author.Username}: {text}", channel.Name, LogOrigin.MSG);

            if (author.IsBot)
            {
                return;
            }

            if (KnownUsers.HasUser(author))
            {
                var usr = KnownUsers.Find(x => x.User == author);
                usr.Channel  = msg.Channel;
                usr.LastSeen = DateTime.Now;
            }
            else
            {
                KnownUsers.Add(new ActiveUser(author, DateTime.Now, channel));
            }

            if (text.StartsWith(c))
            {
                string line = text.ToLower().Substring(1);
                await ParseCommand(line, new CommandContext(Context.DMSG, msg));
            }
        }
Exemple #2
0
        public async Task Compliment(DiscordUser user)
        {
            if (!_compliments.Any())
            {
                string[] compFile = { };
                try
                {
                    compFile = File.ReadAllLines(@"compliments.txt");
                }
                catch (Exception e)
                {
                    Logger.LogError(e, "compliments", LogOrigin.CMD);
                    return;
                }

                _compliments = new List <string>(compFile);

                foreach (var line in _compliments)
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        _compliments.Remove(line);
                    }
                }
            }

            var usr     = KnownUsers.Find(x => x.User == user);
            var channel = usr.Channel;
            await channel.SendMessageAsync($"{usr.User.Mention} - {_compliments[RNG.Next(_compliments.Count)]}");
        }
Exemple #3
0
        private static void SeedProfessors(UniversityDbContext dbContext)
        {
            if (!dbContext.Professors.Any())
            {
                dbContext.Professors.AddRange(KnownUsers.Get().Where(u => u.Type == UserTypes.Professor || u.Type == UserTypes.Principal).Select(data => Professor.Create(data.Id, data.GivenName, data.FamilyName, data.Email, data.Id)));

                dbContext.SaveChanges();
            }
        }
Exemple #4
0
        private static void SeedStudents(UniversityDbContext dbContext)
        {
            if (!dbContext.Students.Any())
            {
                dbContext.Students.AddRange(KnownUsers.Get().Where(u => u.Type == UserTypes.Student).Select(data => Student.Create(data.Id, data.GivenName, data.FamilyName, data.Email, data.Id)));

                dbContext.SaveChanges();
            }
        }
Exemple #5
0
        public void GivenTheFollowingAccountsAreCreated(Table table)
        {
            foreach (var tableRow in table.Rows)
            {
                var userName = tableRow["UserName"];
                var password = KnownUsers.Get(userName).Password;

                User.CreateUser(userName, password);
            }
        }
Exemple #6
0
        public void WhenILoginAs(string userName)
        {
            var userPage = NavigationHelper.Navigate <UserPage>();

            var blogPostUser = KnownUsers.Get(userName);

            userPage.LoginPart()
            .UserName(blogPostUser.UserName)
            .Password(blogPostUser.Password)
            .Register();
        }
Exemple #7
0
        public static void EnsureSeedUsers(IServiceProvider serviceProvider)
        {
            // Scope erzeugen damit nach der Anlage alle Services aufgeräumt werden
            using (var scope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var context = scope.ServiceProvider.GetService <ApplicationDbContext>();
                context.Database.Migrate();

                var userMgr = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();

                foreach (var userData in KnownUsers.Get())
                {
                    CreateUser(userMgr, userData);
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Adds the know users from application configuration.
        /// </summary>
        /// <param name="knownUsers">The known users.</param>
        public void AddKnowUsersFromAppConfig(string knownUsers)
        {
            var existingUsers = this.context.KnownUsers;

            if (existingUsers != null && existingUsers.ToList().Count() == 0)
            {
                List <string> knownUsersList = knownUsers.Split(',').ToList();
                foreach (var user in knownUsersList)
                {
                    var users = new KnownUsers()
                    {
                        UserEmail = user.Trim(),
                        RoleId    = 1, // Publisher Admin
                    };
                    this.context.KnownUsers.Add(users);
                    this.context.SaveChanges();
                }
            }
        }
Exemple #9
0
 /// <summary>
 /// Removes the specified entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 public void Remove(KnownUsers entity)
 {
     throw new NotImplementedException();
 }
Exemple #10
0
 /// <summary>
 /// Adds the specified entities.
 /// </summary>
 /// <param name="entities">The entities.</param>
 /// <returns>
 /// Internal identifier after saving the entity.
 /// </returns>
 public int Save(KnownUsers entities)
 {
     throw new NotImplementedException();
 }