コード例 #1
0
ファイル: RoleService.cs プロジェクト: darkclouddev/Rift
        public async Task AddTempRoleAsync(ulong userId, ulong roleId, TimeSpan duration, string reason)
        {
            var role = new RiftTempRole
            {
                UserId         = userId,
                RoleId         = roleId,
                ObtainedFrom   = reason,
                ObtainedTime   = DateTime.UtcNow,
                ExpirationTime = DateTime.UtcNow + duration,
            };

            if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser))
            {
                return;
            }

            if (!IonicHelper.GetRole(Settings.App.MainGuildId, roleId, out var serverRole))
            {
                return;
            }

            await sgUser.AddRoleAsync(serverRole);

            await DB.TempRoles.AddAsync(role);
        }
コード例 #2
0
        public async Task AddAsync(RiftTempRole role)
        {
            await DB.Users.EnsureExistsAsync(role.UserId);

            await using var context = new RiftContext();
            await context.TempRoles.AddAsync(role);

            await context.SaveChangesAsync();
        }
コード例 #3
0
        public async Task RemoveAsync(ulong userId, ulong roleId)
        {
            var rtr = new RiftTempRole
            {
                UserId = userId,
                RoleId = roleId,
            };

            await using var context = new RiftContext();
            context.TempRoles.Remove(rtr);
            await context.SaveChangesAsync();
        }