Exemple #1
0
 public async Task RestoreUserRoles(SocketCommandContext context, SocketGuildUser target)
 {
     try
     {
         using (var db = new Restoreroles())
         {
             var IRoleCollection = new List <IRole>();
             foreach (var item in db.RoleModelRolesStore.AsQueryable().Where(x => x.UserID == target.Id))
             {
                 IRoleCollection.Add(context.Guild.GetRole(item.RoleID));
             }
             await target.AddRolesAsync(IRoleCollection);
         }
     }
     catch (Exception ex)
     {
         await context.Channel.SendMessageAsync($"restore user roles table is f****d atm sry kid {ex.Message}");
     }
 }
Exemple #2
0
        public async Task StoreUserRoles(SocketCommandContext context, SocketGuildUser target)
        {
            try
            {
                using (var db = new Restoreroles())
                {
                    RestoreRoleModelRemoveExisting(context, target, db);
                    RestoreRolesRemoveExisting(context, target, db);
                    foreach (var role in target.Roles)
                    {
                        if (RoleToStoreIsNotValid(role, context))
                        {
                            continue;
                        }

                        await db.RoleModelRolesStore.AddAsync(new RestoreRoleModelRoles
                        {
                            UserID   = target.Id,
                            RoleName = role.Name,
                            RoleID   = role.Id
                        });
                    }

                    await db.RestoreRoles.AddAsync(new RestoreRoleModel
                    {
                        Username     = target.Username,
                        DateInserted = DateTime.Now.ToShortDateString(),
                        Time         = DateTime.Now.ToShortTimeString(),
                        UserID       = target.Id,
                        AdminID      = context.Message.Author.Id
                    });

                    await db.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                await context.Channel.SendMessageAsync($"store roles table is f****d atm sry kid: {ex.Message}");
            }
        }
Exemple #3
0
        private void RestoreRolesRemoveExisting(SocketCommandContext context, SocketGuildUser target, Restoreroles db)
        {
            var existingUser = db.RestoreRoles.AsQueryable().Where(x => x.UserID == target.Id);

            if (existingUser.Any())
            {
                foreach (var item in existingUser)
                {
                    db.RestoreRoles.Remove(item);
                }
            }
        }
Exemple #4
0
        private void RestoreRoleModelRemoveExisting(SocketCommandContext context, SocketGuildUser target, Restoreroles db)
        {
            var existingUser = db.RoleModelRolesStore.AsQueryable().Where(x => x.UserID == target.Id);

            if (existingUser.Any())
            {
                foreach (var item in existingUser)
                {
                    if (RoleToStoreIsNotValid(context.Guild.GetRole(item.RoleID), context))
                    {
                        continue;
                    }
                    db.RoleModelRolesStore.Remove(item);
                }
            }
        }